-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
392 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { ComputedUserRole } from './roles' | ||
import { type UserFull, UserRole, type UserSecrets } from '~/def/user' | ||
|
||
// TODO server validation impl same logic | ||
export function isRoleEditable(stat: Record<'admin' | 'owner' | 'staff', boolean>, role: UserRole) { | ||
switch (role) { | ||
case UserRole.Admin: { | ||
return stat.owner | ||
} | ||
case UserRole.Staff: { | ||
return stat.admin || stat.owner | ||
} | ||
case UserRole.Owner: { | ||
return stat.owner | ||
} | ||
case UserRole.Moderator: | ||
return stat.admin || stat.owner | ||
default: | ||
return true | ||
} | ||
} | ||
|
||
export function isUserFieldEditable(field: keyof (UserFull<any> & UserSecrets), computedRole: ComputedUserRole) { | ||
switch (field) { | ||
case 'profile': | ||
case 'preferredMode': | ||
case 'roles': | ||
return computedRole.staff || computedRole.admin || computedRole.owner | ||
default: | ||
return computedRole.admin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useSession } from '~/store/session' | ||
|
||
export default defineNuxtRouteMiddleware(() => { | ||
const { $state } = useSession() | ||
if (!$state.role.staff) { | ||
return navigateTo({ | ||
name: 'article-id', | ||
params: { | ||
id: ['403'], | ||
}, | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.