Commit cb8b5c0d by Daniel Lee

WIP: adding roles - not finished

parent 212a66ae
......@@ -4,7 +4,7 @@
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label">Type</span>
<select class="gf-form-input gf-size-auto" ng-model="ctrl.type" ng-options="r for r in ['User', 'User Group']"></select>
<select class="gf-form-input gf-size-auto" ng-model="ctrl.type" ng-options="r for r in ['User Group', 'User']"></select>
</div>
<div class="gf-form" ng-show="ctrl.type === 'User'">
<span class="gf-form-label">User</span>
......@@ -27,51 +27,46 @@
<div class="permissionlist">
<div class="permissionlist__section">
<div class="permissionlist__section-header">
<h6>Users</h6>
<h6>Permissions</h6>
</div>
<table class="filter-table form-inline">
<thead>
<tr>
<th>User</th>
<th style="width: 50px;"></th>
<th>Name</th>
<th style="width: 220px;">Permission</th>
<th style="width: 120px"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="permission in ctrl.userPermissions" class="permissionlist__item">
<td><i class="fa fa-fw fa-user"></i></td>
<td>{{permission.userLogin}}</td>
<td><select class="gf-form-input gf-size-auto" ng-model="permission.permissions" ng-options="p.value as p.text for p in ctrl.permissionTypeOptions" ng-change="ctrl.updatePermission(permission)"></select></td>
<td class="text-right">
<a ng-click="ctrl.removeUserPermission(permission)" class="btn btn-danger btn-small">
<a ng-click="ctrl.removePermission(permission)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
</a>
</td>
</tr>
</tbody>
</table>
</div>
<div class="permissionlist__section">
<div class="permissionlist__section-header">
<h6>Groups</h6>
</div>
<table class="filter-table form-inline">
<thead>
<tr>
<th>User Group</th>
<th style="width: 220px;">Permission</th>
<th style="width: 120px;"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="permission in ctrl.userGroupPermissions" class="permissionlist__item">
<td><i class="fa fa-fw fa-users"></i></td>
<td>{{permission.userGroup}}</td>
<td><select class="gf-form-input gf-size-auto" ng-model="permission.permissionType" ng-options="p.value as p.text for p in ctrl.permissionTypeOptions" ng-change="ctrl.updatePermission(permission)"></select></td>
<td><select class="gf-form-input gf-size-auto" ng-model="permission.permissions" ng-options="p.value as p.text for p in ctrl.permissionTypeOptions" ng-change="ctrl.updatePermission(permission)"></select></td>
<td class="text-right">
<a ng-click="ctrl.removeUserGroupPermission(permission)" class="btn btn-danger btn-small">
<a ng-click="ctrl.removePermission(permission)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
</a>
</td>
</tr>
<tr ng-repeat="role in ctrl.roles" class="permissionlist__item">
<td></td>
<td>{{role.name}}</td>
<td><select class="gf-form-input gf-size-auto" ng-model="role.permissions" ng-options="p.value as p.text for p in ctrl.roleOptions" ng-change="ctrl.updatePermission(role)"></select></td>
<td class="text-right">
</td>
</tr>
</tbody>
</table>
</div>
......
......@@ -15,12 +15,20 @@ export class AclCtrl {
{value: 4, text: 'Edit'}
];
type = 'User';
roleOptions = [
{value: 0, text: 'None'},
{value: 1, text: 'View'},
{value: 2, text: 'Read-only Edit'},
{value: 4, text: 'Edit'}
];
roles = [];
type = 'User Group';
permission = 1;
userId: number;
userGroupId: number;
/** @ngInject */
constructor(private backendSrv, private $scope) {
this.tabIndex = 0;
......@@ -30,13 +38,23 @@ export class AclCtrl {
}
get(dashboardId: number) {
return this.backendSrv.get(`/api/dashboards/${dashboardId}/acl`)
return this.backendSrv.get(`/api/dashboards/id/${dashboardId}/acl`)
.then(result => {
this.userPermissions = _.filter(result, p => { return p.userId > 0;});
this.userGroupPermissions = _.filter(result, p => { return p.userGroupId > 0;});
this.roles = this.setRoles(result);
});
}
setRoles(result: any) {
return [
{name: 'Org Viewer', permissions: 1},
{name: 'Org Read Only Editor', permissions: 2},
{name: 'Org Editor', permissions: 4},
{name: 'Org Admin', permissions: 4}
];
}
addPermission() {
if (this.type === 'User') {
if (!this.userId) {
......@@ -59,38 +77,32 @@ export class AclCtrl {
}
addOrUpdateUserPermission(userId: number, permissionType: number) {
return this.backendSrv.post(`/api/dashboards/${this.dashboard.id}/acl`, {
return this.backendSrv.post(`/api/dashboards/id/${this.dashboard.id}/acl`, {
userId: userId,
permissionType: permissionType
permissions: permissionType
});
}
addOrUpdateUserGroupPermission(userGroupId: number, permissionType: number) {
return this.backendSrv.post(`/api/dashboards/${this.dashboard.id}/acl`, {
return this.backendSrv.post(`/api/dashboards/id/${this.dashboard.id}/acl`, {
userGroupId: userGroupId,
permissionType: permissionType
permissions: permissionType
});
}
updatePermission(permission: any) {
if (permission.userId > 0) {
return this.addOrUpdateUserPermission(permission.userId, permission.permissionType);
return this.addOrUpdateUserPermission(permission.userId, permission.permissions);
} else {
if (!permission.userGroupId) {
return;
}
return this.addOrUpdateUserGroupPermission(permission.userGroupId, permission.permissionType);
return this.addOrUpdateUserGroupPermission(permission.userGroupId, permission.permissions);
}
}
removeUserPermission(permission: Permission) {
return this.backendSrv.delete(`/api/dashboards/${permission.dashboardId}/acl/user/${permission.userId}`).then(() => {
return this.get(permission.dashboardId);
});
}
removeUserGroupPermission(permission: Permission) {
return this.backendSrv.delete(`/api/dashboards/${permission.dashboardId}/acl/user-group/${permission.userGroupId}`).then(() => {
removePermission(permission: Permission) {
return this.backendSrv.delete(`/api/dashboards/id/${permission.dashboardId}/acl/${permission.id}`).then(() => {
return this.get(permission.dashboardId);
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment