Skip to content

Commit 50f7bfc

Browse files
committed
Add dead_hosts and redirection_hosts
1 parent 6bbe7d4 commit 50f7bfc

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

backend/internal/certificate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ const internalCertificate = {
314314
.andWhere('id', data.id)
315315
.allowGraph('[owner]')
316316
.allowGraph('[proxy_hosts]')
317+
.allowGraph('[redirection_hosts]')
318+
.allowGraph('[dead_hosts]')
317319
.first();
318320

319321
if (access_data.permission_visibility !== 'all') {
@@ -466,6 +468,8 @@ const internalCertificate = {
466468
.groupBy('id')
467469
.allowGraph('[owner]')
468470
.allowGraph('[proxy_hosts]')
471+
.allowGraph('[redirection_hosts]')
472+
.allowGraph('[dead_hosts]')
469473
.orderBy('nice_name', 'ASC');
470474

471475
if (access_data.permission_visibility !== 'all') {

backend/models/certificate.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ class Certificate extends Model {
6767
}
6868

6969
static get relationMappings () {
70-
const ProxyHost = require('./proxy_host');
71-
const User = require('./user');
70+
const ProxyHost = require('./proxy_host');
71+
const DeadHost = require('./dead_host');
72+
const User = require('./user');
73+
const RedirectionHost = require('./redirection_host');
74+
7275
return {
7376
owner: {
7477
relation: Model.HasOneRelation,
@@ -91,6 +94,28 @@ class Certificate extends Model {
9194
modify: function (qb) {
9295
qb.where('proxy_host.is_deleted', 0);
9396
}
97+
},
98+
dead_hosts: {
99+
relation: Model.HasManyRelation,
100+
modelClass: DeadHost,
101+
join: {
102+
from: 'certificate.id',
103+
to: 'dead_host.certificate_id'
104+
},
105+
modify: function (qb) {
106+
qb.where('dead_host.is_deleted', 0);
107+
}
108+
},
109+
redirection_hosts: {
110+
relation: Model.HasManyRelation,
111+
modelClass: RedirectionHost,
112+
join: {
113+
from: 'certificate.id',
114+
to: 'redirection_host.certificate_id'
115+
},
116+
modify: function (qb) {
117+
qb.where('redirection_host.is_deleted', 0);
118+
}
94119
}
95120
};
96121
}

frontend/js/app/nginx/certificates/list/item.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<%- formatDbDate(expires_on, 'Do MMMM YYYY, h:mm a') %>
3535
</td>
3636
<td>
37-
<% if (proxy_hosts.length > 0) { %>
37+
<% if (active_domain_names().length > 0) { %>
3838
<span class="status-icon bg-success"></span> <%- i18n('certificates', 'in-use') %>
3939
<% } else { %>
4040
<span class="status-icon bg-danger"></span> <%- i18n('certificates', 'inactive') %>
@@ -55,10 +55,10 @@
5555
<div class="dropdown-divider"></div>
5656
<% } %>
5757
<a href="#" class="delete dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> <%- i18n('str', 'delete') %></a>
58-
<% if (proxy_hosts.length > 0) { %>
58+
<% if (active_domain_names().length > 0) { %>
5959
<div class="dropdown-divider"></div>
6060
<span class="dropdown-header"><%- i18n('certificates', 'active-domain_names') %></span>
61-
<% proxy_hosts.forEach(function(host) { %>
61+
<% active_domain_names().forEach(function(host) { %>
6262
<a href="https://<%- host %>" class="dropdown-item" target="_blank"><%- host %></a>
6363
<% }); %>
6464
<% } %>

frontend/js/app/nginx/certificates/list/item.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ module.exports = Mn.View.extend({
4848
return {
4949
canManage: App.Cache.User.canManage('certificates'),
5050
isExpired: function () {
51+
console.log(this);
5152
return moment(this.expires_on).isBefore(moment());
5253
},
5354
dns_providers: dns_providers,
54-
proxy_hosts: this.getProxyHosts()
55+
active_domain_names: function () {
56+
const { proxy_hosts = [], redirect_hosts = [], dead_hosts = [] } = this;
57+
console.log(proxy_hosts)
58+
return [...proxy_hosts, ...redirect_hosts, ...dead_hosts].reduce((acc, host) => {
59+
acc.push(...(host.domain_names || []));
60+
return acc;
61+
}, []);
62+
}
5563
};
5664
},
5765

58-
getProxyHosts: function () {
59-
const hosts = this.model.attributes.proxy_hosts || [];
60-
return hosts.reduce((acc, host) => {
61-
acc.push(...(host.domain_names || []));
62-
return acc;
63-
}, []);
64-
},
6566

6667
initialize: function () {
6768
this.listenTo(this.model, 'change', this.render);

frontend/js/app/nginx/certificates/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = Mn.View.extend({
7474
e.preventDefault();
7575
let query = this.ui.query.val();
7676

77-
this.fetch(['owner','proxy_hosts'], query)
77+
this.fetch(['owner','proxy_hosts', 'dead_hosts', 'redirection_hosts'], query)
7878
.then(response => this.showData(response))
7979
.catch(err => {
8080
this.showError(err);
@@ -89,7 +89,7 @@ module.exports = Mn.View.extend({
8989
onRender: function () {
9090
let view = this;
9191

92-
view.fetch(['owner','proxy_hosts'])
92+
view.fetch(['owner','proxy_hosts', 'dead_hosts', 'redirection_hosts'])
9393
.then(response => {
9494
if (!view.isDestroyed()) {
9595
if (response && response.length) {

0 commit comments

Comments
 (0)