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

This commit is contained in:
Alex Grozav
2024-05-17 13:29:47 +03:00
committed by GitHub
parent 48588194b9
commit 6aec42069c
8 changed files with 16 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
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(),
@@ -7,7 +8,7 @@ vi.mock('@/stores/users.store', () => ({
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<

View File

@@ -5,7 +5,7 @@ import { isAuthenticated } from '@/rbac/checks';
export const authenticatedMiddleware: RouterMiddleware<AuthenticatedPermissionOptions> = async (
to,
from,
_from,
next,
options,
) => {

View File

@@ -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();

View File

@@ -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,
) => {

View File

@@ -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;

View File

@@ -10,7 +10,7 @@ import { hasScope } from '@/rbac/checks';
export const rbacMiddleware: RouterMiddleware<RBACPermissionOptions> = async (
to,
from,
_from,
next,
{ scope, options },
) => {

View File

@@ -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,
) => {

View File

@@ -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;