mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'develop' of github.com:grafana/grafana into develop
This commit is contained in:
@@ -90,7 +90,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/user-groups/edit/:id', {
|
||||
templateUrl: 'public/app/features/org/partials/edit_user_group.html',
|
||||
templateUrl: 'public/app/features/org/partials/user_group_details.html',
|
||||
controller : 'UserGroupDetailsCtrl',
|
||||
controllerAs: 'ctrl',
|
||||
resolve: loadOrgBundle,
|
||||
|
@@ -39,22 +39,30 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<form name="addPermission" class="gf-form-group">
|
||||
<h6 class="muted">Add Permission For</h6>
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form">
|
||||
<div class="gf-form-select-wrapper">
|
||||
<select class="gf-form-input gf-size-auto" ng-model="ctrl.newType" ng-options="p.value as p.text for p in ctrl.aclTypes" ng-change="ctrl.typeChanged()"></select>
|
||||
<div class="gf-form-inline">
|
||||
<form name="addPermission" class="gf-form-group">
|
||||
<h6 class="muted">Add Permission For</h6>
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form">
|
||||
<div class="gf-form-select-wrapper">
|
||||
<select class="gf-form-input gf-size-auto" ng-model="ctrl.newType" ng-options="p.value as p.text for p in ctrl.aclTypes" ng-change="ctrl.typeChanged()"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form" ng-show="ctrl.newType === 'User'">
|
||||
<user-picker user-picked="ctrl.userPicked($user)"></user-picker>
|
||||
</div>
|
||||
<div class="gf-form" ng-show="ctrl.newType === 'Group'">
|
||||
<user-group-picker user-group-picked="ctrl.groupPicked($group)"></user-group-picker>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form" ng-show="ctrl.newType === 'User'">
|
||||
<user-picker user-picked="ctrl.userPicked($user)"></user-picker>
|
||||
</div>
|
||||
<div class="gf-form" ng-show="ctrl.newType === 'Group'">
|
||||
<user-group-picker user-group-picked="ctrl.groupPicked($group)"></user-group-picker>
|
||||
</div>
|
||||
</form>
|
||||
<div class="gf-form width-17">
|
||||
<span ng-if="ctrl.error" class="text-error p-l-1">
|
||||
<i class="fa fa-warning"></i>
|
||||
{{ctrl.error}}
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-button-row text-center">
|
||||
<button type="button" class="btn btn-danger" ng-disabled="!ctrl.canUpdate" ng-click="ctrl.update()">
|
||||
@@ -62,9 +70,8 @@
|
||||
</button>
|
||||
<a class="btn-text" ng-click="ctrl.dismiss();">Close</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <br> -->
|
||||
<!-- <br> -->
|
||||
|
@@ -22,6 +22,8 @@ export class AclCtrl {
|
||||
dismiss: () => void;
|
||||
newType: string;
|
||||
canUpdate: boolean;
|
||||
error: string;
|
||||
readonly duplicateError = 'This permission exists already.';
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv, private dashboardSrv, private $sce, private $scope) {
|
||||
@@ -111,6 +113,11 @@ export class AclCtrl {
|
||||
}
|
||||
|
||||
addNewItem(item) {
|
||||
if (!this.isValid(item)) {
|
||||
return;
|
||||
}
|
||||
this.error = '';
|
||||
|
||||
item.dashboardId = this.dashboard.id;
|
||||
|
||||
this.items.push(this.prepareViewModel(item));
|
||||
@@ -119,6 +126,23 @@ export class AclCtrl {
|
||||
this.canUpdate = true;
|
||||
}
|
||||
|
||||
isValid(item) {
|
||||
const dupe = _.find(this.items, (it) => { return this.isDuplicate(it, item); });
|
||||
|
||||
if (dupe) {
|
||||
this.error = this.duplicateError;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
isDuplicate(origItem, newItem) {
|
||||
return (origItem.role && newItem.role && origItem.role === newItem.role) ||
|
||||
(origItem.userId && newItem.userId && origItem.userId === newItem.userId) ||
|
||||
(origItem.userGroupId && newItem.userGroupId && origItem.userGroupId === newItem.userGroupId);
|
||||
}
|
||||
|
||||
userPicked(user) {
|
||||
this.addNewItem({userId: user.id, userLogin: user.login, permission: 1,});
|
||||
this.$scope.$broadcast('user-picker-reset');
|
||||
|
@@ -77,4 +77,74 @@ describe('AclCtrl', () => {
|
||||
expect(backendSrv.post.getCall(0).args[1].items[3].permission).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate role permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
backendSrv.get.reset();
|
||||
backendSrv.post.reset();
|
||||
ctx.ctrl.items = [];
|
||||
|
||||
ctx.ctrl.newType = 'Editor';
|
||||
ctx.ctrl.typeChanged();
|
||||
|
||||
ctx.ctrl.newType = 'Editor';
|
||||
ctx.ctrl.typeChanged();
|
||||
});
|
||||
|
||||
it('should throw a validation error', () => {
|
||||
expect(ctx.ctrl.error).to.eql(ctx.ctrl.duplicateError);
|
||||
});
|
||||
|
||||
it('should not add the duplicate permission', () => {
|
||||
expect(ctx.ctrl.items.length).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate user permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
backendSrv.get.reset();
|
||||
backendSrv.post.reset();
|
||||
ctx.ctrl.items = [];
|
||||
|
||||
const userItem = {
|
||||
id: 2,
|
||||
login: 'user2',
|
||||
};
|
||||
|
||||
ctx.ctrl.userPicked(userItem);
|
||||
ctx.ctrl.userPicked(userItem);
|
||||
});
|
||||
|
||||
it('should throw a validation error', () => {
|
||||
expect(ctx.ctrl.error).to.eql(ctx.ctrl.duplicateError);
|
||||
});
|
||||
|
||||
it('should not add the duplicate permission', () => {
|
||||
expect(ctx.ctrl.items.length).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate user group permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
backendSrv.get.reset();
|
||||
backendSrv.post.reset();
|
||||
ctx.ctrl.items = [];
|
||||
|
||||
const userGroupItem = {
|
||||
id: 2,
|
||||
name: 'ug1',
|
||||
};
|
||||
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
});
|
||||
|
||||
it('should throw a validation error', () => {
|
||||
expect(ctx.ctrl.error).to.eql(ctx.ctrl.duplicateError);
|
||||
});
|
||||
|
||||
it('should not add the duplicate permission', () => {
|
||||
expect(ctx.ctrl.items.length).to.eql(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user