mirror of https://github.com/grafana/grafana
Merge pull request #4066 from utkarshcmu/user-removal
Added Confirmation modal for user deletionpull/4072/head
commit
b9059181fd
@ -1,66 +0,0 @@ |
||||
define([ |
||||
'angular', |
||||
], |
||||
function (angular) { |
||||
'use strict'; |
||||
|
||||
var module = angular.module('grafana.controllers'); |
||||
|
||||
module.controller('OrgUsersCtrl', function($scope, $http, backendSrv) { |
||||
|
||||
$scope.user = { |
||||
loginOrEmail: '', |
||||
role: 'Viewer', |
||||
}; |
||||
|
||||
$scope.users = []; |
||||
$scope.pendingInvites = []; |
||||
|
||||
$scope.init = function() { |
||||
$scope.get(); |
||||
$scope.editor = { index: 0 }; |
||||
}; |
||||
|
||||
$scope.get = function() { |
||||
backendSrv.get('/api/org/users').then(function(users) { |
||||
$scope.users = users; |
||||
}); |
||||
backendSrv.get('/api/org/invites').then(function(pendingInvites) { |
||||
$scope.pendingInvites = pendingInvites; |
||||
}); |
||||
}; |
||||
|
||||
$scope.updateOrgUser = function(user) { |
||||
backendSrv.patch('/api/org/users/' + user.userId, user); |
||||
}; |
||||
|
||||
$scope.removeUser = function(user) { |
||||
backendSrv.delete('/api/org/users/' + user.userId).then($scope.get); |
||||
}; |
||||
|
||||
$scope.revokeInvite = function(invite, evt) { |
||||
evt.stopPropagation(); |
||||
backendSrv.patch('/api/org/invites/' + invite.code + '/revoke').then($scope.get); |
||||
}; |
||||
|
||||
$scope.copyInviteToClipboard = function(evt) { |
||||
evt.stopPropagation(); |
||||
}; |
||||
|
||||
$scope.openInviteModal = function() { |
||||
var modalScope = $scope.$new(); |
||||
modalScope.invitesSent = function() { |
||||
$scope.get(); |
||||
}; |
||||
|
||||
$scope.appEvent('show-modal', { |
||||
src: 'public/app/features/org/partials/invite.html', |
||||
modalClass: 'modal-no-header invite-modal', |
||||
scope: modalScope |
||||
}); |
||||
}; |
||||
|
||||
$scope.init(); |
||||
|
||||
}); |
||||
}); |
@ -0,0 +1,85 @@ |
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import angular from 'angular'; |
||||
import _ from 'lodash'; |
||||
import coreModule from '../../core/core_module'; |
||||
|
||||
export class OrgUsersCtrl { |
||||
|
||||
user: any; |
||||
users: any; |
||||
pendingInvites: any; |
||||
editor: any; |
||||
|
||||
/** @ngInject */ |
||||
constructor(private $scope, private $http, private backendSrv) { |
||||
this.user = { |
||||
loginOrEmail: '', |
||||
role: 'Viewer', |
||||
}; |
||||
this.get(); |
||||
this.editor = { index: 0 }; |
||||
} |
||||
|
||||
get() { |
||||
this.backendSrv.get('/api/org/users') |
||||
.then((users) => { |
||||
this.users = users; |
||||
}); |
||||
this.backendSrv.get('/api/org/invites') |
||||
.then((pendingInvites) => { |
||||
this.pendingInvites = pendingInvites; |
||||
}); |
||||
} |
||||
|
||||
updateOrgUser(user) { |
||||
this.backendSrv.patch('/api/org/users/' + user.userId, user); |
||||
} |
||||
|
||||
removeUser(user) { |
||||
this.$scope.appEvent('confirm-modal', { |
||||
title: 'Confirm delete user', |
||||
text: 'Are you sure you want to delete user ' + user.login + '?', |
||||
yesText: "Delete", |
||||
icon: "fa-warning", |
||||
onConfirm: () => { |
||||
this.removeUserConfirmed(user); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
removeUserConfirmed(user) { |
||||
this.backendSrv.delete('/api/org/users/' + user.userId) |
||||
.then(() => { |
||||
this.get(); |
||||
}); |
||||
} |
||||
|
||||
revokeInvite(invite, evt) { |
||||
evt.stopPropagation(); |
||||
this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke') |
||||
.then(() => { |
||||
this.get(); |
||||
}); |
||||
} |
||||
|
||||
copyInviteToClipboard(evt) { |
||||
evt.stopPropagation(); |
||||
} |
||||
|
||||
openInviteModal() { |
||||
var modalScope = this.$scope.$new(); |
||||
modalScope.invitesSent = function() { |
||||
this.get(); |
||||
}; |
||||
|
||||
this.$scope.appEvent('show-modal', { |
||||
src: 'public/app/features/org/partials/invite.html', |
||||
modalClass: 'modal-no-header invite-modal', |
||||
scope: modalScope |
||||
}); |
||||
} |
||||
|
||||
} |
||||
|
||||
coreModule.controller('OrgUsersCtrl', OrgUsersCtrl); |
Loading…
Reference in new issue