diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js index bdbdb703..f2e845a2 100644 --- a/backend/internal/certificate.js +++ b/backend/internal/certificate.js @@ -314,6 +314,8 @@ const internalCertificate = { .andWhere('id', data.id) .allowGraph('[owner]') .allowGraph('[proxy_hosts]') + .allowGraph('[redirection_hosts]') + .allowGraph('[dead_hosts]') .first(); if (access_data.permission_visibility !== 'all') { @@ -466,6 +468,8 @@ const internalCertificate = { .groupBy('id') .allowGraph('[owner]') .allowGraph('[proxy_hosts]') + .allowGraph('[redirection_hosts]') + .allowGraph('[dead_hosts]') .orderBy('nice_name', 'ASC'); if (access_data.permission_visibility !== 'all') { diff --git a/backend/models/certificate.js b/backend/models/certificate.js index 5790900c..294d6de5 100644 --- a/backend/models/certificate.js +++ b/backend/models/certificate.js @@ -67,8 +67,11 @@ class Certificate extends Model { } static get relationMappings () { - const ProxyHost = require('./proxy_host'); - const User = require('./user'); + const ProxyHost = require('./proxy_host'); + const DeadHost = require('./dead_host'); + const User = require('./user'); + const RedirectionHost = require('./redirection_host'); + return { owner: { relation: Model.HasOneRelation, @@ -91,6 +94,28 @@ class Certificate extends Model { modify: function (qb) { qb.where('proxy_host.is_deleted', 0); } + }, + dead_hosts: { + relation: Model.HasManyRelation, + modelClass: DeadHost, + join: { + from: 'certificate.id', + to: 'dead_host.certificate_id' + }, + modify: function (qb) { + qb.where('dead_host.is_deleted', 0); + } + }, + redirection_hosts: { + relation: Model.HasManyRelation, + modelClass: RedirectionHost, + join: { + from: 'certificate.id', + to: 'redirection_host.certificate_id' + }, + modify: function (qb) { + qb.where('redirection_host.is_deleted', 0); + } } }; } diff --git a/frontend/js/app/nginx/certificates/list/item.ejs b/frontend/js/app/nginx/certificates/list/item.ejs index b3d0ab7a..1f6a25a3 100644 --- a/frontend/js/app/nginx/certificates/list/item.ejs +++ b/frontend/js/app/nginx/certificates/list/item.ejs @@ -34,7 +34,7 @@ <%- formatDbDate(expires_on, 'Do MMMM YYYY, h:mm a') %> - <% if (proxy_hosts.length > 0) { %> + <% if (active_domain_names().length > 0) { %> <%- i18n('certificates', 'in-use') %> <% } else { %> <%- i18n('certificates', 'inactive') %> @@ -55,10 +55,10 @@ <% } %> <%- i18n('str', 'delete') %> - <% if (proxy_hosts.length > 0) { %> + <% if (active_domain_names().length > 0) { %> <%- i18n('certificates', 'active-domain_names') %> - <% proxy_hosts.forEach(function(host) { %> + <% active_domain_names().forEach(function(host) { %> <%- host %> <% }); %> <% } %> diff --git a/frontend/js/app/nginx/certificates/list/item.js b/frontend/js/app/nginx/certificates/list/item.js index d73466c3..35cfea17 100644 --- a/frontend/js/app/nginx/certificates/list/item.js +++ b/frontend/js/app/nginx/certificates/list/item.js @@ -48,20 +48,21 @@ module.exports = Mn.View.extend({ return { canManage: App.Cache.User.canManage('certificates'), isExpired: function () { + console.log(this); return moment(this.expires_on).isBefore(moment()); }, dns_providers: dns_providers, - proxy_hosts: this.getProxyHosts() + active_domain_names: function () { + const { proxy_hosts = [], redirect_hosts = [], dead_hosts = [] } = this; + console.log(proxy_hosts) + return [...proxy_hosts, ...redirect_hosts, ...dead_hosts].reduce((acc, host) => { + acc.push(...(host.domain_names || [])); + return acc; + }, []); + } }; }, - getProxyHosts: function () { - const hosts = this.model.attributes.proxy_hosts || []; - return hosts.reduce((acc, host) => { - acc.push(...(host.domain_names || [])); - return acc; - }, []); - }, initialize: function () { this.listenTo(this.model, 'change', this.render); diff --git a/frontend/js/app/nginx/certificates/main.js b/frontend/js/app/nginx/certificates/main.js index 1192873b..3f9f022e 100644 --- a/frontend/js/app/nginx/certificates/main.js +++ b/frontend/js/app/nginx/certificates/main.js @@ -74,7 +74,7 @@ module.exports = Mn.View.extend({ e.preventDefault(); let query = this.ui.query.val(); - this.fetch(['owner','proxy_hosts'], query) + this.fetch(['owner','proxy_hosts', 'dead_hosts', 'redirection_hosts'], query) .then(response => this.showData(response)) .catch(err => { this.showError(err); @@ -89,7 +89,7 @@ module.exports = Mn.View.extend({ onRender: function () { let view = this; - view.fetch(['owner','proxy_hosts']) + view.fetch(['owner','proxy_hosts', 'dead_hosts', 'redirection_hosts']) .then(response => { if (!view.isDestroyed()) { if (response && response.length) {