-
Notifications
You must be signed in to change notification settings - Fork 11.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashboards: Allow updating a dashboard if the user doesn't have access to the parent folder #78075
Conversation
// nolint:staticcheck | ||
if cmd.FolderUID != "" || cmd.FolderID != 0 { | ||
folder, err := hs.folderService.Get(ctx, &folder.GetFolderQuery{ | ||
OrgID: c.SignedInUser.GetOrgID(), | ||
UID: &cmd.FolderUID, | ||
// nolint:staticcheck | ||
ID: &cmd.FolderID, | ||
SignedInUser: c.SignedInUser, | ||
}) | ||
if err != nil { | ||
if errors.Is(err, dashboards.ErrFolderNotFound) { | ||
return response.Error(http.StatusBadRequest, "Folder not found", err) | ||
} | ||
return response.Error(http.StatusInternalServerError, "Error while checking folder ID", err) | ||
} | ||
// nolint:staticcheck | ||
cmd.FolderID = folder.ID | ||
cmd.FolderUID = folder.UID | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is now carried out here.
if dash.FolderID > 0 { | ||
var existingFolder dashboards.Dashboard | ||
folderExists, err := sess.Where("org_id=? AND id=? AND is_folder=?", dash.OrgID, dash.FolderID, | ||
dialect.BooleanStr(true)).Get(&existingFolder) | ||
if err != nil { | ||
return false, fmt.Errorf("SQL query for folder failed: %w", err) | ||
} | ||
|
||
if !folderExists { | ||
return false, dashboards.ErrDashboardFolderNotFound | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is now carried out here for dashboards and here for folders.
if dash.IsFolder && dash.FolderID > 0 { | ||
return nil, dashboards.ErrDashboardFolderCannotHaveParent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup: this is an outdated check - we support nested folders now.
} | ||
|
||
if dash.IsFolder && strings.EqualFold(dash.Title, dashboards.RootFolderName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup: safe to remove dash.IsFolder
, as this code is a part of the folder service, so we know that dash.IsFolder
is true.
What is this feature?
Refactors the code to allow updating a dashboard if the user doesn't have access to the parent folder:
Why do we need this feature?
To allow users to update dashboards if they don't have access to the parent folder.
Who is this feature for?
Everyone.
Which issue(s) does this PR fix?:
Fixes #76068
Special notes for your reviewer:
Please check that: