snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
126
server/compose/rest/icon.go
Normal file
126
server/compose/rest/icon.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza/server/pkg/errors"
|
||||
"mime/multipart"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/compose/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/compose/service"
|
||||
"github.com/cortezaproject/corteza/server/compose/types"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
)
|
||||
|
||||
type (
|
||||
iconPayload struct {
|
||||
*attachmentPayload
|
||||
}
|
||||
|
||||
iconSetPayload struct {
|
||||
Filter types.IconFilter `json:"filter"`
|
||||
Set []*iconPayload `json:"set"`
|
||||
}
|
||||
|
||||
Icon struct {
|
||||
locale service.ResourceTranslationsManagerService
|
||||
attachment service.AttachmentService
|
||||
ac iconAccessController
|
||||
}
|
||||
|
||||
iconAccessController interface {
|
||||
CanGrant(context.Context) bool
|
||||
}
|
||||
)
|
||||
|
||||
func (Icon) New() *Icon {
|
||||
return &Icon{
|
||||
locale: service.DefaultResourceTranslation,
|
||||
attachment: service.DefaultAttachment,
|
||||
ac: service.DefaultAccessControl,
|
||||
}
|
||||
}
|
||||
|
||||
func (ctrl *Icon) List(ctx context.Context, r *request.IconList) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
f = types.AttachmentFilter{
|
||||
Kind: types.IconAttachment,
|
||||
}
|
||||
set types.AttachmentSet
|
||||
)
|
||||
|
||||
if f.Paging, err = filter.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if f.Sorting, err = filter.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//Get only the undeleted icons
|
||||
f.Deleted = filter.StateExcluded
|
||||
|
||||
set, f, err = ctrl.attachment.Find(ctx, f)
|
||||
return ctrl.makeIconFilterPayload(ctx, set, f, err)
|
||||
}
|
||||
|
||||
func (ctrl *Icon) Upload(ctx context.Context, r *request.IconUpload) (interface{}, error) {
|
||||
file, err := r.Icon.Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func(file multipart.File) {
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}(file)
|
||||
|
||||
a, err := ctrl.attachment.CreateIconAttachment(
|
||||
ctx,
|
||||
r.Icon.Filename,
|
||||
r.Icon.Size,
|
||||
file,
|
||||
)
|
||||
|
||||
return makeAttachmentPayload(ctx, a, err)
|
||||
}
|
||||
|
||||
func (ctrl *Icon) makeIconFilterPayload(ctx context.Context, nn types.AttachmentSet, f types.AttachmentFilter, err error) (*iconSetPayload, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
a *attachmentPayload
|
||||
ff types.IconFilter
|
||||
)
|
||||
|
||||
ff.Paging = f.Paging
|
||||
ff.Sorting = f.Sorting
|
||||
|
||||
res := &iconSetPayload{Filter: ff, Set: make([]*iconPayload, len(nn))}
|
||||
|
||||
for i := range nn {
|
||||
a, _ = makeAttachmentPayload(ctx, nn[i], nil)
|
||||
res.Set[i] = &iconPayload{a}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ctrl *Icon) Delete(ctx context.Context, r *request.IconDelete) (interface{}, error) {
|
||||
if !auth.GetIdentityFromContext(ctx).Valid() {
|
||||
return nil, errors.Unauthorized("cannot delete icon")
|
||||
}
|
||||
|
||||
_, err := ctrl.attachment.FindByID(ctx, 0, r.IconID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return api.OK(), ctrl.attachment.DeleteByID(ctx, 0, r.IconID)
|
||||
}
|
||||
Reference in New Issue
Block a user