Skip to content

Commit 7d9e716

Browse files
committed
Access lists
1 parent 13f08df commit 7d9e716

File tree

8 files changed

+38
-29
lines changed

8 files changed

+38
-29
lines changed

src/backend/internal/access-list.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const internalAccessList = {
128128
.then(row => {
129129
if (row) {
130130
if (typeof row.items !== 'undefined' && row.items) {
131-
row.items = internalAccessList.maskItems(row.items);
131+
row = internalAccessList.maskItems(row);
132132
}
133133

134134
return _.omit(row, omissions());
@@ -180,11 +180,14 @@ const internalAccessList = {
180180
.then(access_data => {
181181
let query = accessListModel
182182
.query()
183-
.where('is_deleted', 0)
184-
.groupBy('id')
185-
.omit(['is_deleted'])
183+
.select('access_list.*', accessListModel.raw('COUNT(proxy_hosts.id) as proxy_host_count'), accessListModel.raw('COUNT(items.id) as item_count'))
184+
.leftJoinRelation('proxy_hosts')
185+
.leftJoinRelation('items')
186+
.where('access_list.is_deleted', 0)
187+
.groupBy('access_list.id')
188+
.omit(['access_list.is_deleted'])
186189
.allowEager('[owner,items]')
187-
.orderBy('name', 'ASC');
190+
.orderBy('access_list.name', 'ASC');
188191

189192
if (access_data.permission_visibility !== 'all') {
190193
query.andWhere('owner_user_id', access.token.get('attrs').id);
@@ -207,7 +210,7 @@ const internalAccessList = {
207210
if (rows) {
208211
rows.map(function (row, idx) {
209212
if (typeof row.items !== 'undefined' && row.items) {
210-
rows[idx].items = internalAccessList.maskItems(row.items);
213+
rows[idx] = internalAccessList.maskItems(row);
211214
}
212215
});
213216
}

src/backend/models/access_list.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class AccessList extends Model {
3333
}
3434

3535
static get relationMappings () {
36+
const ProxyHost = require('./proxy_host');
37+
3638
return {
3739
owner: {
3840
relation: Model.HasOneRelation,
@@ -56,6 +58,18 @@ class AccessList extends Model {
5658
modify: function (qb) {
5759
qb.omit(['id', 'created_on', 'modified_on']);
5860
}
61+
},
62+
proxy_hosts: {
63+
relation: Model.HasManyRelation,
64+
modelClass: ProxyHost,
65+
join: {
66+
from: 'access_list.id',
67+
to: 'proxy_host.access_list_id'
68+
},
69+
modify: function (qb) {
70+
qb.where('proxy_host.is_deleted', 0);
71+
qb.omit(['id', 'created_on', 'modified_on', 'is_deleted', 'meta']);
72+
}
5973
}
6074
};
6175
}

src/frontend/js/app/nginx/access/list/item.ejs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,27 @@
55
</td>
66
<td>
77
<div>
8-
<% domain_names.map(function(host) {
9-
%>
10-
<span class="tag"><%- host %></span>
11-
<%
12-
});
13-
%>
8+
<%- name %>
149
</div>
1510
<div class="small text-muted">
1611
<%- i18n('str', 'created-on', {date: formatDbDate(created_on, 'Do MMMM YYYY')}) %>
1712
</div>
1813
</td>
1914
<td>
20-
<div class="text-monospace"><%- forward_ip %>:<%- forward_port %></div>
15+
<%- i18n('access-lists', 'item-count', {count: item_count}) %>
2116
</td>
2217
<td>
23-
<div><%- ssl_enabled && ssl_provider ? i18n('ssl', ssl_provider) : i18n('ssl', 'none') %></div>
24-
</td>
25-
<td>
26-
<div><%- access_list_id ? access_list.name : i18n('str', 'public') %></div>
18+
<%- i18n('access-lists', 'proxy-host-count', {count: proxy_host_count}) %>
2719
</td>
2820
<% if (canManage) { %>
2921
<td class="text-right">
3022
<div class="item-action dropdown">
3123
<a href="#" data-toggle="dropdown" class="icon"><i class="fe fe-more-vertical"></i></a>
3224
<div class="dropdown-menu dropdown-menu-right">
3325
<a href="#" class="edit dropdown-item"><i class="dropdown-icon fe fe-edit"></i> <%- i18n('str', 'edit') %></a>
34-
<a href="#" class="logs dropdown-item"><i class="dropdown-icon fe fe-book"></i> <%- i18n('str', 'logs') %></a>
3526
<div class="dropdown-divider"></div>
3627
<a href="#" class="delete dropdown-item"><i class="dropdown-icon fe fe-trash-2"></i> <%- i18n('str', 'delete') %></a>
3728
</div>
3829
</div>
3930
</td>
40-
<% } %>
31+
<% } %>

src/frontend/js/app/nginx/access/list/item.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ module.exports = Mn.View.extend({
1616
events: {
1717
'click @ui.edit': function (e) {
1818
e.preventDefault();
19-
App.Controller.showNginxProxyForm(this.model);
19+
App.Controller.showNginxAccessListForm(this.model);
2020
},
2121

2222
'click @ui.delete': function (e) {
2323
e.preventDefault();
24-
App.Controller.showNginxProxyDeleteConfirm(this.model);
24+
App.Controller.showNginxAccessListDeleteConfirm(this.model);
2525
}
2626
},
2727

2828
templateContext: {
29-
canManage: App.Cache.User.canManage('proxy_hosts')
29+
canManage: App.Cache.User.canManage('access_lists')
3030
},
3131

3232
initialize: function () {

src/frontend/js/app/nginx/access/list/main.ejs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<thead>
22
<th width="30">&nbsp;</th>
3-
<th><%- i18n('str', 'source') %></th>
4-
<th><%- i18n('str', 'destination') %></th>
5-
<th><%- i18n('str', 'ssl') %></th>
6-
<th><%- i18n('str', 'access') %></th>
3+
<th><%- i18n('str', 'name') %></th>
4+
<th><%- i18n('users', 'title') %></th>
5+
<th><%- i18n('proxy-hosts', 'title') %></th>
76
<% if (canManage) { %>
87
<th>&nbsp;</th>
98
<% } %>

src/frontend/js/app/nginx/access/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = Mn.View.extend({
4242
onRender: function () {
4343
let view = this;
4444

45-
App.Api.Nginx.AccessLists.getAll(['owner'])
45+
App.Api.Nginx.AccessLists.getAll(['owner', 'items'])
4646
.then(response => {
4747
if (!view.isDestroyed()) {
4848
if (response && response.length) {

src/frontend/js/app/ui/main.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
<!-- Footer View -->
1717
</footer>
1818

19-
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-hidden="true"></div>
19+
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false"></div>

src/frontend/js/i18n/messages.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@
155155
"delete-confirm": "Are you sure you want to delete this access list? Any hosts using it will need to be updated later.",
156156
"public": "Publicly Accessible",
157157
"help-title": "What is an Access List?",
158-
"help-content": "Access Lists provide authentication for the Proxy Hosts via Basic HTTP Authentication.\nYou can configure multiple usernames and passwords for a single Access List and then apply that to a Proxy Host.\nThis is most useful for forwarded web services that do not have authentication mechanisms built in."
158+
"help-content": "Access Lists provide authentication for the Proxy Hosts via Basic HTTP Authentication.\nYou can configure multiple usernames and passwords for a single Access List and then apply that to a Proxy Host.\nThis is most useful for forwarded web services that do not have authentication mechanisms built in.",
159+
"item-count": "{count} {count, select, 1{User} other{Users}}",
160+
"proxy-host-count": "{count} {count, select, 1{Proxy Host} other{Proxy Hosts}}"
159161
},
160162
"users": {
161163
"title": "Users",

0 commit comments

Comments
 (0)