Skip to content

Commit

Permalink
E2E: Batch operation permission testing needs namespaces enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
StaNov committed Dec 17, 2024
1 parent 2395ced commit 7c84bf5
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PermissionsTestData {
translateLanguageTags: List<String>? = null,
stateChangeLanguageTags: List<String>? = null,
organizationBaseScopes: List<Scope>? = null,
useNamespaces: Boolean = false,
): UserAccount {
val me =
root.addUserAccount {
Expand All @@ -114,6 +115,8 @@ class PermissionsTestData {
}
}

projectBuilder.self.useNamespaces = useNamespaces

if (organizationBaseScopes != null) {
organizationBuilder.self.basePermission.type = null
organizationBuilder.self.basePermission.scopes = organizationBaseScopes.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PermissionsE2eDataController() : AbstractE2eDataController() {
@RequestParam viewLanguageTags: List<String>?,
@RequestParam translateLanguageTags: List<String>?,
@RequestParam stateChangeLanguageTags: List<String>?,
@RequestParam useNamespaces: Boolean = false,
): StandardTestDataResult {
val user =
this.permissionsTestData.addUserWithPermissions(
Expand All @@ -36,6 +37,7 @@ class PermissionsE2eDataController() : AbstractE2eDataController() {
viewLanguageTags = viewLanguageTags,
translateLanguageTags = translateLanguageTags,
stateChangeLanguageTags = stateChangeLanguageTags,
useNamespaces = useNamespaces,
)
this.permissionsTestData.addTasks(
mutableSetOf(user, permissionsTestData.serverAdmin.self),
Expand Down
3 changes: 2 additions & 1 deletion e2e/cypress/common/apiCalls/testData/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ export type PermissionsOptions = {
};

export const generatePermissionsData = {
generate: (options: Partial<PermissionsOptions>) => {
generate: (options: Partial<PermissionsOptions>, 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()}`
);
Expand Down
3 changes: 2 additions & 1 deletion e2e/cypress/common/permissions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ export function loginAndGetInfo(user: UserMail, projectId: number) {

export function visitProjectWithPermissions(
options: Partial<PermissionsOptions>,
useNamespaces = false,
user: UserMail = '[email protected]'
): Promise<ProjectInfo> {
return new Cypress.Promise<ProjectInfo>((resolve) => {
generatePermissionsData
.clean()
.then(() => generatePermissionsData.generate(options))
.then(() => generatePermissionsData.generate(options, useNamespaces))
.then((res) => {
return res.body.projects[0].id;
})
Expand Down
30 changes: 16 additions & 14 deletions e2e/cypress/e2e/projects/permissions/permissionsAdmin.2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions e2e/cypress/e2e/projects/permissions/permissionsKeys.1.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions e2e/cypress/e2e/projects/permissions/permissionsKeys.2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 18 additions & 16 deletions e2e/cypress/e2e/projects/permissions/permissionsServerAdmin.2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
);
});
});
4 changes: 2 additions & 2 deletions e2e/cypress/e2e/projects/permissions/permissionsTask.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 7c84bf5

Please sign in to comment.