mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'refactor-user-group-to-team' of https://github.com/alexanderzobnin/grafana into user-group-to-team
This commit is contained in:
@@ -10,9 +10,9 @@ const template = `
|
||||
</gf-form-dropdown>
|
||||
</div>
|
||||
`;
|
||||
export class UserGroupPickerCtrl {
|
||||
export class TeamPickerCtrl {
|
||||
group: any;
|
||||
userGroupPicked: any;
|
||||
teamPicked: any;
|
||||
debouncedSearchGroups: any;
|
||||
|
||||
/** @ngInject */
|
||||
@@ -26,34 +26,34 @@ export class UserGroupPickerCtrl {
|
||||
}
|
||||
|
||||
searchGroups(query: string) {
|
||||
return Promise.resolve(this.backendSrv.get('/api/user-groups/search?perpage=10&page=1&query=' + query).then(result => {
|
||||
return _.map(result.userGroups, ug => {
|
||||
return Promise.resolve(this.backendSrv.get('/api/teams/search?perpage=10&page=1&query=' + query).then(result => {
|
||||
return _.map(result.teams, ug => {
|
||||
return {text: ug.name, value: ug};
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
onChange(option) {
|
||||
this.userGroupPicked({$group: option.value});
|
||||
this.teamPicked({$group: option.value});
|
||||
}
|
||||
}
|
||||
|
||||
export function userGroupPicker() {
|
||||
export function teamPicker() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: template,
|
||||
controller: UserGroupPickerCtrl,
|
||||
controller: TeamPickerCtrl,
|
||||
bindToController: true,
|
||||
controllerAs: 'ctrl',
|
||||
scope: {
|
||||
userGroupPicked: '&',
|
||||
teamPicked: '&',
|
||||
},
|
||||
link: function(scope, elem, attrs, ctrl) {
|
||||
scope.$on("user-group-picker-reset", () => {
|
||||
scope.$on("team-picker-reset", () => {
|
||||
ctrl.reset();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
coreModule.directive('userGroupPicker', userGroupPicker);
|
||||
coreModule.directive('teamPicker', teamPicker);
|
||||
@@ -47,7 +47,7 @@ import {helpModal} from './components/help/help';
|
||||
import {JsonExplorer} from './components/json_explorer/json_explorer';
|
||||
import {NavModelSrv, NavModel} from './nav_model_srv';
|
||||
import {userPicker} from './components/user_picker';
|
||||
import {userGroupPicker} from './components/user_group_picker';
|
||||
import {teamPicker} from './components/team_picker';
|
||||
import {geminiScrollbar} from './components/scroll/scroll';
|
||||
import {gfPageDirective} from './components/gf_page';
|
||||
import {orgSwitcher} from './components/org_switcher';
|
||||
@@ -85,7 +85,7 @@ export {
|
||||
NavModelSrv,
|
||||
NavModel,
|
||||
userPicker,
|
||||
userGroupPicker,
|
||||
teamPicker,
|
||||
geminiScrollbar,
|
||||
gfPageDirective,
|
||||
orgSwitcher,
|
||||
|
||||
@@ -109,15 +109,15 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
|
||||
controller : 'OrgApiKeysCtrl',
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/user-groups', {
|
||||
templateUrl: 'public/app/features/org/partials/user_groups.html',
|
||||
controller : 'UserGroupsCtrl',
|
||||
.when('/org/teams', {
|
||||
templateUrl: 'public/app/features/org/partials/teams.html',
|
||||
controller : 'TeamsCtrl',
|
||||
controllerAs: 'ctrl',
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/user-groups/edit/:id', {
|
||||
templateUrl: 'public/app/features/org/partials/user_group_details.html',
|
||||
controller : 'UserGroupDetailsCtrl',
|
||||
.when('/org/teams/edit/:id', {
|
||||
templateUrl: 'public/app/features/org/partials/team_details.html',
|
||||
controller : 'TeamDetailsCtrl',
|
||||
controllerAs: 'ctrl',
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<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>
|
||||
<team-picker team-picked="ctrl.groupPicked($group)"></team-picker>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -101,9 +101,9 @@
|
||||
<!-- </a> -->
|
||||
<!-- </td> -->
|
||||
<!-- </tr> -->
|
||||
<!-- <tr ng-repeat="permission in ctrl.userGroupPermissions" class="permissionlist__item"> -->
|
||||
<!-- <tr ng-repeat="permission in ctrl.teamPermissions" class="permissionlist__item"> -->
|
||||
<!-- <td><i class="fa fa-fw fa-users"></i></td> -->
|
||||
<!-- <td>{{permission.userGroup}}</td> -->
|
||||
<!-- <td>{{permission.team}}</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.removePermission(permission)" class="btn btn-danger btn-small"> -->
|
||||
|
||||
@@ -12,7 +12,7 @@ export class AclCtrl {
|
||||
{value: 4, text: 'Admin'}
|
||||
];
|
||||
aclTypes = [
|
||||
{value: 'Group', text: 'User Group'},
|
||||
{value: 'Group', text: 'Team'},
|
||||
{value: 'User', text: 'User'},
|
||||
{value: 'Viewer', text: 'Everyone With Viewer Role'},
|
||||
{value: 'Editor', text: 'Everyone With Editor Role'}
|
||||
@@ -58,10 +58,10 @@ export class AclCtrl {
|
||||
item.nameHtml = this.$sce.trustAsHtml(item.userLogin);
|
||||
item.sortName = item.userLogin;
|
||||
item.sortRank = 10;
|
||||
} else if (item.userGroupId > 0) {
|
||||
} else if (item.teamId > 0) {
|
||||
item.icon = "fa fa-fw fa-users";
|
||||
item.nameHtml = this.$sce.trustAsHtml(item.userGroup);
|
||||
item.sortName = item.userGroup;
|
||||
item.nameHtml = this.$sce.trustAsHtml(item.team);
|
||||
item.sortName = item.team;
|
||||
item.sortRank = 20;
|
||||
} else if (item.role) {
|
||||
item.icon = "fa fa-fw fa-street-view";
|
||||
@@ -89,7 +89,7 @@ export class AclCtrl {
|
||||
updated.push({
|
||||
id: item.id,
|
||||
userId: item.userId,
|
||||
userGroupId: item.userGroupId,
|
||||
teamId: item.teamId,
|
||||
role: item.role,
|
||||
permission: item.permission,
|
||||
});
|
||||
@@ -144,7 +144,7 @@ export class AclCtrl {
|
||||
|
||||
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);
|
||||
(origItem.teamId && newItem.teamId && origItem.teamId === newItem.teamId);
|
||||
}
|
||||
|
||||
userPicked(user) {
|
||||
@@ -153,8 +153,8 @@ export class AclCtrl {
|
||||
}
|
||||
|
||||
groupPicked(group) {
|
||||
this.addNewItem({userGroupId: group.id, userGroup: group.name, permission: 1});
|
||||
this.$scope.$broadcast('user-group-picker-reset');
|
||||
this.addNewItem({teamId: group.id, team: group.name, permission: 1});
|
||||
this.$scope.$broadcast('team-picker-reset');
|
||||
}
|
||||
|
||||
removeItem(index) {
|
||||
@@ -179,7 +179,7 @@ export function dashAclModal() {
|
||||
export interface FormModel {
|
||||
dashboardId: number;
|
||||
userId?: number;
|
||||
userGroupId?: number;
|
||||
teamId?: number;
|
||||
PermissionType: number;
|
||||
}
|
||||
|
||||
@@ -189,8 +189,8 @@ export interface DashboardAcl {
|
||||
userId?: number;
|
||||
userLogin?: string;
|
||||
userEmail?: string;
|
||||
userGroupId?: number;
|
||||
userGroup?: string;
|
||||
teamId?: number;
|
||||
team?: string;
|
||||
permission?: number;
|
||||
permissionName?: string;
|
||||
role?: string;
|
||||
|
||||
@@ -40,12 +40,12 @@ describe('AclCtrl', () => {
|
||||
|
||||
ctx.ctrl.userPicked(userItem);
|
||||
|
||||
const userGroupItem = {
|
||||
const teamItem = {
|
||||
id: 2,
|
||||
name: 'ug1',
|
||||
};
|
||||
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
ctx.ctrl.groupPicked(teamItem);
|
||||
|
||||
ctx.ctrl.newType = 'Editor';
|
||||
ctx.ctrl.typeChanged();
|
||||
@@ -54,10 +54,10 @@ describe('AclCtrl', () => {
|
||||
ctx.ctrl.typeChanged();
|
||||
});
|
||||
|
||||
it('should sort the result by role, user group and user', () => {
|
||||
it('should sort the result by role, team and user', () => {
|
||||
expect(ctx.ctrl.items[0].role).to.eql('Viewer');
|
||||
expect(ctx.ctrl.items[1].role).to.eql('Editor');
|
||||
expect(ctx.ctrl.items[2].userGroupId).to.eql(2);
|
||||
expect(ctx.ctrl.items[2].teamId).to.eql(2);
|
||||
expect(ctx.ctrl.items[3].userId).to.eql(2);
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('AclCtrl', () => {
|
||||
expect(backendSrv.post.getCall(0).args[1].items[0].permission).to.eql(1);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[1].role).to.eql('Editor');
|
||||
expect(backendSrv.post.getCall(0).args[1].items[1].permission).to.eql(1);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[2].userGroupId).to.eql(2);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[2].teamId).to.eql(2);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[2].permission).to.eql(1);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[3].userId).to.eql(2);
|
||||
expect(backendSrv.post.getCall(0).args[1].items[3].permission).to.eql(1);
|
||||
@@ -124,19 +124,19 @@ describe('AclCtrl', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when duplicate user group permissions are added', () => {
|
||||
describe('when duplicate team permissions are added', () => {
|
||||
beforeEach(() => {
|
||||
backendSrv.get.reset();
|
||||
backendSrv.post.reset();
|
||||
ctx.ctrl.items = [];
|
||||
|
||||
const userGroupItem = {
|
||||
const teamItem = {
|
||||
id: 2,
|
||||
name: 'ug1',
|
||||
};
|
||||
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
ctx.ctrl.groupPicked(teamItem);
|
||||
ctx.ctrl.groupPicked(teamItem);
|
||||
});
|
||||
|
||||
it('should throw a validation error', () => {
|
||||
@@ -148,25 +148,25 @@ describe('AclCtrl', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when one inherited and one not inherited user group permission are added', () => {
|
||||
describe('when one inherited and one not inherited team permission are added', () => {
|
||||
beforeEach(() => {
|
||||
backendSrv.get.reset();
|
||||
backendSrv.post.reset();
|
||||
ctx.ctrl.items = [];
|
||||
|
||||
const inheritedUserGroupItem = {
|
||||
const inheritedTeamItem = {
|
||||
id: 2,
|
||||
name: 'ug1',
|
||||
dashboardId: -1
|
||||
};
|
||||
|
||||
ctx.ctrl.items.push(inheritedUserGroupItem);
|
||||
ctx.ctrl.items.push(inheritedTeamItem);
|
||||
|
||||
const userGroupItem = {
|
||||
const teamItem = {
|
||||
id: 2,
|
||||
name: 'ug1',
|
||||
};
|
||||
ctx.ctrl.groupPicked(userGroupItem);
|
||||
ctx.ctrl.groupPicked(teamItem);
|
||||
});
|
||||
|
||||
it('should not throw a validation error', () => {
|
||||
|
||||
@@ -5,7 +5,9 @@ import './select_org_ctrl';
|
||||
import './change_password_ctrl';
|
||||
import './new_org_ctrl';
|
||||
import './user_invite_ctrl';
|
||||
import './user_groups_ctrl';
|
||||
import './teams_ctrl';
|
||||
import './team_details_ctrl';
|
||||
import './create_team_modal';
|
||||
import './org_api_keys_ctrl';
|
||||
import './org_details_ctrl';
|
||||
import './prefs_control';
|
||||
|
||||
37
public/app/features/org/create_team_modal.ts
Normal file
37
public/app/features/org/create_team_modal.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import coreModule from 'app/core/core_module';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
export class CreateTeamCtrl {
|
||||
teamName = '';
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv, private $location) {
|
||||
}
|
||||
|
||||
createTeam() {
|
||||
this.backendSrv.post('/api/teams', {name: this.teamName}).then((result) => {
|
||||
if (result.teamId) {
|
||||
this.$location.path('/org/teams/edit/' + result.teamId);
|
||||
}
|
||||
this.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
dismiss() {
|
||||
appEvents.emit('hide-modal');
|
||||
}
|
||||
}
|
||||
|
||||
export function createTeamModal() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'public/app/features/org/partials/create_team.html',
|
||||
controller: CreateTeamCtrl,
|
||||
bindToController: true,
|
||||
controllerAs: 'ctrl',
|
||||
};
|
||||
}
|
||||
|
||||
coreModule.directive('createTeamModal', createTeamModal);
|
||||
@@ -1,37 +0,0 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import coreModule from 'app/core/core_module';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
export class CreateUserGroupCtrl {
|
||||
userGroupName = '';
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv, private $location) {
|
||||
}
|
||||
|
||||
createUserGroup() {
|
||||
this.backendSrv.post('/api/user-groups', {name: this.userGroupName}).then((result) => {
|
||||
if (result.userGroupId) {
|
||||
this.$location.path('/org/user-groups/edit/' + result.userGroupId);
|
||||
}
|
||||
this.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
dismiss() {
|
||||
appEvents.emit('hide-modal');
|
||||
}
|
||||
}
|
||||
|
||||
export function createUserGroupModal() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'public/app/features/org/partials/create_user_group.html',
|
||||
controller: CreateUserGroupCtrl,
|
||||
bindToController: true,
|
||||
controllerAs: 'ctrl',
|
||||
};
|
||||
}
|
||||
|
||||
coreModule.directive('createUserGroupModal', createUserGroupModal);
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="modal-body">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-header-title">
|
||||
<span class="p-l-1">Create User Group</span>
|
||||
<span class="p-l-1">Create Team</span>
|
||||
</h2>
|
||||
|
||||
<a class="modal-header-close" ng-click="ctrl.dismiss();">
|
||||
@@ -10,14 +10,14 @@
|
||||
</div>
|
||||
|
||||
<div class="modal-content">
|
||||
<form name="ctrl.createUserGroupForm" class="gf-form-group" novalidate>
|
||||
<form name="ctrl.createTeamForm" class="gf-form-group" novalidate>
|
||||
<div class="p-t-2">
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form max-width-21">
|
||||
<input type="text" class="gf-form-input" ng-model='ctrl.userGroupName' required give-focus="true" placeholder="Enter User Group Name"></input>
|
||||
<input type="text" class="gf-form-input" ng-model='ctrl.teamName' required give-focus="true" placeholder="Enter Team Name"></input>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<button class="btn gf-form-btn btn-success" ng-click="ctrl.createUserGroup();ctrl.dismiss();">Create</button>
|
||||
<button class="btn gf-form-btn btn-success" ng-click="ctrl.createTeam();ctrl.dismiss();">Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
<div class="page-container">
|
||||
<div class="page-header">
|
||||
<h1>Edit User Group</h1>
|
||||
<h1>Edit Team</h1>
|
||||
</div>
|
||||
|
||||
<form name="userGroupDetailsForm" class="gf-form-group gf-form-inline">
|
||||
<form name="teamDetailsForm" class="gf-form-group gf-form-inline">
|
||||
<div class="gf-form">
|
||||
<span class="gf-form-label width-10">Name</span>
|
||||
<input type="text" required ng-model="ctrl.userGroup.name" class="gf-form-input max-width-14" >
|
||||
<input type="text" required ng-model="ctrl.team.name" class="gf-form-input max-width-14" >
|
||||
</div>
|
||||
|
||||
<div class="gf-form">
|
||||
@@ -17,7 +17,7 @@
|
||||
</form>
|
||||
|
||||
<div class="gf-form-group">
|
||||
<h3 class="page-heading">User Group Members</h3>
|
||||
<h3 class="page-heading">Team Members</h3>
|
||||
|
||||
<form name="ctrl.addMemberForm" class="gf-form-group">
|
||||
<div class="gf-form">
|
||||
@@ -26,24 +26,24 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="grafana-options-table" ng-show="ctrl.userGroupMembers.length > 0">
|
||||
<table class="grafana-options-table" ng-show="ctrl.teamMembers.length > 0">
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<tr ng-repeat="member in ctrl.userGroupMembers">
|
||||
<tr ng-repeat="member in ctrl.teamMembers">
|
||||
<td>{{member.login}}</td>
|
||||
<td>{{member.email}}</td>
|
||||
<td style="width: 1%">
|
||||
<a ng-click="ctrl.removeUserGroupMember(member)" class="btn btn-danger btn-mini">
|
||||
<a ng-click="ctrl.removeTeamMember(member)" class="btn btn-danger btn-mini">
|
||||
<i class="fa fa-remove"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div>
|
||||
<em class="muted" ng-hide="ctrl.userGroupMembers.length > 0">
|
||||
This user group has no members yet.
|
||||
<em class="muted" ng-hide="ctrl.teamMembers.length > 0">
|
||||
This team has no members yet.
|
||||
</em>
|
||||
</div>
|
||||
@@ -5,20 +5,20 @@
|
||||
|
||||
<div class="gf-form gf-form--grow">
|
||||
<label class="gf-form-label">Search</label>
|
||||
<input type="text" class="gf-form-input max-width-20" placeholder="Find User Group by name" tabindex="1" give-focus="true"
|
||||
<input type="text" class="gf-form-input max-width-20" placeholder="Find Team by name" tabindex="1" give-focus="true"
|
||||
ng-model="ctrl.query" ng-model-options="{ debounce: 500 }" spellcheck='false' ng-change="ctrl.get()" />
|
||||
</div>
|
||||
|
||||
<div class="page-action-bar__spacer"></div>
|
||||
|
||||
<a class="btn btn-success" ng-click="ctrl.openUserGroupModal()">
|
||||
<a class="btn btn-success" ng-click="ctrl.openTeamModal()">
|
||||
<i class="fa fa-plus"></i>
|
||||
Add Team
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="admin-list-table">
|
||||
<table class="filter-table form-inline" ng-show="ctrl.userGroups.length > 0">
|
||||
<table class="filter-table form-inline" ng-show="ctrl.teams.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
@@ -27,18 +27,18 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="userGroup in ctrl.userGroups">
|
||||
<tr ng-repeat="team in ctrl.teams">
|
||||
<td>
|
||||
<a href="org/user-groups/edit/{{userGroup.id}}">{{userGroup.name}}</a>
|
||||
<a href="org/teams/edit/{{team.id}}">{{team.name}}</a>
|
||||
</td>
|
||||
<td>#Count</td>
|
||||
<td class="text-right">
|
||||
<a href="org/user-groups/edit/{{userGroup.id}}" class="btn btn-inverse btn-small">
|
||||
<a href="org/teams/edit/{{team.id}}" class="btn btn-inverse btn-small">
|
||||
<i class="fa fa-edit"></i>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
<a ng-click="ctrl.deleteUserGroup(userGroup)" class="btn btn-danger btn-small">
|
||||
<a ng-click="ctrl.deleteTeam(team)" class="btn btn-danger btn-small">
|
||||
<i class="fa fa-remove"></i>
|
||||
</a>
|
||||
</td>
|
||||
@@ -58,7 +58,7 @@
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<em class="muted" ng-hide="ctrl.userGroups.length > 0">
|
||||
No User Groups found.
|
||||
<em class="muted" ng-hide="ctrl.teams.length > 0">
|
||||
No Teams found.
|
||||
</em>
|
||||
</div>
|
||||
@@ -1,8 +1,8 @@
|
||||
import '../user_group_details_ctrl';
|
||||
import '../team_details_ctrl';
|
||||
import {describe, beforeEach, it, expect, sinon, angularMocks} from 'test/lib/common';
|
||||
import UserGroupDetailsCtrl from '../user_group_details_ctrl';
|
||||
import TeamDetailsCtrl from '../team_details_ctrl';
|
||||
|
||||
describe('UserGroupDetailsCtrl', () => {
|
||||
describe('TeamDetailsCtrl', () => {
|
||||
var ctx: any = {};
|
||||
var backendSrv = {
|
||||
searchUsers: sinon.stub().returns(Promise.resolve([])),
|
||||
@@ -16,7 +16,7 @@ var backendSrv = {
|
||||
beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
|
||||
ctx.$q = $q;
|
||||
ctx.scope = $rootScope.$new();
|
||||
ctx.ctrl = $controller(UserGroupDetailsCtrl, {
|
||||
ctx.ctrl = $controller(TeamDetailsCtrl, {
|
||||
$scope: ctx.scope,
|
||||
backendSrv: backendSrv,
|
||||
$routeParams: {id: 1},
|
||||
@@ -24,7 +24,7 @@ var backendSrv = {
|
||||
});
|
||||
}));
|
||||
|
||||
describe('when user is chosen to be added to user group', () => {
|
||||
describe('when user is chosen to be added to team', () => {
|
||||
beforeEach(() => {
|
||||
const userItem = {
|
||||
id: 2,
|
||||
@@ -34,13 +34,13 @@ var backendSrv = {
|
||||
});
|
||||
|
||||
it('should parse the result and save to db', () => {
|
||||
expect(backendSrv.post.getCall(0).args[0]).to.eql('/api/user-groups/1/members');
|
||||
expect(backendSrv.post.getCall(0).args[0]).to.eql('/api/teams/1/members');
|
||||
expect(backendSrv.post.getCall(0).args[1].userId).to.eql(2);
|
||||
});
|
||||
|
||||
it('should refresh the list after saving.', () => {
|
||||
expect(backendSrv.get.getCall(0).args[0]).to.eql('/api/user-groups/1');
|
||||
expect(backendSrv.get.getCall(1).args[0]).to.eql('/api/user-groups/1/members');
|
||||
expect(backendSrv.get.getCall(0).args[0]).to.eql('/api/teams/1');
|
||||
expect(backendSrv.get.getCall(1).args[0]).to.eql('/api/teams/1/members');
|
||||
});
|
||||
});
|
||||
});
|
||||
77
public/app/features/org/team_details_ctrl.ts
Normal file
77
public/app/features/org/team_details_ctrl.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import coreModule from 'app/core/core_module';
|
||||
|
||||
export default class TeamDetailsCtrl {
|
||||
team: Team;
|
||||
teamMembers: User[] = [];
|
||||
navModel: any;
|
||||
|
||||
constructor(private $scope, private backendSrv, private $routeParams, navModelSrv) {
|
||||
this.navModel = navModelSrv.getNav('cfg', 'users');
|
||||
this.get();
|
||||
}
|
||||
|
||||
get() {
|
||||
if (this.$routeParams && this.$routeParams.id) {
|
||||
this.backendSrv.get(`/api/teams/${this.$routeParams.id}`)
|
||||
.then(result => {
|
||||
this.team = result;
|
||||
});
|
||||
this.backendSrv.get(`/api/teams/${this.$routeParams.id}/members`)
|
||||
.then(result => {
|
||||
this.teamMembers = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
removeTeamMember(teamMember: TeamMember) {
|
||||
this.$scope.appEvent('confirm-modal', {
|
||||
title: 'Remove Member',
|
||||
text: 'Are you sure you want to remove ' + teamMember.name + ' from this group?',
|
||||
yesText: "Remove",
|
||||
icon: "fa-warning",
|
||||
onConfirm: () => {
|
||||
this.removeMemberConfirmed(teamMember);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
removeMemberConfirmed(teamMember: TeamMember) {
|
||||
this.backendSrv.delete(`/api/teams/${this.$routeParams.id}/members/${teamMember.userId}`)
|
||||
.then(this.get.bind(this));
|
||||
}
|
||||
|
||||
update() {
|
||||
if (!this.$scope.teamDetailsForm.$valid) { return; }
|
||||
|
||||
this.backendSrv.put('/api/teams/' + this.team.id, {name: this.team.name});
|
||||
}
|
||||
|
||||
userPicked(user) {
|
||||
this.backendSrv.post(`/api/teams/${this.$routeParams.id}/members`, {userId: user.id}).then(() => {
|
||||
this.$scope.$broadcast('user-picker-reset');
|
||||
this.get();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface Team {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
login: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface TeamMember {
|
||||
userId: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
coreModule.controller('TeamDetailsCtrl', TeamDetailsCtrl);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import coreModule from 'app/core/core_module';
|
||||
import {appEvents} from 'app/core/core';
|
||||
|
||||
export class UserGroupsCtrl {
|
||||
userGroups: any;
|
||||
export class TeamsCtrl {
|
||||
teams: any;
|
||||
pages = [];
|
||||
perPage = 50;
|
||||
page = 1;
|
||||
@@ -20,9 +20,9 @@ export class UserGroupsCtrl {
|
||||
}
|
||||
|
||||
get() {
|
||||
this.backendSrv.get(`/api/user-groups/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
|
||||
this.backendSrv.get(`/api/teams/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
|
||||
.then((result) => {
|
||||
this.userGroups = result.userGroups;
|
||||
this.teams = result.teams;
|
||||
this.page = result.page;
|
||||
this.perPage = result.perPage;
|
||||
this.totalPages = Math.ceil(result.totalCount / result.perPage);
|
||||
@@ -40,29 +40,29 @@ export class UserGroupsCtrl {
|
||||
this.get();
|
||||
}
|
||||
|
||||
deleteUserGroup(userGroup) {
|
||||
deleteTeam(team) {
|
||||
appEvents.emit('confirm-modal', {
|
||||
title: 'Delete',
|
||||
text: 'Are you sure you want to delete User Group ' + userGroup.name + '?',
|
||||
text: 'Are you sure you want to delete Team ' + team.name + '?',
|
||||
yesText: "Delete",
|
||||
icon: "fa-warning",
|
||||
onConfirm: () => {
|
||||
this.deleteUserGroupConfirmed(userGroup);
|
||||
this.deleteTeamConfirmed(team);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteUserGroupConfirmed(userGroup) {
|
||||
this.backendSrv.delete('/api/user-groups/' + userGroup.id)
|
||||
deleteTeamConfirmed(team) {
|
||||
this.backendSrv.delete('/api/teams/' + team.id)
|
||||
.then(this.get.bind(this));
|
||||
}
|
||||
|
||||
openUserGroupModal() {
|
||||
openTeamModal() {
|
||||
appEvents.emit('show-modal', {
|
||||
templateHtml: '<create-user-group-modal></create-user-group-modal>',
|
||||
templateHtml: '<create-team-modal></create-team-modal>',
|
||||
modalClass: 'modal--narrow'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
coreModule.controller('UserGroupsCtrl', UserGroupsCtrl);
|
||||
coreModule.controller('TeamsCtrl', TeamsCtrl);
|
||||
@@ -1,77 +0,0 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import coreModule from 'app/core/core_module';
|
||||
|
||||
export default class UserGroupDetailsCtrl {
|
||||
userGroup: UserGroup;
|
||||
userGroupMembers: User[] = [];
|
||||
navModel: any;
|
||||
|
||||
constructor(private $scope, private backendSrv, private $routeParams, navModelSrv) {
|
||||
this.navModel = navModelSrv.getNav('cfg', 'users');
|
||||
this.get();
|
||||
}
|
||||
|
||||
get() {
|
||||
if (this.$routeParams && this.$routeParams.id) {
|
||||
this.backendSrv.get(`/api/user-groups/${this.$routeParams.id}`)
|
||||
.then(result => {
|
||||
this.userGroup = result;
|
||||
});
|
||||
this.backendSrv.get(`/api/user-groups/${this.$routeParams.id}/members`)
|
||||
.then(result => {
|
||||
this.userGroupMembers = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
removeUserGroupMember(userGroupMember: UserGroupMember) {
|
||||
this.$scope.appEvent('confirm-modal', {
|
||||
title: 'Remove Member',
|
||||
text: 'Are you sure you want to remove ' + userGroupMember.name + ' from this group?',
|
||||
yesText: "Remove",
|
||||
icon: "fa-warning",
|
||||
onConfirm: () => {
|
||||
this.removeMemberConfirmed(userGroupMember);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
removeMemberConfirmed(userGroupMember: UserGroupMember) {
|
||||
this.backendSrv.delete(`/api/user-groups/${this.$routeParams.id}/members/${userGroupMember.userId}`)
|
||||
.then(this.get.bind(this));
|
||||
}
|
||||
|
||||
update() {
|
||||
if (!this.$scope.userGroupDetailsForm.$valid) { return; }
|
||||
|
||||
this.backendSrv.put('/api/user-groups/' + this.userGroup.id, {name: this.userGroup.name});
|
||||
}
|
||||
|
||||
userPicked(user) {
|
||||
this.backendSrv.post(`/api/user-groups/${this.$routeParams.id}/members`, {userId: user.id}).then(() => {
|
||||
this.$scope.$broadcast('user-picker-reset');
|
||||
this.get();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
login: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface UserGroupMember {
|
||||
userId: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
coreModule.controller('UserGroupDetailsCtrl', UserGroupDetailsCtrl);
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="card-item-wrapper" ng-repeat="permission in ctrl.userGroupPermissions">
|
||||
<li class="card-item-wrapper" ng-repeat="permission in ctrl.teamPermissions">
|
||||
<div class="card-item card-item--alert">
|
||||
<div class="card-item-header">
|
||||
<div class="card-item-sub-name">{{permission.permissionName}}</div>
|
||||
</div>
|
||||
<div class="card-item-body">
|
||||
<div class="card-item-details">
|
||||
<div class="card-item-notice">{{permission.userGroup}}</div>
|
||||
<div class="card-item-notice">{{permission.team}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@ class PermissionListCtrl extends PanelCtrl {
|
||||
static templateUrl = 'module.html';
|
||||
|
||||
userPermissions: any[];
|
||||
userGroupPermissions: any[];
|
||||
teamPermissions: any[];
|
||||
roles: any[];
|
||||
|
||||
panelDefaults = {
|
||||
@@ -48,7 +48,7 @@ class PermissionListCtrl extends PanelCtrl {
|
||||
return this.backendSrv.get(`/api/dashboards/id/${this.panel.folderId}/acl`)
|
||||
.then(result => {
|
||||
this.userPermissions = _.filter(result, p => { return p.userId > 0;});
|
||||
this.userGroupPermissions = _.filter(result, p => { return p.userGroupId > 0;});
|
||||
this.teamPermissions = _.filter(result, p => { return p.teamId > 0;});
|
||||
// this.roles = this.setRoles(result);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user