diff --git a/pkg/api/dashboard_acl.go b/pkg/api/dashboard_acl.go index a64360c92f7..577dba5e619 100644 --- a/pkg/api/dashboard_acl.go +++ b/pkg/api/dashboard_acl.go @@ -23,7 +23,39 @@ func GetDashboardAclList(c *middleware.Context) Response { return ApiError(500, "Failed to get Dashboard ACL", err) } - return Json(200, &query.Result) + list := query.Result + hasViewRoleAcl := false + hasEditRoleAcl := false + + for _, item := range list { + if item.Role == m.ROLE_EDITOR { + hasEditRoleAcl = true + } + if item.Role == m.ROLE_VIEWER { + hasViewRoleAcl = true + } + } + + if !hasEditRoleAcl { + tmpList := append([]*m.DashboardAclInfoDTO{}, &m.DashboardAclInfoDTO{ + Id: 0, + Role: m.ROLE_EDITOR, + Permissions: m.PERMISSION_EDIT, + PermissionName: "Edit", + }) + list = append(tmpList, list...) + } + if !hasViewRoleAcl { + tmpList := append([]*m.DashboardAclInfoDTO{}, &m.DashboardAclInfoDTO{ + Id: 0, + Role: m.ROLE_VIEWER, + Permissions: m.PERMISSION_VIEW, + PermissionName: "View", + }) + list = append(tmpList, list...) + } + + return Json(200, list) } func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Response { diff --git a/pkg/models/dashboard_acl.go b/pkg/models/dashboard_acl.go index 05a28553d40..11e8f71434c 100644 --- a/pkg/models/dashboard_acl.go +++ b/pkg/models/dashboard_acl.go @@ -8,16 +8,18 @@ import ( type PermissionType int const ( + PERMISSION_NONE = 0 PERMISSION_VIEW PermissionType = 1 << iota - PERMISSION_READ_ONLY_EDIT PERMISSION_EDIT + PERMISSION_ADMIN ) func (p PermissionType) String() string { names := map[int]string{ - int(PERMISSION_VIEW): "View", - int(PERMISSION_READ_ONLY_EDIT): "Read-only Edit", - int(PERMISSION_EDIT): "Edit", + int(PERMISSION_NONE): "None", + int(PERMISSION_VIEW): "View", + int(PERMISSION_EDIT): "Edit", + int(PERMISSION_ADMIN): "Admin", } return names[int(p)] } @@ -55,6 +57,7 @@ type DashboardAclInfoDTO struct { UserEmail string `json:"userEmail"` UserGroupId int64 `json:"userGroupId"` UserGroup string `json:"userGroup"` + Role RoleType `json:"role"` Permissions PermissionType `json:"permissions"` PermissionName string `json:"permissionName"` } diff --git a/pkg/services/guardian/guardian.go b/pkg/services/guardian/guardian.go index 087b22cdd2f..7fb33a8d01e 100644 --- a/pkg/services/guardian/guardian.go +++ b/pkg/services/guardian/guardian.go @@ -29,7 +29,7 @@ func (g *DashboardGuardian) CanSave() (bool, error) { } func (g *DashboardGuardian) CanEdit() (bool, error) { - return g.HasPermission(m.PERMISSION_READ_ONLY_EDIT, m.ROLE_READ_ONLY_EDITOR) + return g.HasPermission(m.PERMISSION_EDIT, m.ROLE_READ_ONLY_EDITOR) } func (g *DashboardGuardian) CanView() (bool, error) { diff --git a/public/app/core/directives/dash_edit_link.js b/public/app/core/directives/dash_edit_link.js index 21e8940200c..d5fd80f9143 100644 --- a/public/app/core/directives/dash_edit_link.js +++ b/public/app/core/directives/dash_edit_link.js @@ -22,6 +22,7 @@ function ($, angular, coreModule, _) { restrict: 'A', link: function(scope, elem) { var editorScope; + var modalScope; var lastEditView; function hideEditorPane(hideToShowOtherView) { @@ -47,6 +48,11 @@ function ($, angular, coreModule, _) { editorScope = options.scope ? options.scope.$new() : scope.$new(); editorScope.dismiss = function(hideToShowOtherView) { + if (modalScope) { + modalScope.dismiss(); + modalScope = null; + } + editorScope.$destroy(); lastEditView = null; editorScope = null; @@ -73,7 +79,7 @@ function ($, angular, coreModule, _) { }; if (options.isModal) { - var modalScope = $rootScope.$new(); + modalScope = $rootScope.$new(); modalScope.$on("$destroy", function() { editorScope.dismiss(); }); diff --git a/public/app/features/dashboard/acl/acl.html b/public/app/features/dashboard/acl/acl.html index b51508693ee..b9f4a11b5c0 100644 --- a/public/app/features/dashboard/acl/acl.html +++ b/public/app/features/dashboard/acl/acl.html @@ -36,53 +36,27 @@ -