org_users_ctrl.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import config from 'app/core/config';
  2. import coreModule from 'app/core/core_module';
  3. import Remarkable from 'remarkable';
  4. export class OrgUsersCtrl {
  5. user: any;
  6. users: any;
  7. pendingInvites: any;
  8. editor: any;
  9. navModel: any;
  10. externalUserMngLinkUrl: string;
  11. externalUserMngLinkName: string;
  12. externalUserMngInfo: string;
  13. addUsersBtnName: string;
  14. /** @ngInject */
  15. constructor(private $scope, private backendSrv, navModelSrv, $sce) {
  16. this.user = {
  17. loginOrEmail: '',
  18. role: 'Viewer',
  19. };
  20. this.navModel = navModelSrv.getNav('cfg', 'users', 0);
  21. this.get();
  22. this.editor = { index: 0 };
  23. this.externalUserMngLinkUrl = config.externalUserMngLinkUrl;
  24. this.externalUserMngLinkName = config.externalUserMngLinkName;
  25. // render external user management info markdown
  26. if (config.externalUserMngInfo) {
  27. this.externalUserMngInfo = new Remarkable({
  28. linkTarget: '__blank',
  29. }).render(config.externalUserMngInfo);
  30. }
  31. this.addUsersBtnName = this.getAddUserBtnName();
  32. }
  33. getAddUserBtnName(): string {
  34. if (this.externalUserMngLinkName) {
  35. return this.externalUserMngLinkName;
  36. }
  37. return "Invite User";
  38. }
  39. get() {
  40. this.backendSrv.get('/api/org/users')
  41. .then((users) => {
  42. this.users = users;
  43. });
  44. this.backendSrv.get('/api/org/invites')
  45. .then((pendingInvites) => {
  46. this.pendingInvites = pendingInvites;
  47. });
  48. }
  49. updateOrgUser(user) {
  50. this.backendSrv.patch('/api/org/users/' + user.userId, user);
  51. }
  52. removeUser(user) {
  53. this.$scope.appEvent('confirm-modal', {
  54. title: 'Delete',
  55. text: 'Are you sure you want to delete user ' + user.login + '?',
  56. yesText: "Delete",
  57. icon: "fa-warning",
  58. onConfirm: () => {
  59. this.removeUserConfirmed(user);
  60. }
  61. });
  62. }
  63. removeUserConfirmed(user) {
  64. this.backendSrv.delete('/api/org/users/' + user.userId)
  65. .then(this.get.bind(this));
  66. }
  67. revokeInvite(invite, evt) {
  68. evt.stopPropagation();
  69. this.backendSrv.patch('/api/org/invites/' + invite.code + '/revoke')
  70. .then(this.get.bind(this));
  71. }
  72. copyInviteToClipboard(evt) {
  73. evt.stopPropagation();
  74. }
  75. getInviteUrl(invite) {
  76. return invite.url;
  77. }
  78. openAddUsersView() {
  79. var modalScope = this.$scope.$new();
  80. modalScope.invitesSent = this.get.bind(this);
  81. var src = config.disableLoginForm
  82. ? 'public/app/features/org/partials/add_user.html'
  83. : 'public/app/features/org/partials/invite.html';
  84. this.$scope.appEvent('show-modal', {
  85. src: src,
  86. modalClass: 'invite-modal',
  87. scope: modalScope
  88. });
  89. }
  90. }
  91. coreModule.controller('OrgUsersCtrl', OrgUsersCtrl);