From 314501a161dd42759a700e69087861ddac37454c Mon Sep 17 00:00:00 2001 From: Sergei Ogorelkov Date: Tue, 30 May 2023 20:56:45 +0400 Subject: [PATCH] [UBER-323] "Create Project" fixes (#3296) Signed-off-by: Sergei Ogorelkov --- .../components/projects/CreateProject.svelte | 21 ++++++-------- server/middleware/src/spaceSecurity.ts | 29 +++++++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/plugins/tracker-resources/src/components/projects/CreateProject.svelte b/plugins/tracker-resources/src/components/projects/CreateProject.svelte index 50a96217ee..78bb3dc26c 100644 --- a/plugins/tracker-resources/src/components/projects/CreateProject.svelte +++ b/plugins/tracker-resources/src/components/projects/CreateProject.svelte @@ -57,7 +57,8 @@ let description: string = project?.description ?? '' let isPrivate: boolean = project?.private ?? false let icon: Asset | undefined = project?.icon ?? undefined - let color: number | undefined = project?.color ?? undefined + let color = project?.color ?? getColorNumberByText(name) + let isColorSelected = false let defaultAssignee: Ref | null | undefined = project?.defaultAssignee ?? null let members: Ref[] = project?.members !== undefined ? hierarchy.clone(project.members) : [getCurrentAccount()._id] @@ -141,20 +142,14 @@ } } } + if (Object.keys(update).length > 0) { - const ops = client.apply(project._id).notMatch(tracker.class.Project, { identifier: projectData.identifier }) - isSaving = true - await ops.update(project, update) - const succeeded = await ops.commit() + await client.update(project, update) isSaving = false - - if (succeeded) { - close() - } else { - changeIdentity(changeIdentityRef) - } } + + close() } async function createProject () { @@ -209,10 +204,11 @@ } function chooseIcon (ev: MouseEvent) { - showPopup(ProjectIconChooser, { icon, color: color ?? getColorNumberByText(name) }, 'top', (result) => { + showPopup(ProjectIconChooser, { icon, color }, 'top', (result) => { if (result !== undefined && result !== null) { icon = result.icon color = result.color + isColorSelected = true } }) } @@ -263,6 +259,7 @@ on:input={() => { if (isNew) { identifier = name.toLocaleUpperCase().replaceAll(' ', '_').substring(0, 5) + color = isColorSelected ? color : getColorNumberByText(name) } }} /> diff --git a/server/middleware/src/spaceSecurity.ts b/server/middleware/src/spaceSecurity.ts index acf297083d..c3b87fee1b 100644 --- a/server/middleware/src/spaceSecurity.ts +++ b/server/middleware/src/spaceSecurity.ts @@ -271,16 +271,11 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar return users.map((p) => p.email) } - async tx (ctx: SessionContext, tx: Tx): Promise { + private async getTxTargets (ctx: SessionContext, tx: Tx): Promise { const h = this.storage.hierarchy let targets: string[] | undefined if (h.isDerived(tx._class, core.class.TxCUD)) { - const cudTx = tx as TxCUD - const isSpace = h.isDerived(cudTx.objectClass, core.class.Space) - if (isSpace) { - await this.handleTx(ctx, cudTx as TxCUD) - } const account = await getUser(this.storage, ctx) if (tx.objectSpace === (account._id as string)) { targets = [account.email] @@ -289,6 +284,8 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar if (space !== undefined) { targets = await this.getTargets(space.members) if (!isOwner(account)) { + const cudTx = tx as TxCUD + const isSpace = h.isDerived(cudTx.objectClass, core.class.Space) const allowed = this.allowedSpaces[account._id] if (allowed === undefined || !allowed.includes(isSpace ? (cudTx.objectId as Ref) : tx.objectSpace)) { throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {})) @@ -302,6 +299,19 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar } } } + } + + return targets + } + + private async proccessTx (ctx: SessionContext, tx: Tx): Promise { + const h = this.storage.hierarchy + if (h.isDerived(tx._class, core.class.TxCUD)) { + const cudTx = tx as TxCUD + const isSpace = h.isDerived(cudTx.objectClass, core.class.Space) + if (isSpace) { + await this.handleTx(ctx, cudTx as TxCUD) + } if (h.isDerived(cudTx.objectClass, core.class.Account) && cudTx._class === core.class.TxUpdateDoc) { const ctx = cudTx as TxUpdateDoc if (ctx.operations.role !== undefined) { @@ -309,8 +319,15 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar } } } + } + async tx (ctx: SessionContext, tx: Tx): Promise { + await this.proccessTx(ctx, tx) + const targets = await this.getTxTargets(ctx, tx) const res = await this.provideTx(ctx, tx) + for (const tx of res[1]) { + await this.proccessTx(ctx, tx) + } return [res[0], res[1], mergeTargets(targets, res[2])] }