From 9e97d24d6c85c7af0af51180e05694dc04cdaf66 Mon Sep 17 00:00:00 2001 From: StaNov Date: Tue, 17 Dec 2024 15:37:44 +0100 Subject: [PATCH] E2E: Batch operation permission testing needs namespaces enabled --- .../data/PermissionsTestData.kt | 3 + .../e2eData/PermissionsE2eDataController.kt | 2 + .../common/apiCalls/testData/testData.ts | 3 +- e2e/cypress/common/permissions/main.ts | 3 +- .../permissions/permissionsAdmin.2.cy.ts | 30 ++++---- .../permissions/permissionsBatchJobs.1.cy.ts | 9 ++- .../permissions/permissionsBatchJobs.2.cy.ts | 9 ++- .../permissions/permissionsKeys.1.cy.ts | 8 +-- .../permissions/permissionsKeys.2.cy.ts | 6 +- .../permissionsPerLanguage.1.cy.ts | 22 +++--- .../permissionsPerLanguage.2.cy.ts | 24 ++++--- .../permissionsServerAdmin.2.cy.ts | 34 +++++----- .../permissions/permissionsTask.cy.ts | 4 +- .../permissionsTranslations.1.cy.ts | 4 +- .../permissionsTranslations.2.cy.ts | 68 ++++++++++--------- e2e/cypress/e2e/projects/projectMembers.cy.ts | 1 + 16 files changed, 133 insertions(+), 97 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/PermissionsTestData.kt b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/PermissionsTestData.kt index 2e99e4ae43..8be65b5a39 100644 --- a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/PermissionsTestData.kt +++ b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/data/PermissionsTestData.kt @@ -97,6 +97,7 @@ class PermissionsTestData { translateLanguageTags: List? = null, stateChangeLanguageTags: List? = null, organizationBaseScopes: List? = null, + useNamespaces: Boolean = false, ): UserAccount { val me = root.addUserAccount { @@ -114,6 +115,8 @@ class PermissionsTestData { } } + projectBuilder.self.useNamespaces = useNamespaces + if (organizationBaseScopes != null) { organizationBuilder.self.basePermission.type = null organizationBuilder.self.basePermission.scopes = organizationBaseScopes.toTypedArray() diff --git a/backend/development/src/main/kotlin/io/tolgee/controllers/internal/e2eData/PermissionsE2eDataController.kt b/backend/development/src/main/kotlin/io/tolgee/controllers/internal/e2eData/PermissionsE2eDataController.kt index c381a37e3f..de81eec61d 100644 --- a/backend/development/src/main/kotlin/io/tolgee/controllers/internal/e2eData/PermissionsE2eDataController.kt +++ b/backend/development/src/main/kotlin/io/tolgee/controllers/internal/e2eData/PermissionsE2eDataController.kt @@ -28,6 +28,7 @@ class PermissionsE2eDataController() : AbstractE2eDataController() { @RequestParam viewLanguageTags: List?, @RequestParam translateLanguageTags: List?, @RequestParam stateChangeLanguageTags: List?, + @RequestParam useNamespaces: Boolean = false, ): StandardTestDataResult { val user = this.permissionsTestData.addUserWithPermissions( @@ -36,6 +37,7 @@ class PermissionsE2eDataController() : AbstractE2eDataController() { viewLanguageTags = viewLanguageTags, translateLanguageTags = translateLanguageTags, stateChangeLanguageTags = stateChangeLanguageTags, + useNamespaces = useNamespaces, ) this.permissionsTestData.addTasks( mutableSetOf(user, permissionsTestData.serverAdmin.self), diff --git a/e2e/cypress/common/apiCalls/testData/testData.ts b/e2e/cypress/common/apiCalls/testData/testData.ts index 4fa3280d49..3d1e6f6b9a 100644 --- a/e2e/cypress/common/apiCalls/testData/testData.ts +++ b/e2e/cypress/common/apiCalls/testData/testData.ts @@ -126,13 +126,14 @@ export type PermissionsOptions = { }; export const generatePermissionsData = { - generate: (options: Partial) => { + generate: (options: Partial, useNamespaces = false) => { const params = new URLSearchParams(); Object.entries(options).forEach(([key, values]) => { values.forEach((value) => { params.append(key, value); }); }); + params.append('useNamespaces', String(useNamespaces)); return internalFetch( `e2e-data/permissions/generate-with-user?${params.toString()}` ); diff --git a/e2e/cypress/common/permissions/main.ts b/e2e/cypress/common/permissions/main.ts index 10a2a217d5..ac4444819f 100644 --- a/e2e/cypress/common/permissions/main.ts +++ b/e2e/cypress/common/permissions/main.ts @@ -88,12 +88,13 @@ export function loginAndGetInfo(user: UserMail, projectId: number) { export function visitProjectWithPermissions( options: Partial, + useNamespaces = false, user: UserMail = 'me@me.me' ): Promise { return new Cypress.Promise((resolve) => { generatePermissionsData .clean() - .then(() => generatePermissionsData.generate(options)) + .then(() => generatePermissionsData.generate(options, useNamespaces)) .then((res) => { return res.body.projects[0].id; }) diff --git a/e2e/cypress/e2e/projects/permissions/permissionsAdmin.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsAdmin.2.cy.ts index 05d7ac7643..56c41ede69 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsAdmin.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsAdmin.2.cy.ts @@ -7,19 +7,21 @@ import { describe('Permissions admin 2', () => { it('admin', () => { - visitProjectWithPermissions({ scopes: ['admin'] }).then((projectInfo) => { - checkPermissions(projectInfo, { - 'project-menu-item-dashboard': SKIP, - 'project-menu-item-translations': RUN, - 'project-menu-item-tasks': SKIP, - 'project-menu-item-settings': SKIP, - 'project-menu-item-languages': SKIP, - 'project-menu-item-members': SKIP, - 'project-menu-item-import': SKIP, - 'project-menu-item-export': SKIP, - 'project-menu-item-developer': SKIP, - 'project-menu-item-integrate': SKIP, - }); - }); + visitProjectWithPermissions({ scopes: ['admin'] }, true).then( + (projectInfo) => { + checkPermissions(projectInfo, { + 'project-menu-item-dashboard': SKIP, + 'project-menu-item-translations': RUN, + 'project-menu-item-tasks': SKIP, + 'project-menu-item-settings': SKIP, + 'project-menu-item-languages': SKIP, + 'project-menu-item-members': SKIP, + 'project-menu-item-import': SKIP, + 'project-menu-item-export': SKIP, + 'project-menu-item-developer': SKIP, + 'project-menu-item-integrate': SKIP, + }); + } + ); }); }); diff --git a/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.1.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.1.cy.ts index 0cacce02e6..1827ca5970 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.1.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.1.cy.ts @@ -7,9 +7,12 @@ import { describe('Batch jobs permissions 1', () => { it('translations.batch-machine', () => { - visitProjectWithPermissions({ - scopes: ['translations.batch-machine'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.batch-machine'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.2.cy.ts index 9df6299dbf..03ae7ec5ab 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsBatchJobs.2.cy.ts @@ -7,9 +7,12 @@ import { describe('Batch jobs permissions 2', () => { it('translations.batch-by-mt', () => { - visitProjectWithPermissions({ - scopes: ['translations.batch-by-tm'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.batch-by-tm'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsKeys.1.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsKeys.1.cy.ts index b09c4036e6..326abf9ed7 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsKeys.1.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsKeys.1.cy.ts @@ -7,7 +7,7 @@ import { describe('Keys permissions 1', () => { it('screenshots.view', { retries: { runMode: 3 } }, () => { - visitProjectWithPermissions({ scopes: ['screenshots.view'] }).then( + visitProjectWithPermissions({ scopes: ['screenshots.view'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, @@ -19,7 +19,7 @@ describe('Keys permissions 1', () => { }); it('screenshots.upload', { retries: { runMode: 3 } }, () => { - visitProjectWithPermissions({ scopes: ['screenshots.upload'] }).then( + visitProjectWithPermissions({ scopes: ['screenshots.upload'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, @@ -31,7 +31,7 @@ describe('Keys permissions 1', () => { }); it('screenshots.delete', () => { - visitProjectWithPermissions({ scopes: ['screenshots.delete'] }).then( + visitProjectWithPermissions({ scopes: ['screenshots.delete'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, @@ -43,7 +43,7 @@ describe('Keys permissions 1', () => { }); it('keys.view', () => { - visitProjectWithPermissions({ scopes: ['keys.view'] }).then( + visitProjectWithPermissions({ scopes: ['keys.view'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsKeys.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsKeys.2.cy.ts index b4776c5bd4..cee7801ec5 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsKeys.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsKeys.2.cy.ts @@ -7,7 +7,7 @@ import { describe('Keys permissions 2', () => { it('keys.edit', () => { - visitProjectWithPermissions({ scopes: ['keys.edit'] }).then( + visitProjectWithPermissions({ scopes: ['keys.edit'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, @@ -19,7 +19,7 @@ describe('Keys permissions 2', () => { }); it('keys.delete', () => { - visitProjectWithPermissions({ scopes: ['keys.delete'] }).then( + visitProjectWithPermissions({ scopes: ['keys.delete'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, @@ -31,7 +31,7 @@ describe('Keys permissions 2', () => { }); it('keys.create', () => { - visitProjectWithPermissions({ scopes: ['keys.create'] }).then( + visitProjectWithPermissions({ scopes: ['keys.create'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.1.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.1.cy.ts index bac2331bf0..dbfb96019c 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.1.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.1.cy.ts @@ -6,10 +6,13 @@ import { describe('Permissions per language 1', () => { it('translations.view', () => { - visitProjectWithPermissions({ - scopes: ['translations.view'], - viewLanguageTags: ['en', 'de'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.view'], + viewLanguageTags: ['en', 'de'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, @@ -20,10 +23,13 @@ describe('Permissions per language 1', () => { }); it('translations.edit', () => { - visitProjectWithPermissions({ - scopes: ['translations.edit'], - translateLanguageTags: ['de'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.edit'], + translateLanguageTags: ['de'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.2.cy.ts index 1e3d44129d..5ae588400b 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsPerLanguage.2.cy.ts @@ -6,10 +6,13 @@ import { describe('Permissions per language 2', () => { it('translations.state-edit', () => { - visitProjectWithPermissions({ - scopes: ['translations.view', 'translations.state-edit'], - stateChangeLanguageTags: ['de'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.view', 'translations.state-edit'], + stateChangeLanguageTags: ['de'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, @@ -20,11 +23,14 @@ describe('Permissions per language 2', () => { }); it('combined translations.edit and translations.state-edit', () => { - visitProjectWithPermissions({ - scopes: ['translations.edit', 'translations.state-edit'], - translateLanguageTags: ['cs'], - stateChangeLanguageTags: ['de'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translations.edit', 'translations.state-edit'], + translateLanguageTags: ['cs'], + stateChangeLanguageTags: ['de'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, 'project-menu-item-translations': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsServerAdmin.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsServerAdmin.2.cy.ts index 18ae5a2a6e..b9aff1cf36 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsServerAdmin.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsServerAdmin.2.cy.ts @@ -8,21 +8,23 @@ import { describe('Server admin 2', () => { it('Server admin', () => { - visitProjectWithPermissions({ scopes: ['admin'] }).then((projectInfo) => { - // login as admin - login('Server admin', 'admin'); - checkPermissions(projectInfo, { - 'project-menu-item-dashboard': SKIP, - 'project-menu-item-translations': RUN, - 'project-menu-item-tasks': SKIP, - 'project-menu-item-settings': SKIP, - 'project-menu-item-languages': SKIP, - 'project-menu-item-members': SKIP, - 'project-menu-item-import': SKIP, - 'project-menu-item-export': SKIP, - 'project-menu-item-developer': SKIP, - 'project-menu-item-integrate': SKIP, - }); - }); + visitProjectWithPermissions({ scopes: ['admin'] }, true).then( + (projectInfo) => { + // login as admin + login('Server admin', 'admin'); + checkPermissions(projectInfo, { + 'project-menu-item-dashboard': SKIP, + 'project-menu-item-translations': RUN, + 'project-menu-item-tasks': SKIP, + 'project-menu-item-settings': SKIP, + 'project-menu-item-languages': SKIP, + 'project-menu-item-members': SKIP, + 'project-menu-item-import': SKIP, + 'project-menu-item-export': SKIP, + 'project-menu-item-developer': SKIP, + 'project-menu-item-integrate': SKIP, + }); + } + ); }); }); diff --git a/e2e/cypress/e2e/projects/permissions/permissionsTask.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsTask.cy.ts index 9c1174a4c8..910481254e 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsTask.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsTask.cy.ts @@ -6,7 +6,7 @@ import { describe('Permissions task', () => { it('tasks.view', () => { - visitProjectWithPermissions({ scopes: ['tasks.view'] }).then( + visitProjectWithPermissions({ scopes: ['tasks.view'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, @@ -20,7 +20,7 @@ describe('Permissions task', () => { }); it('tasks.edit', () => { - visitProjectWithPermissions({ scopes: ['tasks.edit'] }).then( + visitProjectWithPermissions({ scopes: ['tasks.edit'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsTranslations.1.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsTranslations.1.cy.ts index 5c9b1a2ac4..08c2feb709 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsTranslations.1.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsTranslations.1.cy.ts @@ -6,7 +6,7 @@ import { describe('Permissions translations 1', () => { it('translations.view', () => { - visitProjectWithPermissions({ scopes: ['translations.view'] }).then( + visitProjectWithPermissions({ scopes: ['translations.view'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, @@ -19,7 +19,7 @@ describe('Permissions translations 1', () => { }); it('translations.edit', () => { - visitProjectWithPermissions({ scopes: ['translations.edit'] }).then( + visitProjectWithPermissions({ scopes: ['translations.edit'] }, true).then( (projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': RUN, diff --git a/e2e/cypress/e2e/projects/permissions/permissionsTranslations.2.cy.ts b/e2e/cypress/e2e/projects/permissions/permissionsTranslations.2.cy.ts index 9d8881ee37..fe55db2de4 100644 --- a/e2e/cypress/e2e/projects/permissions/permissionsTranslations.2.cy.ts +++ b/e2e/cypress/e2e/projects/permissions/permissionsTranslations.2.cy.ts @@ -7,46 +7,52 @@ import { describe('Permissions translations 2', () => { it('translations.state-edit', () => { - visitProjectWithPermissions({ scopes: ['translations.state-edit'] }).then( - (projectInfo) => { - checkPermissions(projectInfo, { - 'project-menu-item-dashboard': RUN, - 'project-menu-item-export': RUN, - }); - } - ); + visitProjectWithPermissions( + { scopes: ['translations.state-edit'] }, + true + ).then((projectInfo) => { + checkPermissions(projectInfo, { + 'project-menu-item-dashboard': RUN, + 'project-menu-item-export': RUN, + }); + }); }); it('translation-comments.add', () => { - visitProjectWithPermissions({ scopes: ['translation-comments.add'] }).then( - (projectInfo) => { - checkPermissions(projectInfo, { - 'project-menu-item-dashboard': SKIP, - 'project-menu-item-translations': RUN, - 'project-menu-item-export': SKIP, - 'project-menu-item-integrate': SKIP, - }); - } - ); + visitProjectWithPermissions( + { scopes: ['translation-comments.add'] }, + true + ).then((projectInfo) => { + checkPermissions(projectInfo, { + 'project-menu-item-dashboard': SKIP, + 'project-menu-item-translations': RUN, + 'project-menu-item-export': SKIP, + 'project-menu-item-integrate': SKIP, + }); + }); }); it('translation-comments.edit', () => { - visitProjectWithPermissions({ scopes: ['translation-comments.edit'] }).then( - (projectInfo) => { - checkPermissions(projectInfo, { - 'project-menu-item-dashboard': SKIP, - 'project-menu-item-translations': RUN, - 'project-menu-item-export': SKIP, - 'project-menu-item-integrate': SKIP, - }); - } - ); + visitProjectWithPermissions( + { scopes: ['translation-comments.edit'] }, + true + ).then((projectInfo) => { + checkPermissions(projectInfo, { + 'project-menu-item-dashboard': SKIP, + 'project-menu-item-translations': RUN, + 'project-menu-item-export': SKIP, + 'project-menu-item-integrate': SKIP, + }); + }); }); it('translation-comments.set-state', () => { - visitProjectWithPermissions({ - scopes: ['translation-comments.set-state'], - }).then((projectInfo) => { + visitProjectWithPermissions( + { + scopes: ['translation-comments.set-state'], + }, + true + ).then((projectInfo) => { checkPermissions(projectInfo, { 'project-menu-item-dashboard': SKIP, 'project-menu-item-translations': RUN, diff --git a/e2e/cypress/e2e/projects/projectMembers.cy.ts b/e2e/cypress/e2e/projects/projectMembers.cy.ts index 3e9ec54657..4eefa69e31 100644 --- a/e2e/cypress/e2e/projects/projectMembers.cy.ts +++ b/e2e/cypress/e2e/projects/projectMembers.cy.ts @@ -122,6 +122,7 @@ describe('Project members', () => { { scopes: ['activity.view'], }, + true, 'admin@admin.com' ).then((infoData) => { info = infoData;