Skip to content

Commit

Permalink
✨ Role-based login for election manager (#393)
Browse files Browse the repository at this point in the history
Parent issue: sequentech/meta#127
  • Loading branch information
Findeton committed Sep 20, 2023
1 parent b133e70 commit 2d69268
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 63 deletions.
33 changes: 26 additions & 7 deletions avAdmin/admin-controller/admin-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ angular
var id = $stateParams.id;
$scope.electionId = id;

// get election perms, with a default of no perms
$scope.perms = {val: ""};

$scope.state = $state.current.name;
$scope.current = null;
$scope.noplugin = true;
Expand Down Expand Up @@ -219,13 +216,30 @@ angular
Plugins.hook('add-dashboard-election-states', plugins_data);
states = states.concat(plugins_data.states);


$scope.hasPerms = function (optionList) {
return optionList.some(function (option ) {
return $scope.perms.val.includes(option);
});
};

// get election perms, with a default of no perms
$scope.perms = {val: ""};
ElectionsApi
.getEditPerm($scope.electionId)
.then(
function (perm) {
$scope.perms.val = perm.split(":")[4].split("|");
}
);

$scope.globalPerms = {val: ""};
// update global perms
ElectionsApi
.getEditPerm(null)
.then(
function (perm) {
$scope.globalPerms.val = perm;
$scope.globalPerms.val = perm.split(":")[4].split("|");
}
);

Expand Down Expand Up @@ -258,7 +272,6 @@ angular

if (
perm.indexOf('event-view-activity') !== -1 ||
perm.indexOf('view') !== -1 ||
perm.indexOf('edit') !== -1
) {
$scope.sidebarlinks = $scope.sidebarlinks.concat([
Expand All @@ -268,7 +281,7 @@ angular


// update election perms
$scope.perms.val = perm;
$scope.perms.val = perm.split(":")[4].split("|");
}
);
}
Expand All @@ -279,7 +292,13 @@ angular
{name: 'questions', icon: 'question-circle'},
{name: 'auth', icon: 'unlock'},
{name: 'censusConfig', icon: 'newspaper-o'},
{name: 'census', icon: 'users'},
{
name: 'census',
icon: 'users',
permsFunc: function() {
return $scope.hasPerms(["view-census", "edit"]);
}
},
//{name: 'successAction', icon: 'star-o'},
{name: 'adminFields', icon: 'user'},
//{name: 'tally', icon: 'pie-chart'},
Expand Down
1 change: 1 addition & 0 deletions avAdmin/admin-directives/ballot-box/ballot-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ <h2 ng-i18next>avAdmin.ballotBox.title</h2>
<td class="small-col text-right actions">
<span
ng-repeat="command in row_commands"
ng-if="command.permsFunc()"
ng-class="{'disabled': !command.enableFunc(obj)}">
<a ng-click="command.actionFunc(obj)">
<i class="{{command.iconClass}}"
Expand Down
12 changes: 12 additions & 0 deletions avAdmin/admin-directives/ballot-box/ballot-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ angular.module('avAdmin')
ballotBox.num_tally_sheets > 0 &&
ElectionsApi.getCachedEditPerm(scope.electionId).indexOf('list-tally-sheets') !== -1
);
},
permsFunc: function() {
return scope.hasPerms(["list-tally-sheets", "edit"]);
}
},
{
Expand Down Expand Up @@ -313,6 +316,9 @@ angular.module('avAdmin')
)
)
);
},
permsFunc: function() {
return scope.hasPerms(["override-tally-sheets", "add-tally-sheets"]);
}
},
{
Expand Down Expand Up @@ -351,6 +357,9 @@ angular.module('avAdmin')
ballotBox.num_tally_sheets > 0 &&
ElectionsApi.getCachedEditPerm(scope.electionId).indexOf('delete-tally-sheets') !== -1
);
},
permsFunc: function() {
return scope.hasPerms(["delete-tally-sheets"]);
}
},
{
Expand All @@ -377,6 +386,9 @@ angular.module('avAdmin')
return (
ElectionsApi.getCachedEditPerm(scope.electionId).indexOf('delete-ballot-boxes') !== -1
);
},
permsFunc: function() {
return scope.hasPerms(["delete-ballot-boxes"]);
}
}
];
Expand Down
15 changes: 8 additions & 7 deletions avAdmin/admin-directives/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>
</h2>
</span>
</div>
<div class="dropdown pull-right actions-div">
<div class="dropdown pull-right actions-div" ng-if="permittedActions().length > 0">
<button
class="btn btn-success actionbtn ng-scope btn-primary dropdown-toggle"
type="button"
Expand All @@ -22,7 +22,7 @@ <h2>
</button>
<ul class="dropdown-menu">
<li
ng-repeat="action in actions"
ng-repeat="action in permittedActions()"
ng-class="{'disabled': !action.enableFunc()}">
<a ng-click="action.enableFunc() && action.actionFunc()">
<i class="{{action.iconClass}}"></i>
Expand Down Expand Up @@ -71,9 +71,9 @@ <h2>
</div>
<button
ng-click="doActionConfirm($index)"
class="actionbtn btn btn-success"
class="actionbtn btn btn-success"
ng-disabled="!commands[$index].enableFunc()"
ng-if="index == $index && nextaction"
ng-if="index == $index && nextaction && commands[$index].permsFunc()"
ng-class="['election-status-action-' + index]">
<div
class="small {{ nextaction }}"
Expand All @@ -88,7 +88,7 @@ <h2>
ng-click="doActionConfirm($index)"
class="actionbtn btn btn-success"
ng-disabled="!commands[$index].enableFunc()"
ng-if="getStatusIndex('results_ok') === $index && index === 1 + $index"
ng-if="getStatusIndex('results_ok') === $index && index === 1 + $index && commands[$index].permsFunc()"
>
<div
class="small"
Expand Down Expand Up @@ -123,7 +123,7 @@ <h2>
<strong>{{ election.auth.census|number }}</strong><br/>
<button
ng-click="sendAuthCodes()"
ng-disabled="perms.val.indexOf('send-auth-all') === -1 && perms.val.indexOf('edit') === -1"
ng-if="scope.hasPerms(['send-auth-all', 'edit'])"
class="btn btn-success send-auth pull-left">
<i class="fa fa-sw fa-send"></i>
<span ng-i18next>
Expand Down Expand Up @@ -161,14 +161,15 @@ <h2>

<button
class="btn btn-block btn-lg btn-success-action"
ng-if="nextaction"
ng-if="nextaction && commands[index].permsFunc()"
ng-disabled="!commands[index].enableFunc()"
ng-i18next="{{ nextaction }}"
ng-click="doActionConfirm(index)">
</button>

<button
ng-click="duplicateElection()"
ng-if="hasPerms(['create'])"
class="btn btn-block btn-lg btn-success"
ng-i18next>
avAdmin.dashboard.duplicateElection
Expand Down
Loading

0 comments on commit 2d69268

Please sign in to comment.