feat: Introduce advanced permissions (#7844)

This PR introduces the possibility of inviting new users with an `admin`
role and changing the role of already invited users.
Also using scoped permission checks where applicable instead of using
user role checks.

---------

Co-authored-by: Val <68596159+valya@users.noreply.github.com>
Co-authored-by: Alex Grozav <alex@grozav.com>
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Csaba Tuncsik
2023-12-08 12:52:25 +01:00
committed by GitHub
parent e00577b1d3
commit dbd62a4992
26 changed files with 364 additions and 71 deletions

View File

@@ -4,6 +4,9 @@ import router from '@/router';
import { VIEWS } from '@/constants';
import { setupServer } from '@/__tests__/server';
import { useSettingsStore } from '@/stores/settings.store';
import { useRBACStore } from '@/stores/rbac.store';
import type { Scope } from '@n8n/permissions';
import type { RouteRecordName } from 'vue-router';
const App = {
template: '<div />',
@@ -64,7 +67,7 @@ describe('router', () => {
'should resolve %s to %s if user has permissions',
async (path, name) => {
const settingsStore = useSettingsStore();
await settingsStore.getSettings();
settingsStore.settings.enterprise.debugInEditor = true;
settingsStore.settings.enterprise.workflowHistory = true;
@@ -73,4 +76,42 @@ describe('router', () => {
},
10000,
);
test.each<[string, RouteRecordName, Scope[]]>([
['/settings/users', VIEWS.WORKFLOWS, []],
['/settings/users', VIEWS.USERS_SETTINGS, ['user:create', 'user:update']],
['/settings/environments', VIEWS.WORKFLOWS, []],
['/settings/environments', VIEWS.SOURCE_CONTROL, ['sourceControl:manage']],
['/settings/external-secrets', VIEWS.WORKFLOWS, []],
[
'/settings/external-secrets',
VIEWS.EXTERNAL_SECRETS_SETTINGS,
['externalSecretsProvider:list', 'externalSecretsProvider:update'],
],
['/settings/sso', VIEWS.WORKFLOWS, []],
['/settings/sso', VIEWS.SSO_SETTINGS, ['saml:manage']],
['/settings/log-streaming', VIEWS.WORKFLOWS, []],
['/settings/log-streaming', VIEWS.LOG_STREAMING_SETTINGS, ['logStreaming:manage']],
['/settings/community-nodes', VIEWS.WORKFLOWS, []],
[
'/settings/community-nodes',
VIEWS.COMMUNITY_NODES,
['communityPackage:list', 'communityPackage:update'],
],
['/settings/ldap', VIEWS.WORKFLOWS, []],
['/settings/ldap', VIEWS.LDAP_SETTINGS, ['ldap:manage']],
])(
'should resolve %s to %s with %s user permissions',
async (path, name, scopes) => {
const settingsStore = useSettingsStore();
const rbacStore = useRBACStore();
settingsStore.settings.communityNodesEnabled = true;
rbacStore.setGlobalScopes(scopes);
await router.push(path);
expect(router.currentRoute.value.name).toBe(name);
},
10000,
);
});