refactor(auth): remove Guest role from user type system
Remove all references to 'Guest' user type from the codebase, simplifying the role system to only support 'Admin' and 'User' roles. Changes: - Update type definitions to exclude 'Guest' from UserType - Remove isGuest() method from SessionManager - Remove Guest-specific logic from update services - Update all type assertions from 'Admin | User | Guest' to 'Admin | User' - Remove Guest UI styling from UserSelectionDialog - Replace Guest fallback with ValidationError in settings handler Error handling: - Zod schema now rejects 'Guest' as invalid user type - TypeScript will fail compilation if 'Guest' is referenced - Runtime errors occur if database contains Guest users No database migration needed (confirmed: no Guest users exist) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,13 @@ export function registerSettingsHandlers(): void {
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.SETTINGS_GET_USER_TYPE, async (): Promise<IpcResult<UserType>> => {
|
||||
return withErrorHandling(
|
||||
async () => (sessionManager.getUserType() as UserType) || 'Guest',
|
||||
async () => {
|
||||
const userType = sessionManager.getUserType()
|
||||
if (!userType) {
|
||||
throw new ValidationError('未找到用户类型', 'VAL_INVALID_INPUT')
|
||||
}
|
||||
return userType as UserType
|
||||
},
|
||||
'settings:getUserType'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ export type LoginRequestZod = z.infer<typeof LoginRequestSchema>
|
||||
export const UserInfoSchema = z.object({
|
||||
id: z.number().int().positive(),
|
||||
username: z.string().min(1),
|
||||
userType: z.enum(['Admin', 'User', 'Guest']),
|
||||
userType: z.enum(['Admin', 'User']),
|
||||
computerName: z.string().optional()
|
||||
})
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export class UpdateCatalogService {
|
||||
|
||||
public getDialogCatalog(status: UpdateStatus, catalog: UpdateCatalog): UpdateDialogCatalog {
|
||||
const currentUserType = status.currentUserType
|
||||
if (!status.enabled || !currentUserType || currentUserType === 'Guest') {
|
||||
if (!status.enabled || !currentUserType) {
|
||||
return { mode: 'disabled' }
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ export class UpdateService {
|
||||
this.ensureInitialized()
|
||||
this.status.currentUserType = userType
|
||||
|
||||
if (!this.status.enabled || !userType || userType === 'Guest') {
|
||||
if (!this.status.enabled || !userType) {
|
||||
this.clearPolling()
|
||||
this.catalog = { stable: [], preview: [] }
|
||||
this.publishStatus({
|
||||
|
||||
@@ -139,7 +139,7 @@ export class BIPUsersDAO {
|
||||
return {
|
||||
id: row.ID as number,
|
||||
username: row.UserName as string,
|
||||
userType: row.UserType as 'Admin' | 'User' | 'Guest'
|
||||
userType: row.UserType as 'Admin' | 'User'
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -157,7 +157,7 @@ export class BIPUsersDAO {
|
||||
return {
|
||||
id: row.ID as number,
|
||||
username: row.UserName as string,
|
||||
userType: row.UserType as 'Admin' | 'User' | 'Guest'
|
||||
userType: row.UserType as 'Admin' | 'User'
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -198,7 +198,7 @@ export class BIPUsersDAO {
|
||||
return {
|
||||
id: row.ID as number,
|
||||
username: row.UserName as string,
|
||||
userType: row.UserType as 'Admin' | 'User' | 'Guest'
|
||||
userType: row.UserType as 'Admin' | 'User'
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -216,7 +216,7 @@ export class BIPUsersDAO {
|
||||
return {
|
||||
id: row.ID as number,
|
||||
username: row.UserName as string,
|
||||
userType: row.UserType as 'Admin' | 'User' | 'Guest'
|
||||
userType: row.UserType as 'Admin' | 'User'
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -254,7 +254,7 @@ export class BIPUsersDAO {
|
||||
return result.rows.map((row) => ({
|
||||
id: row.ID as number,
|
||||
username: row.UserName as string,
|
||||
userType: row.UserType as 'Admin' | 'User' | 'Guest',
|
||||
userType: row.UserType as 'Admin' | 'User',
|
||||
createTime: row.CreateTime as Date | undefined
|
||||
}))
|
||||
} catch (error) {
|
||||
@@ -270,7 +270,7 @@ export class BIPUsersDAO {
|
||||
* Create a new user
|
||||
* @param username - The username (must be unique)
|
||||
* @param password - The password
|
||||
* @param userType - User type ('Admin', 'User', or 'Guest')
|
||||
* @param userType - User type ('Admin' or 'User')
|
||||
* @param computerName - Optional computer name for silent login
|
||||
* @returns True if successful
|
||||
*/
|
||||
|
||||
@@ -126,13 +126,6 @@ export class SessionManager {
|
||||
return this.currentUser?.userType === 'Admin'
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user is a guest
|
||||
*/
|
||||
public isGuest(): boolean {
|
||||
return this.currentUser?.userType === 'Guest'
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current username
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/**
|
||||
* User type for settings permission control
|
||||
*/
|
||||
export type UserType = 'Admin' | 'User' | 'Guest'
|
||||
export type UserType = 'Admin' | 'User'
|
||||
|
||||
/**
|
||||
* Database type selection
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/**
|
||||
* User type enumeration
|
||||
*/
|
||||
export type UserType = 'Admin' | 'User' | 'Guest'
|
||||
export type UserType = 'Admin' | 'User'
|
||||
|
||||
/**
|
||||
* User information interface
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Modal } from './ui/Modal'
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
username: string
|
||||
userType: 'Admin' | 'User' | 'Guest'
|
||||
userType: 'Admin' | 'User'
|
||||
createTime?: Date
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ export const UserSelectionDialog: React.FC<UserSelectionDialogProps> = ({
|
||||
|
||||
const userTypeStyles: Record<string, string> = {
|
||||
Admin: 'bg-amber-50 text-amber-600',
|
||||
User: 'bg-blue-50 text-blue-600',
|
||||
Guest: 'bg-gray-100 text-gray-600'
|
||||
User: 'bg-blue-50 text-blue-600'
|
||||
}
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
@@ -4,7 +4,7 @@ import UserSelectionDialog, { type UserInfo as SelectedUserInfo } from '../UserS
|
||||
|
||||
interface CurrentUser {
|
||||
username: string
|
||||
userType: 'Admin' | 'User' | 'Guest'
|
||||
userType: 'Admin' | 'User'
|
||||
}
|
||||
|
||||
interface UnauthenticatedAppProps {
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface CurrentUser {
|
||||
export interface SelectedUserInfo {
|
||||
id: number
|
||||
username: string
|
||||
userType: 'Admin' | 'User' | 'Guest'
|
||||
userType: 'Admin' | 'User'
|
||||
computerName?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useState, useCallback } from 'react'
|
||||
interface UserInfo {
|
||||
id: number
|
||||
username: string
|
||||
userType: 'Admin' | 'User' | 'Guest'
|
||||
userType: 'Admin' | 'User'
|
||||
computerName?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { create } from 'zustand'
|
||||
interface UserInfo {
|
||||
id: number
|
||||
username: string
|
||||
userType: 'Admin' | 'User' | 'Guest'
|
||||
userType: 'Admin' | 'User'
|
||||
computerName?: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user