mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
35fe58de37
* API: Using go-swagger for extracting OpenAPI specification from source code * Merge Grafana Alerting spec * Include enterprise endpoints (if enabled) * Serve SwaggerUI under feature flag * Fix building dev docker images * Configure swaggerUI * Add missing json tags Co-authored-by: Ying WANG <ying.wang@grafana.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
90 lines
2.0 KiB
Go
90 lines
2.0 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")
|
|
ErrFolderContainsAlertRules = errors.New("folder contains alert rules")
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
// 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 `json:"-"`
|
|
}
|
|
|
|
type UpdateFolderCommand struct {
|
|
Uid string `json:"uid"`
|
|
Title string `json:"title"`
|
|
Version int `json:"version"`
|
|
Overwrite bool `json:"overwrite"`
|
|
|
|
Result *Folder `json:"-"`
|
|
}
|
|
|
|
//
|
|
// QUERIES
|
|
//
|
|
|
|
type HasEditPermissionInFoldersQuery struct {
|
|
SignedInUser *SignedInUser
|
|
Result bool
|
|
}
|
|
|
|
type HasAdminPermissionInFoldersQuery struct {
|
|
SignedInUser *SignedInUser
|
|
Result bool
|
|
}
|