org_users_ctrl.ts 2.0 KB

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