From ba57b3a9bf59e6e46e85b141760656bbca7dfba0 Mon Sep 17 00:00:00 2001 From: Anton Alexeyev Date: Tue, 10 Jun 2025 16:51:21 +0700 Subject: [PATCH] Allow workspace owners to edit spaces (#9194) Signed-off-by: Anton Alexeyev --- .../view-resources/src/visibilityTester.ts | 12 +++++++--- .../sanity/tests/documents/REQ-10.spec.ts | 23 ++++++++++++------- .../model/documents/document-content-page.ts | 11 +++++++++ qms-tests/sanity/tests/utils.ts | 5 ++++ .../recruiting/common-recruiting-page.ts | 4 +++- .../tests/model/recruiting/talents-page.ts | 2 +- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/plugins/view-resources/src/visibilityTester.ts b/plugins/view-resources/src/visibilityTester.ts index 00d357315c..9d6fda382f 100644 --- a/plugins/view-resources/src/visibilityTester.ts +++ b/plugins/view-resources/src/visibilityTester.ts @@ -17,6 +17,7 @@ import core, { checkPermission, getCurrentAccount, toIdMap, + AccountRole, type Doc, type Space, type TypedSpace @@ -29,6 +30,11 @@ function isTypedSpace (space: Space): space is TypedSpace { return getClient().getHierarchy().isDerived(space._class, core.class.TypedSpace) } +function isSpaceOwner (space: Space): boolean { + const currentAccount = getCurrentAccount() + return currentAccount.role === AccountRole.Owner || (space.owners ?? []).includes(currentAccount.uuid) +} + export async function canDeleteObject (doc?: Doc | Doc[]): Promise { if (doc === undefined) { return false @@ -57,7 +63,7 @@ export async function canEditSpace (doc?: Doc | Doc[]): Promise { const space = doc as Space - if ((space.owners ?? []).includes(getCurrentAccount().uuid)) { + if (isSpaceOwner(space)) { return true } @@ -83,7 +89,7 @@ export async function canArchiveSpace (doc?: Doc | Doc[]): Promise { const space = doc as Space - if ((space.owners ?? []).includes(getCurrentAccount().uuid)) { + if (isSpaceOwner(space)) { return true } @@ -109,7 +115,7 @@ export async function canDeleteSpace (doc?: Doc | Doc[]): Promise { const space = doc as Space - if ((space.owners ?? []).includes(getCurrentAccount().uuid)) { + if (isSpaceOwner(space)) { return true } diff --git a/qms-tests/sanity/tests/documents/REQ-10.spec.ts b/qms-tests/sanity/tests/documents/REQ-10.spec.ts index 7b649c71a3..2242ad3c19 100644 --- a/qms-tests/sanity/tests/documents/REQ-10.spec.ts +++ b/qms-tests/sanity/tests/documents/REQ-10.spec.ts @@ -4,6 +4,7 @@ import { DocumentURI, generateId, getSecondPage, + getThirdPage, HomepageURI, PlatformSettingSecond, PlatformURI @@ -121,18 +122,24 @@ test.describe('ISO 13485, 4.2.4 Control of documents ensure that documents of ex }) }) - test('TESTS-404. As a space member only, I cannot create any doc from that space', async ({ page }) => { + test('TESTS-404. As a space member only, I cannot create any doc from that space', async ({ page, browser }) => { await allure.description('Requirement\nUser is not able to create any document from that space') await allure.tms('TESTS-404', 'https://tracex.hc.engineering/workbench/platform/tracker/TESTS-404') - await test.step('2. cCheck if user can not create documents as a space member', async () => { - const folderName = faker.word.words(1) - const documentContentPage = new DocumentContentPage(page) + const folderName = faker.word.words(1) + const userThirdPage = await getThirdPage(browser) + const documentContentPage = new DocumentContentPage(page) + const documentContentPageThird = new DocumentContentPage(userThirdPage) + await (await userThirdPage.goto(`${PlatformURI}/${DocumentURI}`))?.finished() + await test.step('2. Add a user as a space member', async () => { await documentContentPage.clickAddFolderButton() await documentContentPage.createDocumentSpaceMembersToJustMember(folderName) - await documentContentPage.checkIfEditSpaceButtonExists(folderName, false) - await page.keyboard.press('Escape') - await documentContentPage.checkIfUserCanSelectSpace(folderName, false) - await attachScreenshot('TESTS-404_non_space_member_can_not_create_documents.png', page) + await documentContentPage.addThirdUserToMembers(folderName) + }) + await test.step('3. Check if user can not create documents as a space member', async () => { + await documentContentPageThird.checkIfEditSpaceButtonExists(folderName, false) + await userThirdPage.keyboard.press('Escape') + await documentContentPageThird.checkIfUserCanSelectSpace(folderName, false) + await attachScreenshot('TESTS-404_non_space_member_can_not_create_documents.png', userThirdPage) }) }) diff --git a/qms-tests/sanity/tests/model/documents/document-content-page.ts b/qms-tests/sanity/tests/model/documents/document-content-page.ts index a74e33bdbb..a159c9d1ea 100644 --- a/qms-tests/sanity/tests/model/documents/document-content-page.ts +++ b/qms-tests/sanity/tests/model/documents/document-content-page.ts @@ -589,6 +589,17 @@ export class DocumentContentPage extends DocumentCommonPage { await this.createButton.click() } + async addThirdUserToMembers (spaceName: string): Promise { + await this.page.getByRole('button', { name: spaceName }).hover() + await this.page.getByRole('button', { name: spaceName }).getByRole('button').click() + await this.editDocumentSpace.click() + await this.page.getByRole('button', { name: 'AJ DK 2 members' }).click() + await this.page.getByRole('button', { name: 'VC Velasquez Cain' }).click() + await this.page.keyboard.press('Escape') + await this.page.waitForTimeout(1000) + await this.saveButton.click() + } + async checkIfTheSpaceIsVisible (spaceName: string, visible: boolean): Promise { if (visible) { await expect(this.page.getByRole('button', { name: spaceName })).toBeVisible() diff --git a/qms-tests/sanity/tests/utils.ts b/qms-tests/sanity/tests/utils.ts index 89a55f6d5d..a95c17981b 100644 --- a/qms-tests/sanity/tests/utils.ts +++ b/qms-tests/sanity/tests/utils.ts @@ -57,6 +57,11 @@ export async function getSecondPage (browser: Browser): Promise { return await userSecondContext.newPage() } +export async function getThirdPage (browser: Browser): Promise { + const userSecondContext = await browser.newContext({ storageState: PlatformSettingThird }) + return await userSecondContext.newPage() +} + export async function getNewPage (browser: Browser): Promise { const context = await browser.newContext({ storageState: undefined }) return await context.newPage() diff --git a/tests/sanity/tests/model/recruiting/common-recruiting-page.ts b/tests/sanity/tests/model/recruiting/common-recruiting-page.ts index 9004946aa7..01201a85e0 100644 --- a/tests/sanity/tests/model/recruiting/common-recruiting-page.ts +++ b/tests/sanity/tests/model/recruiting/common-recruiting-page.ts @@ -21,7 +21,9 @@ export class CommonRecruitingPage extends CalendarPage { this.page.locator('.popupPanel > .hulyHeader-container > .hulyHeader-buttonsGroup.actions > button').first() readonly buttonDelete = (): Locator => this.page.locator('button[class*="menuItem"] span', { hasText: 'Delete' }) - readonly buttonAddSocialLinks = (): Locator => this.page.locator('button[id="presentation:string:AddSocialLinks"]') + readonly buttonAddSocialLinks = (): Locator => + this.page.locator('button[id="presentation:string:AddSocialLinks"]').last() + readonly buttonContactPhone = (): Locator => this.page.locator('div[class^="popupPanel-body"] div.horizontal button[id="contact:string:Phone"]') diff --git a/tests/sanity/tests/model/recruiting/talents-page.ts b/tests/sanity/tests/model/recruiting/talents-page.ts index 9264894f37..39778e2ef2 100644 --- a/tests/sanity/tests/model/recruiting/talents-page.ts +++ b/tests/sanity/tests/model/recruiting/talents-page.ts @@ -43,7 +43,7 @@ export class TalentsPage extends CommonRecruitingPage { talentsTab = (): Locator => this.page.locator('.antiPanel-navigator').locator('text=Talents') newTalentButton = (): Locator => this.page.locator('button:has-text("New Talent")') - addSocialLinksButton = (): Locator => this.page.locator('[id="presentation\\:string\\:AddSocialLinks"]') + addSocialLinksButton = (): Locator => this.page.locator('[id="presentation\\:string\\:AddSocialLinks"]').last() emailSelectorButton = (): Locator => this.page.locator('.antiPopup').locator('text=Email') confirmEmailButton = (): Locator => this.page.locator('#channel-ok.antiButton') createTalentButton = (): Locator => this.page.locator('.antiCard button:has-text("Create")')