mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* Generate default_roles_permissions.js from a live server snapshot Replace the hand-maintained default_roles_permissions.js with a generated file. The generator (scripts/default_permissions_generator/) boots a real app.NewServer() against a temporary database created by storetest.MakeSqlSettings, lets all schema and app-level migrations run naturally, then snapshots the resulting Roles table into the JS file. This eliminates the drift risk of the previous hand-maintained map: new migrations are picked up automatically because the same server initialization path is used here as in production. The CI job gets a postgres service and sets IS_CI=true so the generator uses the same host-switching logic as the rest of the test suite. Locally, make start-docker provides the postgres instance. * Address CodeRabbit feedback: pin checkout SHA, add permissions, add .PHONY entries
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import xor from 'lodash.xor';
|
|
|
|
import {defaultRolesPermissions} from './default_roles_permissions';
|
|
|
|
// *****************************************************************************
|
|
// Preferences
|
|
// https://api.mattermost.com/#tag/roles
|
|
// *****************************************************************************
|
|
|
|
export {defaultRolesPermissions};
|
|
|
|
Cypress.Commands.add('getRoleByName', (name) => {
|
|
return cy.request({
|
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
url: `/api/v4/roles/name/${name}`,
|
|
method: 'GET',
|
|
}).then((response) => {
|
|
expect(response.status).to.equal(200);
|
|
return cy.wrap({name: response.body});
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('apiGetRolesByNames', (names) => {
|
|
return cy.request({
|
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
url: '/api/v4/roles/names',
|
|
method: 'POST',
|
|
body: names || Object.keys(defaultRolesPermissions),
|
|
}).then((response) => {
|
|
expect(response.status).to.equal(200);
|
|
return cy.wrap({roles: response.body});
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('apiPatchRole', (roleID, patch) => {
|
|
return cy.request({
|
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
url: `/api/v4/roles/${roleID}/patch`,
|
|
method: 'PUT',
|
|
body: patch,
|
|
}).then((response) => {
|
|
expect(response.status).to.equal(200);
|
|
return cy.wrap({role: response.body});
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('apiResetRoles', () => {
|
|
cy.apiGetRolesByNames().then(({roles}) => {
|
|
roles.forEach((role) => {
|
|
const permissions = getPermissions(role.name);
|
|
const diff = xor(role.permissions, permissions)?.filter((p) => p?.length);
|
|
|
|
if (diff?.length > 0) {
|
|
cy.apiPatchRole(role.id, {permissions});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function getPermissions(roleName) {
|
|
const permissions = defaultRolesPermissions[roleName];
|
|
if (!permissions) {
|
|
return [];
|
|
}
|
|
return permissions.split(' ').map((permission) => permission.trim()).filter((permission) => permission !== '');
|
|
}
|