fix(editor): Replace isInstanceOwner checks with scopes where applicable (#7858)
Co-authored-by: Alex Grozav <alex@grozav.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import { isInstanceOwner } from '@/rbac/checks/isInstanceOwner';
|
||||
|
||||
vi.mock('@/stores/users.store', () => ({
|
||||
useUsersStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Checks', () => {
|
||||
describe('isInstanceOwner()', () => {
|
||||
it('should return false if user not logged in', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ isInstanceOwner: false } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isInstanceOwner()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if user is default user', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ isInstanceOwner: true } as unknown as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isInstanceOwner()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ export * from './hasRole';
|
||||
export * from './hasScope';
|
||||
export * from './isAuthenticated';
|
||||
export * from './isDefaultUser';
|
||||
export * from './isInstanceOwner';
|
||||
export * from './isEnterpriseFeatureEnabled';
|
||||
export * from './isGuest';
|
||||
export * from './isValid';
|
||||
|
||||
5
packages/editor-ui/src/rbac/checks/isInstanceOwner.ts
Normal file
5
packages/editor-ui/src/rbac/checks/isInstanceOwner.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import type { DefaultUserMiddlewareOptions, RBACPermissionCheck } from '@/types/rbac';
|
||||
|
||||
export const isInstanceOwner: RBACPermissionCheck<DefaultUserMiddlewareOptions> = () =>
|
||||
useUsersStore().isInstanceOwner;
|
||||
Reference in New Issue
Block a user