feat: мультироль
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 2m6s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 26s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
This commit is contained in:
@@ -25,14 +25,20 @@ const columns = [
|
||||
|
||||
const roleLabels = { Student: 'Студент', Teacher: 'Преподаватель', Admin: 'Администратор' } as const
|
||||
const roleApi = { Студент: 'Student', Преподаватель: 'Teacher', Администратор: 'Admin' } as const
|
||||
type ApiUserRole = 'Student' | 'Teacher' | 'Admin'
|
||||
const roleSetSequence: ApiUserRole[][] = [
|
||||
['Student'],
|
||||
['Student', 'Teacher'],
|
||||
['Student', 'Teacher', 'Admin'],
|
||||
]
|
||||
|
||||
const rows = computed(() =>
|
||||
users.value.map(user => ({
|
||||
id: user.id,
|
||||
name: user.displayName || user.email,
|
||||
email: user.email,
|
||||
role: roleLabels[user.role],
|
||||
apiRole: user.role,
|
||||
role: user.roles.map(role => roleLabels[role]).join(', '),
|
||||
apiRoles: user.roles,
|
||||
institute: 'ЮФУ',
|
||||
activity: user.isActive ? 'Активен' : 'Заблокирован',
|
||||
isActive: user.isActive,
|
||||
@@ -56,14 +62,24 @@ async function fetchUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleActive(row: Record<string, any>) {
|
||||
await usersApi.setActive(row.id, !row.isActive)
|
||||
async function toggleActive(row: Record<string, unknown>) {
|
||||
const id = Number(row.id)
|
||||
const isActive = Boolean(row.isActive)
|
||||
await usersApi.setActive(id, !isActive)
|
||||
await fetchUsers()
|
||||
}
|
||||
|
||||
async function promoteRole(row: Record<string, any>) {
|
||||
const next = row.apiRole === 'Student' ? 'Teacher' : row.apiRole === 'Teacher' ? 'Admin' : 'Student'
|
||||
await usersApi.setRole(row.id, next)
|
||||
async function promoteRole(row: Record<string, unknown>) {
|
||||
const id = Number(row.id)
|
||||
const apiRoles = (Array.isArray(row.apiRoles) ? row.apiRoles : []) as ApiUserRole[]
|
||||
const currentKey = [...new Set(apiRoles)].sort().join(',')
|
||||
const currentIndex = roleSetSequence.findIndex(set => set.slice().sort().join(',') === currentKey)
|
||||
const next: ApiUserRole[] = (
|
||||
currentIndex >= 0
|
||||
? roleSetSequence[(currentIndex + 1) % roleSetSequence.length]
|
||||
: roleSetSequence[0]
|
||||
) ?? ['Student']
|
||||
await usersApi.setRole(id, next)
|
||||
await fetchUsers()
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ onMounted(async () => {
|
||||
else throw new Error('Microsoft не вернул токен авторизации.')
|
||||
|
||||
window.history.replaceState({}, document.title, window.location.pathname)
|
||||
const role = auth.user?.role
|
||||
const role = auth.user?.activeRole
|
||||
if (role === 'teacher') await router.replace('/teacher')
|
||||
else if (role === 'admin') await router.replace('/admin')
|
||||
else await router.replace('/')
|
||||
|
||||
Reference in New Issue
Block a user