Skip to content
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

Merged
merged 8 commits into from
Nov 16, 2023

Conversation

IevaVasiljeva
Copy link
Contributor

What is this feature?

Refactors the code to allow updating a dashboard if the user doesn't have access to the parent folder:

  • don't fetch the folder from the APIs, instead check if the folder is valid from the dashboard service (this seems like a more appropriate place for validation);
  • fetch the parent folder using folder store, so we can fetch it even if the caller doesn't have access to the 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:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@IevaVasiljeva IevaVasiljeva added this to the 10.3.x milestone Nov 13, 2023
@IevaVasiljeva IevaVasiljeva requested review from joshhunt and a team November 13, 2023 17:24
@IevaVasiljeva IevaVasiljeva requested a review from a team as a code owner November 13, 2023 17:24
@IevaVasiljeva IevaVasiljeva requested review from mildwonkey, undef1nd and suntala and removed request for a team November 13, 2023 17:24
Comment on lines -389 to -409
// 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
}
Copy link
Contributor Author

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.

Comment on lines -333 to -315
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
}
}
Copy link
Contributor Author

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.

Comment on lines -859 to -863
if dash.IsFolder && dash.FolderID > 0 {
return nil, dashboards.ErrDashboardFolderCannotHaveParent
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@IevaVasiljeva IevaVasiljeva changed the title Dashboards: allow updating a dashboard if the user doesn't have access to the parent folder Dashboards: Allow updating a dashboard if the user doesn't have access to the parent folder Nov 13, 2023
@IevaVasiljeva IevaVasiljeva merged commit b0448b9 into main Nov 16, 2023
13 checks passed
@IevaVasiljeva IevaVasiljeva deleted the ieva/fix-folder-updating branch November 16, 2023 11:11
@aangelisc aangelisc removed this from the 10.3.x milestone Dec 21, 2023
@aangelisc aangelisc added this to the 10.2.3 milestone Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to save a dashboard when lacking permissions on parent folder
3 participants