Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Fix RBAC type errors (no-changelog) #9435

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading