fix(editor): Fix RBAC type errors (no-changelog) (#9435)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { useUsersStore } from '@/stores/users.store';
|
import { useUsersStore } from '@/stores/users.store';
|
||||||
import { isAuthenticated } from '@/rbac/checks/isAuthenticated';
|
import { isAuthenticated } from '@/rbac/checks/isAuthenticated';
|
||||||
|
import type { IUser } from '@/Interface';
|
||||||
|
|
||||||
vi.mock('@/stores/users.store', () => ({
|
vi.mock('@/stores/users.store', () => ({
|
||||||
useUsersStore: vi.fn(),
|
useUsersStore: vi.fn(),
|
||||||
@@ -7,7 +8,7 @@ vi.mock('@/stores/users.store', () => ({
|
|||||||
|
|
||||||
describe('Checks', () => {
|
describe('Checks', () => {
|
||||||
describe('isAuthenticated()', () => {
|
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', () => {
|
it('should return true if there is a current user', () => {
|
||||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as unknown as ReturnType<
|
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as unknown as ReturnType<
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { isAuthenticated } from '@/rbac/checks';
|
|||||||
|
|
||||||
export const authenticatedMiddleware: RouterMiddleware<AuthenticatedPermissionOptions> = async (
|
export const authenticatedMiddleware: RouterMiddleware<AuthenticatedPermissionOptions> = async (
|
||||||
to,
|
to,
|
||||||
from,
|
_from,
|
||||||
next,
|
next,
|
||||||
options,
|
options,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import type { DefaultUserMiddlewareOptions } from '@/types/rbac';
|
|||||||
import { isDefaultUser } from '@/rbac/checks';
|
import { isDefaultUser } from '@/rbac/checks';
|
||||||
|
|
||||||
export const defaultUserMiddleware: RouterMiddleware<DefaultUserMiddlewareOptions> = async (
|
export const defaultUserMiddleware: RouterMiddleware<DefaultUserMiddlewareOptions> = async (
|
||||||
to,
|
_to,
|
||||||
from,
|
_from,
|
||||||
next,
|
next,
|
||||||
) => {
|
) => {
|
||||||
const valid = isDefaultUser();
|
const valid = isDefaultUser();
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import type { EnterprisePermissionOptions } from '@/types/rbac';
|
|||||||
import { isEnterpriseFeatureEnabled } from '@/rbac/checks';
|
import { isEnterpriseFeatureEnabled } from '@/rbac/checks';
|
||||||
|
|
||||||
export const enterpriseMiddleware: RouterMiddleware<EnterprisePermissionOptions> = async (
|
export const enterpriseMiddleware: RouterMiddleware<EnterprisePermissionOptions> = async (
|
||||||
to,
|
_to,
|
||||||
from,
|
_from,
|
||||||
next,
|
next,
|
||||||
options,
|
options,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import { VIEWS } from '@/constants';
|
|||||||
import type { GuestPermissionOptions } from '@/types/rbac';
|
import type { GuestPermissionOptions } from '@/types/rbac';
|
||||||
import { isGuest } from '@/rbac/checks';
|
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();
|
const valid = isGuest();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
const redirect = to.query.redirect as string;
|
const redirect = to.query.redirect as string;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { hasScope } from '@/rbac/checks';
|
|||||||
|
|
||||||
export const rbacMiddleware: RouterMiddleware<RBACPermissionOptions> = async (
|
export const rbacMiddleware: RouterMiddleware<RBACPermissionOptions> = async (
|
||||||
to,
|
to,
|
||||||
from,
|
_from,
|
||||||
next,
|
next,
|
||||||
{ scope, options },
|
{ scope, options },
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { VIEWS } from '@/constants';
|
|||||||
import { hasRole } from '@/rbac/checks';
|
import { hasRole } from '@/rbac/checks';
|
||||||
|
|
||||||
export const roleMiddleware: RouterMiddleware<RolePermissionOptions> = async (
|
export const roleMiddleware: RouterMiddleware<RolePermissionOptions> = async (
|
||||||
to,
|
_to,
|
||||||
from,
|
_from,
|
||||||
next,
|
next,
|
||||||
checkRoles,
|
checkRoles,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import type {
|
|||||||
DefaultUserMiddlewareOptions,
|
DefaultUserMiddlewareOptions,
|
||||||
} from '@/types/rbac';
|
} from '@/types/rbac';
|
||||||
|
|
||||||
export type RouterMiddlewareType = PermissionType;
|
export type RouterMiddlewareType = Exclude<PermissionType, 'instanceOwner'>;
|
||||||
export type CustomMiddlewareOptions = CustomPermissionOptions<{
|
export type CustomMiddlewareOptions = CustomPermissionOptions<{
|
||||||
to: RouteLocationNormalized;
|
to: RouteLocationNormalized;
|
||||||
from: RouteLocationNormalized;
|
from: RouteLocationNormalized;
|
||||||
|
|||||||
Reference in New Issue
Block a user