feat(editor): Replace middleware for Role checks with Scope checks (#7847)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useRBACStore } from '@/stores/rbac.store';
|
||||
import { hasScope } from '@/rbac/checks/hasScope';
|
||||
import type { HasScopeOptions } from '@n8n/permissions';
|
||||
import type { ScopeOptions } from '@n8n/permissions';
|
||||
|
||||
vi.mock('@/stores/rbac.store', () => ({
|
||||
useRBACStore: vi.fn(),
|
||||
@@ -19,7 +19,7 @@ describe('Checks', () => {
|
||||
} as unknown as ReturnType<typeof useRBACStore>);
|
||||
|
||||
const scope = 'workflow:read';
|
||||
const options: HasScopeOptions = { mode: 'allOf' };
|
||||
const options: ScopeOptions = { mode: 'allOf' };
|
||||
const projectId = 'proj123';
|
||||
const resourceType = 'workflow';
|
||||
const resourceId = 'res123';
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import { isDefaultUser } from '@/rbac/checks/isDefaultUser';
|
||||
|
||||
vi.mock('@/stores/users.store', () => ({
|
||||
useUsersStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Checks', () => {
|
||||
describe('isDefaultUser()', () => {
|
||||
it('should return false if user not logged in', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: null } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isDefaultUser()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if user is default user', () => {
|
||||
const mockUser = { id: 'user123', name: 'Test User', isDefaultUser: true };
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as unknown as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isDefaultUser()).toBe(mockUser.isDefaultUser);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from './hasRole';
|
||||
export * from './hasScope';
|
||||
export * from './isAuthenticated';
|
||||
export * from './isDefaultUser';
|
||||
export * from './isEnterpriseFeatureEnabled';
|
||||
export * from './isGuest';
|
||||
export * from './isValid';
|
||||
|
||||
12
packages/editor-ui/src/rbac/checks/isDefaultUser.ts
Normal file
12
packages/editor-ui/src/rbac/checks/isDefaultUser.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import type { DefaultUserMiddlewareOptions, RBACPermissionCheck } from '@/types/rbac';
|
||||
|
||||
export const isDefaultUser: RBACPermissionCheck<DefaultUserMiddlewareOptions> = () => {
|
||||
const usersStore = useUsersStore();
|
||||
const currentUser = usersStore.currentUser;
|
||||
|
||||
if (currentUser) {
|
||||
return currentUser.isDefaultUser;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user