feat: roles SPA Users, Profile, API keys, Activity
This commit is contained in:
1 parent
3db490a615
commit
34dffe222f
98 files changed
+4957
-434
No files matched your search
@@ -1,27 +1,9 @@
|
||||
import { useApi } from '@/composables/useApi'
|
||||
import type { LinkableUser } from '@/lib/directoryTypes'
|
||||
import type { RoleRef } from '@/lib/permissions'
|
||||
import type { AcceptedUser, CreatedInvite, OwnershipTransfer, UserListItem } from '@/lib/users'
|
||||
|
||||
export type UserListItem =
|
||||
| {
|
||||
kind: 'user'
|
||||
id: number
|
||||
username: string
|
||||
display_name: string
|
||||
email: string
|
||||
role: RoleRef | null
|
||||
status: 'accepted'
|
||||
created_at: string
|
||||
}
|
||||
| {
|
||||
kind: 'invite'
|
||||
id: number
|
||||
email: string
|
||||
display_name?: string
|
||||
role?: RoleRef | null
|
||||
status: 'pending' | 'expired'
|
||||
created_at: string
|
||||
}
|
||||
export type { AcceptedUser, CreatedInvite, OwnershipTransfer, UserListItem }
|
||||
|
||||
export const USER_SKELETON_ROWS = 5
|
||||
|
||||
@@ -30,22 +12,14 @@ export function userRowKey(kind: UserListItem['kind'], id: number) {
|
||||
}
|
||||
|
||||
export function userDisplayName(item: UserListItem) {
|
||||
return item.display_name ?? ''
|
||||
return item.kind === 'user' ? item.display_name : ''
|
||||
}
|
||||
|
||||
export function userRole(item: UserListItem): RoleRef | null {
|
||||
return item.role ?? null
|
||||
}
|
||||
|
||||
export interface CreatedInvite {
|
||||
id: number
|
||||
kind: 'invite'
|
||||
email: string
|
||||
role?: RoleRef | null
|
||||
status: 'pending'
|
||||
created_at: string
|
||||
expires_at: string
|
||||
}
|
||||
const JSON_HEADERS = { 'Content-Type': 'application/json' }
|
||||
|
||||
export function useUsers() {
|
||||
const { request } = useApi()
|
||||
@@ -71,11 +45,27 @@ export function useUsers() {
|
||||
)
|
||||
}
|
||||
|
||||
function inviteUser(email: string): Promise<CreatedInvite> {
|
||||
function inviteUser(email: string, roleId?: number): Promise<CreatedInvite> {
|
||||
return request<CreatedInvite>('/v1/user/invite', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email }),
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify(roleId === undefined ? { email } : { email, role_id: roleId }),
|
||||
})
|
||||
}
|
||||
|
||||
function changeUserRole(id: number, roleId: number): Promise<AcceptedUser> {
|
||||
return request<AcceptedUser>(`/v1/user/${id}/role`, {
|
||||
method: 'PUT',
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify({ role_id: roleId }),
|
||||
})
|
||||
}
|
||||
|
||||
function transferOwnership(userId: number, confirmEmail: string): Promise<OwnershipTransfer> {
|
||||
return request<OwnershipTransfer>('/v1/site/transfer-ownership', {
|
||||
method: 'POST',
|
||||
headers: JSON_HEADERS,
|
||||
body: JSON.stringify({ user_id: userId, confirm_email: confirmEmail }),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,6 +83,8 @@ export function useUsers() {
|
||||
listUsers,
|
||||
listLinkableUsers,
|
||||
inviteUser,
|
||||
changeUserRole,
|
||||
transferOwnership,
|
||||
cancelInvite,
|
||||
renewInvite,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user