Skip to content
Merged
8 changes: 6 additions & 2 deletions proxies/client/proxies.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
</div>
<div class="col-md-6">
<h2>
<button class="btn btn-default btn-sm pull-right" id="add-proxy">{{ _ "proxies_addProxy" }}</button>
{{ # unless hideAddProxyButton }}
<button class="btn btn-default btn-sm pull-right" id="add-proxy">
{{ _ "proxies_addProxy" }}
</button>
{{ / unless }}
{{ _ "proxies_pageHeader" }}
</h2>
<hr>
<div class="">
<div>
{{# if Template.subscriptionsReady }}
{{ # if proxies }}
{{ # each proxy in proxies }}
Expand Down
6 changes: 6 additions & 0 deletions proxies/client/proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ Template.proxies.helpers({

return proxies;
},
hideAddProxyButton () {
const proxiesCount = Proxies.find().count();

// Set button disabled if at least one proxy is already added
return proxiesCount >= 1;
},
});
6 changes: 6 additions & 0 deletions proxies/collection/permissions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Proxies } from './';
import { Roles } from 'meteor/alanning:roles';

Proxies.allow({
insert (userId, proxy) {
// Check if proxy is already exist
if (Proxies.find().count() >= 1) {
return false;
}

// Check if user has admin role
return Roles.userIsInRole(userId, ['admin']);
},
Expand Down