mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-16 17:21:29 +00:00

* feat(command): remove org * refactor: imports, unused code, error handling * reduce org removed in action * add org deletion to projections * add org removal to projections * add org removal to projections * org removed projection * lint import * projections * fix: table names in tests * fix: table names in tests * logging * add org state * fix(domain): add Owner removed to object details * feat(ListQuery): add with owner removed * fix(org-delete): add bool to functions to select with owner removed * fix(org-delete): add bools to user grants with events to determine if dependencies lost owner * fix(org-delete): add unit tests for owner removed and org removed events * fix(org-delete): add handling of org remove for grants and members * fix(org-delete): correction of unit tests for owner removed * fix(org-delete): update projections, unit tests and get functions * fix(org-delete): add change date to authnkeys and owner removed to org metadata * fix(org-delete): include owner removed for login names * fix(org-delete): some column fixes in projections and build for queries with owner removed * indexes * fix(org-delete): include review changes * fix(org-delete): change user projection name after merge * fix(org-delete): include review changes for project grant where no project owner is necessary * fix(org-delete): include auth and adminapi tables with owner removed information * fix(org-delete): cleanup username and orgdomain uniqueconstraints when org is removed * fix(org-delete): add permissions for org.remove * remove unnecessary unique constraints * fix column order in primary keys * fix(org-delete): include review changes * fix(org-delete): add owner removed indexes and chang setup step to create tables * fix(org-delete): move PK order of instance_id and change added user_grant from review * fix(org-delete): no params for prepareUserQuery * change to step 6 * merge main * fix(org-delete): OldUserName rename to private * fix linting * cleanup * fix: remove org test * create prerelease * chore: delete org-delete as prerelease Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
395 lines
12 KiB
Go
395 lines
12 KiB
Go
package assets
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
"github.com/zitadel/zitadel/internal/static"
|
|
)
|
|
|
|
func (h *Handler) UploadDefaultLabelPolicyLogo() Uploader {
|
|
return &labelPolicyLogoUploader{h.idGenerator, false, true, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadDefaultLabelPolicyLogoDark() Uploader {
|
|
return &labelPolicyLogoUploader{h.idGenerator, true, true, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadOrgLabelPolicyLogo() Uploader {
|
|
return &labelPolicyLogoUploader{h.idGenerator, false, false, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadOrgLabelPolicyLogoDark() Uploader {
|
|
return &labelPolicyLogoUploader{h.idGenerator, true, false, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
type labelPolicyLogoUploader struct {
|
|
idGenerator id.Generator
|
|
darkMode bool
|
|
defaultPolicy bool
|
|
contentTypes []string
|
|
maxSize int64
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) ContentTypeAllowed(contentType string) bool {
|
|
for _, ct := range l.contentTypes {
|
|
if strings.HasPrefix(contentType, ct) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) ObjectType() static.ObjectType {
|
|
return static.ObjectTypeStyling
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) MaxFileSize() int64 {
|
|
return l.maxSize
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) ObjectName(_ authz.CtxData) (string, error) {
|
|
suffixID, err := l.idGenerator.Next()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
prefix := domain.LabelPolicyLogoPath
|
|
if l.darkMode {
|
|
return prefix + "-" + domain.Dark + "-" + suffixID, nil
|
|
}
|
|
return prefix + "-" + suffixID, nil
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) ResourceOwner(instance authz.Instance, ctxData authz.CtxData) string {
|
|
if l.defaultPolicy {
|
|
return instance.InstanceID()
|
|
}
|
|
return ctxData.OrgID
|
|
}
|
|
|
|
func (l *labelPolicyLogoUploader) UploadAsset(ctx context.Context, orgID string, upload *command.AssetUpload, commands *command.Commands) error {
|
|
if l.defaultPolicy {
|
|
if l.darkMode {
|
|
_, err := commands.AddLogoDarkDefaultLabelPolicy(ctx, upload)
|
|
return err
|
|
}
|
|
_, err := commands.AddLogoDefaultLabelPolicy(ctx, upload)
|
|
return err
|
|
}
|
|
if l.darkMode {
|
|
_, err := commands.AddLogoDarkLabelPolicy(ctx, orgID, upload)
|
|
return err
|
|
}
|
|
_, err := commands.AddLogoLabelPolicy(ctx, orgID, upload)
|
|
return err
|
|
}
|
|
|
|
func (h *Handler) GetDefaultLabelPolicyLogo() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: false, defaultPolicy: true, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetDefaultLabelPolicyLogoDark() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: true, defaultPolicy: true, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewDefaultLabelPolicyLogo() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: false, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewDefaultLabelPolicyLogoDark() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: true, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetOrgLabelPolicyLogo() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: false, defaultPolicy: false, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetOrgLabelPolicyLogoDark() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: true, defaultPolicy: false, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewOrgLabelPolicyLogo() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: false, defaultPolicy: false, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewOrgLabelPolicyLogoDark() Downloader {
|
|
return &labelPolicyLogoDownloader{query: h.query, darkMode: true, defaultPolicy: false, preview: true}
|
|
}
|
|
|
|
type labelPolicyLogoDownloader struct {
|
|
query *query.Queries
|
|
darkMode bool
|
|
defaultPolicy bool
|
|
preview bool
|
|
}
|
|
|
|
func (l *labelPolicyLogoDownloader) ObjectName(ctx context.Context, path string) (string, error) {
|
|
policy, err := getLabelPolicy(ctx, l.defaultPolicy, l.preview, l.query)
|
|
if err != nil {
|
|
return "", nil
|
|
}
|
|
if l.darkMode {
|
|
return policy.Dark.LogoURL, nil
|
|
}
|
|
return policy.Light.LogoURL, nil
|
|
}
|
|
|
|
func (l *labelPolicyLogoDownloader) ResourceOwner(ctx context.Context, _ string) string {
|
|
return getLabelPolicyResourceOwner(ctx, l.defaultPolicy, l.preview, l.query)
|
|
}
|
|
|
|
func (h *Handler) UploadDefaultLabelPolicyIcon() Uploader {
|
|
return &labelPolicyIconUploader{h.idGenerator, false, true, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadDefaultLabelPolicyIconDark() Uploader {
|
|
return &labelPolicyIconUploader{h.idGenerator, true, true, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadOrgLabelPolicyIcon() Uploader {
|
|
return &labelPolicyIconUploader{h.idGenerator, false, false, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadOrgLabelPolicyIconDark() Uploader {
|
|
return &labelPolicyIconUploader{h.idGenerator, true, false, []string{"image/"}, 1 << 19}
|
|
}
|
|
|
|
type labelPolicyIconUploader struct {
|
|
idGenerator id.Generator
|
|
darkMode bool
|
|
defaultPolicy bool
|
|
contentTypes []string
|
|
maxSize int64
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) ContentTypeAllowed(contentType string) bool {
|
|
for _, ct := range l.contentTypes {
|
|
if strings.HasPrefix(contentType, ct) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) ObjectType() static.ObjectType {
|
|
return static.ObjectTypeStyling
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) MaxFileSize() int64 {
|
|
return l.maxSize
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) ObjectName(_ authz.CtxData) (string, error) {
|
|
suffixID, err := l.idGenerator.Next()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
prefix := domain.LabelPolicyIconPath
|
|
if l.darkMode {
|
|
return prefix + "-" + domain.Dark + "-" + suffixID, nil
|
|
}
|
|
return prefix + "-" + suffixID, nil
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) ResourceOwner(instance authz.Instance, ctxData authz.CtxData) string {
|
|
if l.defaultPolicy {
|
|
return instance.InstanceID()
|
|
}
|
|
return ctxData.OrgID
|
|
}
|
|
|
|
func (l *labelPolicyIconUploader) UploadAsset(ctx context.Context, orgID string, upload *command.AssetUpload, commands *command.Commands) error {
|
|
if l.defaultPolicy {
|
|
if l.darkMode {
|
|
_, err := commands.AddIconDarkDefaultLabelPolicy(ctx, upload)
|
|
return err
|
|
}
|
|
_, err := commands.AddIconDefaultLabelPolicy(ctx, upload)
|
|
return err
|
|
}
|
|
|
|
if l.darkMode {
|
|
_, err := commands.AddIconDarkLabelPolicy(ctx, orgID, upload)
|
|
return err
|
|
}
|
|
_, err := commands.AddIconLabelPolicy(ctx, orgID, upload)
|
|
return err
|
|
}
|
|
|
|
func (h *Handler) GetDefaultLabelPolicyIcon() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: false, defaultPolicy: true, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetDefaultLabelPolicyIconDark() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: true, defaultPolicy: true, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewDefaultLabelPolicyIcon() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: false, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewDefaultLabelPolicyIconDark() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: true, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetOrgLabelPolicyIcon() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: false, defaultPolicy: false, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetOrgLabelPolicyIconDark() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: true, defaultPolicy: false, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewOrgLabelPolicyIcon() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: false, defaultPolicy: false, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewOrgLabelPolicyIconDark() Downloader {
|
|
return &labelPolicyIconDownloader{query: h.query, darkMode: true, defaultPolicy: false, preview: true}
|
|
}
|
|
|
|
type labelPolicyIconDownloader struct {
|
|
query *query.Queries
|
|
darkMode bool
|
|
defaultPolicy bool
|
|
preview bool
|
|
}
|
|
|
|
func (l *labelPolicyIconDownloader) ObjectName(ctx context.Context, path string) (string, error) {
|
|
policy, err := getLabelPolicy(ctx, l.defaultPolicy, l.preview, l.query)
|
|
if err != nil {
|
|
return "", nil
|
|
}
|
|
if l.darkMode {
|
|
return policy.Dark.IconURL, nil
|
|
}
|
|
return policy.Light.IconURL, nil
|
|
}
|
|
|
|
func (l *labelPolicyIconDownloader) ResourceOwner(ctx context.Context, _ string) string {
|
|
return getLabelPolicyResourceOwner(ctx, l.defaultPolicy, l.preview, l.query)
|
|
}
|
|
|
|
func (h *Handler) UploadDefaultLabelPolicyFont() Uploader {
|
|
return &labelPolicyFontUploader{h.idGenerator, true, []string{"font/", "application/octet-stream"}, 1 << 19}
|
|
}
|
|
|
|
func (h *Handler) UploadOrgLabelPolicyFont() Uploader {
|
|
return &labelPolicyFontUploader{h.idGenerator, false, []string{"font/", "application/octet-stream"}, 1 << 19}
|
|
}
|
|
|
|
type labelPolicyFontUploader struct {
|
|
idGenerator id.Generator
|
|
defaultPolicy bool
|
|
contentTypes []string
|
|
maxSize int64
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) ContentTypeAllowed(contentType string) bool {
|
|
for _, ct := range l.contentTypes {
|
|
if strings.HasPrefix(contentType, ct) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) ObjectType() static.ObjectType {
|
|
return static.ObjectTypeStyling
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) MaxFileSize() int64 {
|
|
return l.maxSize
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) ObjectName(_ authz.CtxData) (string, error) {
|
|
suffixID, err := l.idGenerator.Next()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
prefix := domain.LabelPolicyFontPath
|
|
return prefix + "-" + suffixID, nil
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) ResourceOwner(instance authz.Instance, ctxData authz.CtxData) string {
|
|
if l.defaultPolicy {
|
|
return instance.InstanceID()
|
|
}
|
|
return ctxData.OrgID
|
|
}
|
|
|
|
func (l *labelPolicyFontUploader) UploadAsset(ctx context.Context, orgID string, upload *command.AssetUpload, commands *command.Commands) error {
|
|
if l.defaultPolicy {
|
|
_, err := commands.AddFontDefaultLabelPolicy(ctx, upload)
|
|
return err
|
|
}
|
|
_, err := commands.AddFontLabelPolicy(ctx, orgID, upload)
|
|
return err
|
|
}
|
|
|
|
func (h *Handler) GetDefaultLabelPolicyFont() Downloader {
|
|
return &labelPolicyFontDownloader{query: h.query, defaultPolicy: true, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewDefaultLabelPolicyFont() Downloader {
|
|
return &labelPolicyFontDownloader{query: h.query, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
func (h *Handler) GetOrgLabelPolicyFont() Downloader {
|
|
return &labelPolicyFontDownloader{query: h.query, defaultPolicy: false, preview: false}
|
|
}
|
|
|
|
func (h *Handler) GetPreviewOrgLabelPolicyFont() Downloader {
|
|
return &labelPolicyFontDownloader{query: h.query, defaultPolicy: true, preview: true}
|
|
}
|
|
|
|
type labelPolicyFontDownloader struct {
|
|
query *query.Queries
|
|
defaultPolicy bool
|
|
preview bool
|
|
}
|
|
|
|
func (l *labelPolicyFontDownloader) ObjectName(ctx context.Context, path string) (string, error) {
|
|
policy, err := getLabelPolicy(ctx, l.defaultPolicy, l.preview, l.query)
|
|
if err != nil {
|
|
return "", nil
|
|
}
|
|
return policy.FontURL, nil
|
|
}
|
|
|
|
func (l *labelPolicyFontDownloader) ResourceOwner(ctx context.Context, _ string) string {
|
|
return getLabelPolicyResourceOwner(ctx, l.defaultPolicy, l.preview, l.query)
|
|
}
|
|
|
|
func getLabelPolicy(ctx context.Context, defaultPolicy, preview bool, queries *query.Queries) (*query.LabelPolicy, error) {
|
|
if defaultPolicy {
|
|
if preview {
|
|
return queries.DefaultPreviewLabelPolicy(ctx)
|
|
}
|
|
return queries.DefaultActiveLabelPolicy(ctx)
|
|
}
|
|
if preview {
|
|
return queries.PreviewLabelPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
|
}
|
|
return queries.ActiveLabelPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID, false)
|
|
}
|
|
|
|
func getLabelPolicyResourceOwner(ctx context.Context, defaultPolicy, preview bool, queries *query.Queries) string {
|
|
if defaultPolicy {
|
|
return authz.GetInstance(ctx).InstanceID()
|
|
}
|
|
policy, err := getLabelPolicy(ctx, defaultPolicy, preview, queries)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
if policy.IsDefault {
|
|
return authz.GetInstance(ctx).InstanceID()
|
|
}
|
|
return authz.GetCtxData(ctx).OrgID
|
|
}
|