From 81a71e11175d18a5d3f8238469499ca3ab8be43b Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 29 Feb 2024 14:59:49 +0700 Subject: [PATCH] UBERF-5812: Fix allow to delete based on all my accounts Signed-off-by: Andrey Sobolev --- models/tracker/src/index.ts | 2 +- packages/presentation/src/utils.ts | 28 +++++--- packages/query/src/index.ts | 6 ++ .../components/DeleteConfirmationPopup.svelte | 15 ++-- .../src/components/schedule/MonthView.svelte | 13 ++-- .../src/components/WorkspaceSettings.svelte | 7 +- .../projects/ProjectPresenter.svelte | 6 +- plugins/view-resources/src/utils.ts | 71 ++++++++++++++----- plugins/view/src/types.ts | 2 +- .../src/components/Workbench.svelte | 4 +- plugins/workbench-resources/src/connect.ts | 4 +- plugins/workbench-resources/src/index.ts | 3 +- server/middleware/src/configuration.ts | 4 +- server/middleware/src/spaceSecurity.ts | 8 +-- server/middleware/src/utils.ts | 4 +- 15 files changed, 116 insertions(+), 61 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 2e257085f14..19b043a7425 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -326,7 +326,7 @@ function defineApplication ( spaceClass: tracker.class.Project, componentProps: { _class: tracker.class.Project, - label: tracker.string.AllIssues, + label: tracker.string.AllProjects, icon: tracker.icon.Issues } } diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index f9191cb113f..1dc0bba39c3 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -187,12 +187,22 @@ export async function setClient (_client: MeasureClient): Promise { * @public */ export async function refreshClient (): Promise { - await liveQuery?.refreshConnect() - for (const q of globalQueries) { - q.refreshClient() + if (!(liveQuery?.isClosed() ?? true)) { + await liveQuery?.refreshConnect() + for (const q of globalQueries) { + q.refreshClient() + } } } +/** + * @public + */ +export async function purgeClient (): Promise { + await liveQuery?.close() + await pipeline?.close() +} + /** * @public */ @@ -529,13 +539,9 @@ export function isCollectionAttr (hierarchy: Hierarchy, key: KeyedAttribute): bo * @public */ export function decodeTokenPayload (token: string): any { - const parts = token.split('.') - - const payload = parts[1] - - const decodedPayload = atob(payload) - - const parsedPayload = JSON.parse(decodedPayload) + return JSON.parse(atob(token.split('.')[1])) +} - return parsedPayload +export function isAdminUser (): boolean { + return decodeTokenPayload(getMetadata(plugin.metadata.Token) ?? '').admin === 'true' } diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 1260b35dce0..aca0c65ed43 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -91,6 +91,7 @@ export class LiveQuery implements WithTx, Client { private readonly queries: Map>, Query[]> = new Map>, Query[]>() private readonly queue: Query[] = [] private queryCounter: number = 0 + private closed: boolean = false // A map of _class to documents. private readonly documentRefs = new Map, DocumentRef>>() @@ -104,7 +105,12 @@ export class LiveQuery implements WithTx, Client { await this.refreshConnect() } + public isClosed (): boolean { + return this.closed + } + async close (): Promise { + this.closed = true await this.client.close() } diff --git a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte index d772c13ca4a..7c8f4bb5e44 100644 --- a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte +++ b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte @@ -13,16 +13,16 @@ // limitations under the License. --> diff --git a/plugins/hr-resources/src/components/schedule/MonthView.svelte b/plugins/hr-resources/src/components/schedule/MonthView.svelte index c9d983d601b..f1c485da742 100644 --- a/plugins/hr-resources/src/components/schedule/MonthView.svelte +++ b/plugins/hr-resources/src/components/schedule/MonthView.svelte @@ -16,20 +16,21 @@ import contact, { Employee } from '@hcengineering/contact' import { AccountRole, getCurrentAccount, Ref } from '@hcengineering/core' import { tzDateCompare, type Department, type Request, type RequestType, type Staff } from '@hcengineering/hr' + import { isAdminUser } from '@hcengineering/presentation' import { areDatesEqual, - day as getDay, daysInMonth, + deviceOptionsStore as deviceInfo, eventToHTMLElement, + day as getDay, getWeekDayName, isWeekend, Label, LabelAndProps, + resizeObserver, Scroller, showPopup, - tooltip, - deviceOptionsStore as deviceInfo, - resizeObserver + tooltip } from '@hcengineering/ui' import hr from '../../plugin' import { getHolidayDatesForEmployee, getRequests, isHoliday } from '../../utils' @@ -183,7 +184,7 @@ } function isEditable (employee: Staff): boolean { - return editableList.includes(employee._id) && (isFutureDate() || me.role === AccountRole.Owner) + return editableList.includes(employee._id) && (isFutureDate() || me.role === AccountRole.Owner || isAdminUser()) } function getTooltip (requests: Request[], day: Date, staff: Staff): LabelAndProps | undefined { @@ -306,7 +307,7 @@ class="timeline-cell timeline-day-header flex-col-center justify-center" style={getCellStyle()} on:click={() => { - if (isFutureDate() || me.role === AccountRole.Owner) { + if (isFutureDate() || me.role === AccountRole.Owner || isAdminUser()) { setPublicHoliday(day) } }} diff --git a/plugins/setting-resources/src/components/WorkspaceSettings.svelte b/plugins/setting-resources/src/components/WorkspaceSettings.svelte index 8cf6fddfc0e..bfef9dff4f1 100644 --- a/plugins/setting-resources/src/components/WorkspaceSettings.svelte +++ b/plugins/setting-resources/src/components/WorkspaceSettings.svelte @@ -15,7 +15,7 @@