acl.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. import appEvents from 'app/core/app_events';
  4. import _ from 'lodash';
  5. export class AclCtrl {
  6. tabIndex: any;
  7. dashboard: any;
  8. userPermissions: Permission[];
  9. userGroupPermissions: Permission[];
  10. /** @ngInject */
  11. constructor(private backendSrv, private $scope, $sce) {
  12. this.tabIndex = 0;
  13. this.userPermissions = [];
  14. this.userGroupPermissions = [];
  15. this.get(this.dashboard.id);
  16. }
  17. get(dashboardId: number) {
  18. return this.backendSrv.get(`/api/dashboards/${dashboardId}/acl`)
  19. .then(result => {
  20. this.userPermissions = _.filter(result, p => { return p.userId > 0;});
  21. this.userGroupPermissions = _.filter(result, p => { return p.userGroupId > 0;});
  22. });
  23. }
  24. removeUserPermission(permission: Permission) {
  25. this.backendSrv.delete(`/api/dashboards/${permission.dashboardId}/acl/user/${permission.userId}`).then(() => {
  26. this.get(permission.dashboardId);
  27. });
  28. }
  29. removeUserGroupPermission(permission: Permission) {
  30. this.backendSrv.delete(`/api/dashboards/${permission.dashboardId}/acl/user-group/${permission.userGroupId}`).then(() => {
  31. this.get(permission.dashboardId);
  32. });
  33. }
  34. }
  35. export function aclSettings() {
  36. return {
  37. restrict: 'E',
  38. templateUrl: 'public/app/features/dashboard/acl/acl.html',
  39. controller: AclCtrl,
  40. bindToController: true,
  41. controllerAs: 'ctrl',
  42. scope: { dashboard: "=" }
  43. };
  44. }
  45. export interface Permission {
  46. id: number;
  47. orgId: number;
  48. dashboardId: number;
  49. created: Date;
  50. updated: Date;
  51. userId: number;
  52. userLogin: number;
  53. userEmail: string;
  54. userGroupId: number;
  55. userGroup: string;
  56. permissions: number[];
  57. }
  58. coreModule.directive('aclSettings', aclSettings);