folder

package
v0.0.0-cloud Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeneralFolderUID     = "general"
	RootFolderUID        = ""
	MaxNestedFolderDepth = 8
)

Variables

View Source
var ErrBadRequest = errutil.NewBase(errutil.StatusBadRequest, "folder.bad-request")
View Source
var ErrCircularReference = errutil.NewBase(errutil.StatusBadRequest, "folder.circular-reference", errutil.WithPublicMessage("Circular reference detected"))
View Source
var ErrDatabaseError = errutil.NewBase(errutil.StatusInternal, "folder.database-error")
View Source
var ErrFolderNotFound = errutil.NewBase(errutil.StatusNotFound, "folder.notFound")
View Source
var ErrFolderTooDeep = errutil.NewBase(errutil.StatusInternal, "folder.too-deep")
View Source
var ErrInternal = errutil.NewBase(errutil.StatusInternal, "folder.internal")
View Source
var ErrMaximumDepthReached = errutil.NewBase(errutil.StatusBadRequest, "folder.maximum-depth-reached", errutil.WithPublicMessage("Maximum nested folder depth reached"))
View Source
var GeneralFolder = Folder{ID: 0, Title: "General"}

Functions

This section is empty.

Types

type CreateFolderCommand

type CreateFolderCommand struct {
	UID         string `json:"uid"`
	OrgID       int64  `json:"-"`
	Title       string `json:"title"`
	Description string `json:"description"`
	ParentUID   string `json:"parentUid"`

	SignedInUser *user.SignedInUser `json:"-"`
}

CreateFolderCommand captures the information required by the folder service to create a folder.

type DeleteFolderCommand

type DeleteFolderCommand struct {
	UID              string `json:"uid" xorm:"uid"`
	OrgID            int64  `json:"orgId" xorm:"org_id"`
	ForceDeleteRules bool   `json:"forceDeleteRules"`

	SignedInUser *user.SignedInUser `json:"-"`
}

DeleteFolderCommand captures the information required by the folder service to delete a folder.

type Folder

type Folder struct {
	ID          int64  `xorm:"pk autoincr 'id'"`
	OrgID       int64  `xorm:"org_id"`
	UID         string `xorm:"uid"`
	ParentUID   string `xorm:"parent_uid"`
	Title       string
	Description string

	Created time.Time
	Updated time.Time

	// TODO: validate if this field is required/relevant to folders.
	// currently there is no such column
	Version   int
	URL       string
	UpdatedBy int64
	CreatedBy int64
	HasACL    bool
}

func NewFolder

func NewFolder(title string, description string) *Folder

NewFolder tales a title and returns a Folder with the Created and Updated fields set to the current time.

func (*Folder) IsGeneral

func (f *Folder) IsGeneral() bool

type FolderDTO

type FolderDTO struct {
	Folder

	Children []FolderDTO
}

type FolderStore

type FolderStore interface {
	// GetFolderByTitle retrieves a folder by its title
	GetFolderByTitle(ctx context.Context, orgID int64, title string) (*Folder, error)
	// GetFolderByUID retrieves a folder by its UID
	GetFolderByUID(ctx context.Context, orgID int64, uid string) (*Folder, error)
	// GetFolderByID retrieves a folder by its ID
	GetFolderByID(ctx context.Context, orgID int64, id int64) (*Folder, error)
}

FolderStore is a folder store.

type GetChildrenQuery

type GetChildrenQuery struct {
	UID   string `xorm:"uid"`
	OrgID int64  `xorm:"org_id"`
	Depth int64

	// Pagination options
	Limit int64
	Page  int64

	SignedInUser *user.SignedInUser `json:"-"`
}

type GetFolderQuery

type GetFolderQuery struct {
	UID   *string
	ID    *int64
	Title *string
	OrgID int64

	SignedInUser *user.SignedInUser `json:"-"`
}

GetFolderQuery is used for all folder Get requests. Only one of UID, ID, or Title should be set; if multilpe fields are set by the caller the dashboard service will select the field with the most specificity, in order: ID, UID, Title.

type GetParentsQuery

type GetParentsQuery struct {
	UID   string `xorm:"uid"`
	OrgID int64  `xorm:"org_id"`
}

GetParentsQuery captures the information required by the folder service to return a list of all parent folders of a given folder.

type HasAdminPermissionInDashboardsOrFoldersQuery

type HasAdminPermissionInDashboardsOrFoldersQuery struct {
	SignedInUser *user.SignedInUser
}

type HasEditPermissionInFoldersQuery

type HasEditPermissionInFoldersQuery struct {
	SignedInUser *user.SignedInUser
}

type MoveFolderCommand

type MoveFolderCommand struct {
	UID          string `json:"-"`
	NewParentUID string `json:"parentUid"`
	OrgID        int64  `json:"-"`

	SignedInUser *user.SignedInUser `json:"-"`
}

MoveFolderCommand captures the information required by the folder service to move a folder.

type Service

type Service interface {
	// GetChildren returns an array containing all child folders.
	GetChildren(ctx context.Context, cmd *GetChildrenQuery) ([]*Folder, error)
	// GetParents returns an array containing add parent folders if nested folders are enabled
	// otherwise it returns an empty array
	GetParents(ctx context.Context, q GetParentsQuery) ([]*Folder, error)
	Create(ctx context.Context, cmd *CreateFolderCommand) (*Folder, error)

	// GetFolder takes a GetFolderCommand and returns a folder matching the
	// request. One of ID, UID, or Title must be included. If multiple values
	// are included in the request, Grafana will select one in order of
	// specificity (ID, UID, Title).
	Get(ctx context.Context, cmd *GetFolderQuery) (*Folder, error)

	// Update is used to update a folder's UID, Title and Description. To change
	// a folder's parent folder, use Move.
	Update(ctx context.Context, cmd *UpdateFolderCommand) (*Folder, error)
	Delete(ctx context.Context, cmd *DeleteFolderCommand) error
	MakeUserAdmin(ctx context.Context, orgID int64, userID, folderID int64, setViewAndEditPermissions bool) error
	// Move changes a folder's parent folder to the requested new parent.
	Move(ctx context.Context, cmd *MoveFolderCommand) (*Folder, error)
}

type UpdateFolderCommand

type UpdateFolderCommand struct {
	UID   string `json:"-"`
	OrgID int64  `json:"-"`
	// NewUID it's an optional parameter used for overriding the existing folder UID
	NewUID *string `json:"uid"` // keep same json tag with the legacy command for not breaking the existing APIs
	// NewTitle it's an optional parameter used for overriding the existing folder title
	NewTitle *string `json:"title"` // keep same json tag with the legacy command for not breaking the existing APIs
	// NewDescription it's an optional parameter used for overriding the existing folder description
	NewDescription *string `json:"description"` // keep same json tag with the legacy command for not breaking the existing APIs
	NewParentUID   *string `json:"-"`

	// Version only used by the legacy folder implementation
	Version int `json:"version"`
	// Overwrite only used by the legacy folder implementation
	Overwrite bool `json:"overwrite"`

	SignedInUser *user.SignedInUser `json:"-"`
}

UpdateFolderCommand captures the information required by the folder service to update a folder. Use Move to update a folder's parent folder.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL