Remove add item buttons when there are no permissions

This commit is contained in:
Jamie Curnow 2018-07-10 18:23:14 +10:00
parent 0455920355
commit 74d2238010
8 changed files with 48 additions and 11 deletions

View File

@ -3,7 +3,9 @@
<div class="card-header"> <div class="card-header">
<h3 class="card-title">404 Hosts</h3> <h3 class="card-title">404 Hosts</h3>
<div class="card-options"> <div class="card-options">
<% if (showAddButton) { %>
<a href="#" class="btn btn-outline-danger btn-sm ml-2 add-item">Add 404 Host</a> <a href="#" class="btn btn-outline-danger btn-sm ml-2 add-item">Add 404 Host</a>
<% } %>
</div> </div>
</div> </div>
<div class="card-body no-padding min-100"> <div class="card-body no-padding min-100">

View File

@ -3,6 +3,7 @@
const Mn = require('backbone.marionette'); const Mn = require('backbone.marionette');
const DeadHostModel = require('../../../models/dead-host'); const DeadHostModel = require('../../../models/dead-host');
const Api = require('../../api'); const Api = require('../../api');
const Cache = require('../../cache');
const Controller = require('../../controller'); const Controller = require('../../controller');
const ListView = require('./list/main'); const ListView = require('./list/main');
const ErrorView = require('../../error/main'); const ErrorView = require('../../error/main');
@ -30,6 +31,10 @@ module.exports = Mn.View.extend({
} }
}, },
templateContext: {
showAddButton: Cache.User.canManage('dead_hosts')
},
onRender: function () { onRender: function () {
let view = this; let view = this;
@ -41,10 +46,12 @@ module.exports = Mn.View.extend({
collection: new DeadHostModel.Collection(response) collection: new DeadHostModel.Collection(response)
})); }));
} else { } else {
let manage = Cache.User.canManage('dead_hosts');
view.showChildView('list_region', new EmptyView({ view.showChildView('list_region', new EmptyView({
title: 'There are no 404 Hosts', title: 'There are no 404 Hosts',
subtitle: 'Why don\'t you create one?', subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
link: 'Add 404 Host', link: manage ? 'Add 404 Host' : null,
btn_color: 'danger', btn_color: 'danger',
action: function () { action: function () {
Controller.showNginxDeadForm(); Controller.showNginxDeadForm();

View File

@ -3,7 +3,9 @@
<div class="card-header"> <div class="card-header">
<h3 class="card-title">Proxy Hosts</h3> <h3 class="card-title">Proxy Hosts</h3>
<div class="card-options"> <div class="card-options">
<% if (showAddButton) { %>
<a href="#" class="btn btn-outline-success btn-sm ml-2 add-item">Add Proxy Host</a> <a href="#" class="btn btn-outline-success btn-sm ml-2 add-item">Add Proxy Host</a>
<% } %>
</div> </div>
</div> </div>
<div class="card-body no-padding min-100"> <div class="card-body no-padding min-100">

View File

@ -3,6 +3,7 @@
const Mn = require('backbone.marionette'); const Mn = require('backbone.marionette');
const ProxyHostModel = require('../../../models/proxy-host'); const ProxyHostModel = require('../../../models/proxy-host');
const Api = require('../../api'); const Api = require('../../api');
const Cache = require('../../cache');
const Controller = require('../../controller'); const Controller = require('../../controller');
const ListView = require('./list/main'); const ListView = require('./list/main');
const ErrorView = require('../../error/main'); const ErrorView = require('../../error/main');
@ -30,6 +31,10 @@ module.exports = Mn.View.extend({
} }
}, },
templateContext: {
showAddButton: Cache.User.canManage('proxy_hosts')
},
onRender: function () { onRender: function () {
let view = this; let view = this;
@ -41,11 +46,14 @@ module.exports = Mn.View.extend({
collection: new ProxyHostModel.Collection(response) collection: new ProxyHostModel.Collection(response)
})); }));
} else { } else {
let manage = Cache.User.canManage('proxy_hosts');
view.showChildView('list_region', new EmptyView({ view.showChildView('list_region', new EmptyView({
title: 'There are no Proxy Hosts', title: 'There are no Proxy Hosts',
subtitle: 'Why don\'t you create one?', subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
link: 'Add Proxy Host', link: manage ? 'Add Proxy Host' : null,
btn_color: 'success', btn_color: 'success',
permission: 'proxy_hosts',
action: function () { action: function () {
Controller.showNginxProxyForm(); Controller.showNginxProxyForm();
} }

View File

@ -3,7 +3,9 @@
<div class="card-header"> <div class="card-header">
<h3 class="card-title">Redirection Hosts</h3> <h3 class="card-title">Redirection Hosts</h3>
<div class="card-options"> <div class="card-options">
<% if (showAddButton) { %>
<a href="#" class="btn btn-outline-yellow btn-sm ml-2 add-item">Add Redirection Host</a> <a href="#" class="btn btn-outline-yellow btn-sm ml-2 add-item">Add Redirection Host</a>
<% } %>
</div> </div>
</div> </div>
<div class="card-body no-padding min-100"> <div class="card-body no-padding min-100">

View File

@ -3,6 +3,7 @@
const Mn = require('backbone.marionette'); const Mn = require('backbone.marionette');
const RedirectionHostModel = require('../../../models/redirection-host'); const RedirectionHostModel = require('../../../models/redirection-host');
const Api = require('../../api'); const Api = require('../../api');
const Cache = require('../../cache');
const Controller = require('../../controller'); const Controller = require('../../controller');
const ListView = require('./list/main'); const ListView = require('./list/main');
const ErrorView = require('../../error/main'); const ErrorView = require('../../error/main');
@ -30,6 +31,10 @@ module.exports = Mn.View.extend({
} }
}, },
templateContext: {
showAddButton: Cache.User.canManage('redirection_hosts')
},
onRender: function () { onRender: function () {
let view = this; let view = this;
@ -41,10 +46,12 @@ module.exports = Mn.View.extend({
collection: new RedirectionHostModel.Collection(response) collection: new RedirectionHostModel.Collection(response)
})); }));
} else { } else {
let manage = Cache.User.canManage('redirection_hosts');
view.showChildView('list_region', new EmptyView({ view.showChildView('list_region', new EmptyView({
title: 'There are no Redirection Hosts', title: 'There are no Redirection Hosts',
subtitle: 'Why don\'t you create one?', subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
link: 'Add Redirection Host', link: manage ? 'Add Redirection Host' : null,
btn_color: 'yellow', btn_color: 'yellow',
action: function () { action: function () {
Controller.showNginxRedirectionForm(); Controller.showNginxRedirectionForm();

View File

@ -3,7 +3,9 @@
<div class="card-header"> <div class="card-header">
<h3 class="card-title">Streams</h3> <h3 class="card-title">Streams</h3>
<div class="card-options"> <div class="card-options">
<% if (showAddButton) { %>
<a href="#" class="btn btn-outline-blue btn-sm ml-2 add-item">Add Stream</a> <a href="#" class="btn btn-outline-blue btn-sm ml-2 add-item">Add Stream</a>
<% } %>
</div> </div>
</div> </div>
<div class="card-body no-padding min-100"> <div class="card-body no-padding min-100">

View File

@ -3,6 +3,7 @@
const Mn = require('backbone.marionette'); const Mn = require('backbone.marionette');
const StreamModel = require('../../../models/stream'); const StreamModel = require('../../../models/stream');
const Api = require('../../api'); const Api = require('../../api');
const Cache = require('../../cache');
const Controller = require('../../controller'); const Controller = require('../../controller');
const ListView = require('./list/main'); const ListView = require('./list/main');
const ErrorView = require('../../error/main'); const ErrorView = require('../../error/main');
@ -30,6 +31,10 @@ module.exports = Mn.View.extend({
} }
}, },
templateContext: {
showAddButton: Cache.User.canManage('streams')
},
onRender: function () { onRender: function () {
let view = this; let view = this;
@ -41,10 +46,12 @@ module.exports = Mn.View.extend({
collection: new StreamModel.Collection(response) collection: new StreamModel.Collection(response)
})); }));
} else { } else {
let manage = Cache.User.canManage('streams');
view.showChildView('list_region', new EmptyView({ view.showChildView('list_region', new EmptyView({
title: 'There are no Streams', title: 'There are no Streams',
subtitle: 'Why don\'t you create one?', subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
link: 'Add Stream', link: manage ? 'Add Stream' : null,
btn_color: 'blue', btn_color: 'blue',
action: function () { action: function () {
Controller.showNginxStreamForm(); Controller.showNginxStreamForm();