mirror of
https://github.com/grafana/grafana.git
synced 2024-12-29 10:21:41 -06:00
8fd153edb7
Existing /api/alert-notifications now requires at least editor access. Existing /api/alert-notifiers now requires at least editor access. New /api/alert-notifications/lookup returns less information than /api/alert-notifications and can be access by any authenticated user. Existing /api/org/users now requires org admin role. New /api/org/users/lookup returns less information than /api/org/users and can be access by users that are org admins, admin in any folder or admin of any team. UserPicker component now uses /api/org/users/lookup instead of /api/org/users. Fixes #17318
106 lines
2.3 KiB
Go
106 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Typed errors
|
|
var (
|
|
ErrFolderNotFound = errors.New("Folder not found")
|
|
ErrFolderVersionMismatch = errors.New("The folder has been changed by someone else")
|
|
ErrFolderTitleEmpty = errors.New("Folder title cannot be empty")
|
|
ErrFolderWithSameUIDExists = errors.New("A folder/dashboard with the same uid already exists")
|
|
ErrFolderSameNameExists = errors.New("A folder or dashboard in the general folder with the same name already exists")
|
|
ErrFolderFailedGenerateUniqueUid = errors.New("Failed to generate unique folder id")
|
|
ErrFolderAccessDenied = errors.New("Access denied to folder")
|
|
)
|
|
|
|
type Folder struct {
|
|
Id int64
|
|
Uid string
|
|
Title string
|
|
Url string
|
|
Version int
|
|
|
|
Created time.Time
|
|
Updated time.Time
|
|
|
|
UpdatedBy int64
|
|
CreatedBy int64
|
|
HasAcl bool
|
|
}
|
|
|
|
// GetDashboardModel turns the command into the saveable model
|
|
func (cmd *CreateFolderCommand) GetDashboardModel(orgId int64, userId int64) *Dashboard {
|
|
dashFolder := NewDashboardFolder(strings.TrimSpace(cmd.Title))
|
|
dashFolder.OrgId = orgId
|
|
dashFolder.SetUid(strings.TrimSpace(cmd.Uid))
|
|
|
|
if userId == 0 {
|
|
userId = -1
|
|
}
|
|
|
|
dashFolder.CreatedBy = userId
|
|
dashFolder.UpdatedBy = userId
|
|
dashFolder.UpdateSlug()
|
|
|
|
return dashFolder
|
|
}
|
|
|
|
// UpdateDashboardModel updates an existing model from command into model for update
|
|
func (cmd *UpdateFolderCommand) UpdateDashboardModel(dashFolder *Dashboard, orgId int64, userId int64) {
|
|
dashFolder.OrgId = orgId
|
|
dashFolder.Title = strings.TrimSpace(cmd.Title)
|
|
dashFolder.Data.Set("title", dashFolder.Title)
|
|
|
|
if cmd.Uid != "" {
|
|
dashFolder.SetUid(cmd.Uid)
|
|
}
|
|
|
|
dashFolder.SetVersion(cmd.Version)
|
|
dashFolder.IsFolder = true
|
|
|
|
if userId == 0 {
|
|
userId = -1
|
|
}
|
|
|
|
dashFolder.UpdatedBy = userId
|
|
dashFolder.UpdateSlug()
|
|
}
|
|
|
|
//
|
|
// COMMANDS
|
|
//
|
|
|
|
type CreateFolderCommand struct {
|
|
Uid string `json:"uid"`
|
|
Title string `json:"title"`
|
|
|
|
Result *Folder
|
|
}
|
|
|
|
type UpdateFolderCommand struct {
|
|
Uid string `json:"uid"`
|
|
Title string `json:"title"`
|
|
Version int `json:"version"`
|
|
Overwrite bool `json:"overwrite"`
|
|
|
|
Result *Folder
|
|
}
|
|
|
|
//
|
|
// QUERIES
|
|
//
|
|
|
|
type HasEditPermissionInFoldersQuery struct {
|
|
SignedInUser *SignedInUser
|
|
Result bool
|
|
}
|
|
|
|
type HasAdminPermissionInFoldersQuery struct {
|
|
SignedInUser *SignedInUser
|
|
Result bool
|
|
}
|