org_users_ctrl.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import _ from 'lodash';
  4. import coreModule from 'app/core/core_module';
  5. export class OrgUsersCtrl {
  6. user: any;
  7. users: any;
  8. pendingInvites: any;
  9. editor: any;
  10. showInviteUI: boolean;
  11. /** @ngInject */
  12. constructor(private $scope, private $http, private backendSrv) {
  13. this.user = {
  14. loginOrEmail: '',
  15. role: 'Viewer',
  16. };
  17. this.get();
  18. this.editor = { index: 0 };
  19. this.showInviteUI = config.disableLoginForm === false;
  20. }
  21. get() {
  22. this.backendSrv.get('/api/org/users')
  23. .then((users) => {
  24. this.users = users;
  25. });
  26. this.backendSrv.get('/api/org/invites')
  27. .then((pendingInvites) => {
  28. this.pendingInvites = pendingInvites;
  29. });
  30. }
  31. updateOrgUser(user) {
  32. this.backendSrv.patch('/api/org/users/' + user.userId, user);
  33. }
  34. removeUser(user) {
  35. this.$scope.appEvent('confirm-modal', {
  36. title: 'Delete',
  37. text: 'Are you sure you want to delete user ' + user.login + '?',
  38. yesText: "Delete",
  39. icon: "fa-warning",
  40. onConfirm: () => {
  41. this.removeUserConfirmed(user);
  42. }
  43. });
  44. }
  45. removeUserConfirmed(user) {
  46. this.backendSrv.delete('/api/org/users/' + user.userId)
  47. .then(this.get.bind(this));
  48. }
  49. revokeInvite(invite, evt) {
  50. evt.stopPropagation();
  51. this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke')
  52. .then(this.get.bind(this));
  53. }
  54. copyInviteToClipboard(evt) {
  55. evt.stopPropagation();
  56. }
  57. openInviteModal() {
  58. var modalScope = this.$scope.$new();
  59. modalScope.invitesSent = this.get.bind(this);
  60. var src = this.showInviteUI
  61. ? 'public/app/features/org/partials/invite.html'
  62. : 'public/app/features/org/partials/add_user.html';
  63. this.$scope.appEvent('show-modal', {
  64. src: src,
  65. modalClass: 'invite-modal',
  66. scope: modalScope
  67. });
  68. }
  69. }
  70. coreModule.controller('OrgUsersCtrl', OrgUsersCtrl);