Skip to content

Commit

Permalink
fix(editor): Fix RBAC type errors (no-changelog) (#9435)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgrozav authored May 17, 2024
1 parent 4858819 commit 6aec420
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useUsersStore } from '@/stores/users.store';
import { isAuthenticated } from '@/rbac/checks/isAuthenticated';
import type { IUser } from '@/Interface';

vi.mock('@/stores/users.store', () => ({
useUsersStore: vi.fn(),
}));

describe('Checks', () => {
describe('isAuthenticated()', () => {
const mockUser = { id: 'user123', name: 'Test User' };
const mockUser: Partial<IUser> = { id: 'user123', fullName: 'Test User' };

it('should return true if there is a current user', () => {
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as unknown as ReturnType<
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/rbac/middleware/authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isAuthenticated } from '@/rbac/checks';

export const authenticatedMiddleware: RouterMiddleware<AuthenticatedPermissionOptions> = async (
to,
from,
_from,
next,
options,
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/rbac/middleware/defaultUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { DefaultUserMiddlewareOptions } from '@/types/rbac';
import { isDefaultUser } from '@/rbac/checks';

export const defaultUserMiddleware: RouterMiddleware<DefaultUserMiddlewareOptions> = async (
to,
from,
_to,
_from,
next,
) => {
const valid = isDefaultUser();
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/rbac/middleware/enterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { EnterprisePermissionOptions } from '@/types/rbac';
import { isEnterpriseFeatureEnabled } from '@/rbac/checks';

export const enterpriseMiddleware: RouterMiddleware<EnterprisePermissionOptions> = async (
to,
from,
_to,
_from,
next,
options,
) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/editor-ui/src/rbac/middleware/guest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { VIEWS } from '@/constants';
import type { GuestPermissionOptions } from '@/types/rbac';
import { isGuest } from '@/rbac/checks';

export const guestMiddleware: RouterMiddleware<GuestPermissionOptions> = async (to, from, next) => {
export const guestMiddleware: RouterMiddleware<GuestPermissionOptions> = async (
to,
_from,
next,
) => {
const valid = isGuest();
if (!valid) {
const redirect = to.query.redirect as string;
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/rbac/middleware/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { hasScope } from '@/rbac/checks';

export const rbacMiddleware: RouterMiddleware<RBACPermissionOptions> = async (
to,
from,
_from,
next,
{ scope, options },
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor-ui/src/rbac/middleware/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { VIEWS } from '@/constants';
import { hasRole } from '@/rbac/checks';

export const roleMiddleware: RouterMiddleware<RolePermissionOptions> = async (
to,
from,
_to,
_from,
next,
checkRoles,
) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/types/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
DefaultUserMiddlewareOptions,
} from '@/types/rbac';

export type RouterMiddlewareType = PermissionType;
export type RouterMiddlewareType = Exclude<PermissionType, 'instanceOwner'>;
export type CustomMiddlewareOptions = CustomPermissionOptions<{
to: RouteLocationNormalized;
from: RouteLocationNormalized;
Expand Down

0 comments on commit 6aec420

Please sign in to comment.