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:
Misaka_Company
2026-03-26 12:50:18 +08:00
parent 6b2a3b088f
commit 491f2afe3f
13 changed files with 24 additions and 26 deletions

View File

@@ -28,7 +28,13 @@ export function registerSettingsHandlers(): void {
ipcMain.handle(IPC_CHANNELS.SETTINGS_GET_USER_TYPE, async (): Promise<IpcResult<UserType>> => { ipcMain.handle(IPC_CHANNELS.SETTINGS_GET_USER_TYPE, async (): Promise<IpcResult<UserType>> => {
return withErrorHandling( 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' 'settings:getUserType'
) )
}) })

View File

@@ -20,7 +20,7 @@ export type LoginRequestZod = z.infer<typeof LoginRequestSchema>
export const UserInfoSchema = z.object({ export const UserInfoSchema = z.object({
id: z.number().int().positive(), id: z.number().int().positive(),
username: z.string().min(1), username: z.string().min(1),
userType: z.enum(['Admin', 'User', 'Guest']), userType: z.enum(['Admin', 'User']),
computerName: z.string().optional() computerName: z.string().optional()
}) })

View File

@@ -29,7 +29,7 @@ export class UpdateCatalogService {
public getDialogCatalog(status: UpdateStatus, catalog: UpdateCatalog): UpdateDialogCatalog { public getDialogCatalog(status: UpdateStatus, catalog: UpdateCatalog): UpdateDialogCatalog {
const currentUserType = status.currentUserType const currentUserType = status.currentUserType
if (!status.enabled || !currentUserType || currentUserType === 'Guest') { if (!status.enabled || !currentUserType) {
return { mode: 'disabled' } return { mode: 'disabled' }
} }

View File

@@ -106,7 +106,7 @@ export class UpdateService {
this.ensureInitialized() this.ensureInitialized()
this.status.currentUserType = userType this.status.currentUserType = userType
if (!this.status.enabled || !userType || userType === 'Guest') { if (!this.status.enabled || !userType) {
this.clearPolling() this.clearPolling()
this.catalog = { stable: [], preview: [] } this.catalog = { stable: [], preview: [] }
this.publishStatus({ this.publishStatus({

View File

@@ -139,7 +139,7 @@ export class BIPUsersDAO {
return { return {
id: row.ID as number, id: row.ID as number,
username: row.UserName as string, username: row.UserName as string,
userType: row.UserType as 'Admin' | 'User' | 'Guest' userType: row.UserType as 'Admin' | 'User'
} }
} }
return null return null
@@ -157,7 +157,7 @@ export class BIPUsersDAO {
return { return {
id: row.ID as number, id: row.ID as number,
username: row.UserName as string, username: row.UserName as string,
userType: row.UserType as 'Admin' | 'User' | 'Guest' userType: row.UserType as 'Admin' | 'User'
} }
} }
return null return null
@@ -198,7 +198,7 @@ export class BIPUsersDAO {
return { return {
id: row.ID as number, id: row.ID as number,
username: row.UserName as string, username: row.UserName as string,
userType: row.UserType as 'Admin' | 'User' | 'Guest' userType: row.UserType as 'Admin' | 'User'
} }
} }
return null return null
@@ -216,7 +216,7 @@ export class BIPUsersDAO {
return { return {
id: row.ID as number, id: row.ID as number,
username: row.UserName as string, username: row.UserName as string,
userType: row.UserType as 'Admin' | 'User' | 'Guest' userType: row.UserType as 'Admin' | 'User'
} }
} }
return null return null
@@ -254,7 +254,7 @@ export class BIPUsersDAO {
return result.rows.map((row) => ({ return result.rows.map((row) => ({
id: row.ID as number, id: row.ID as number,
username: row.UserName as string, username: row.UserName as string,
userType: row.UserType as 'Admin' | 'User' | 'Guest', userType: row.UserType as 'Admin' | 'User',
createTime: row.CreateTime as Date | undefined createTime: row.CreateTime as Date | undefined
})) }))
} catch (error) { } catch (error) {
@@ -270,7 +270,7 @@ export class BIPUsersDAO {
* Create a new user * Create a new user
* @param username - The username (must be unique) * @param username - The username (must be unique)
* @param password - The password * @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 * @param computerName - Optional computer name for silent login
* @returns True if successful * @returns True if successful
*/ */

View File

@@ -126,13 +126,6 @@ export class SessionManager {
return this.currentUser?.userType === 'Admin' 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 * Get the current username
*/ */

View File

@@ -10,7 +10,7 @@
/** /**
* User type for settings permission control * User type for settings permission control
*/ */
export type UserType = 'Admin' | 'User' | 'Guest' export type UserType = 'Admin' | 'User'
/** /**
* Database type selection * Database type selection

View File

@@ -5,7 +5,7 @@
/** /**
* User type enumeration * User type enumeration
*/ */
export type UserType = 'Admin' | 'User' | 'Guest' export type UserType = 'Admin' | 'User'
/** /**
* User information interface * User information interface

View File

@@ -13,7 +13,7 @@ import { Modal } from './ui/Modal'
export interface UserInfo { export interface UserInfo {
id: number id: number
username: string username: string
userType: 'Admin' | 'User' | 'Guest' userType: 'Admin' | 'User'
createTime?: Date createTime?: Date
} }
@@ -61,8 +61,7 @@ export const UserSelectionDialog: React.FC<UserSelectionDialogProps> = ({
const userTypeStyles: Record<string, string> = { const userTypeStyles: Record<string, string> = {
Admin: 'bg-amber-50 text-amber-600', Admin: 'bg-amber-50 text-amber-600',
User: 'bg-blue-50 text-blue-600', User: 'bg-blue-50 text-blue-600'
Guest: 'bg-gray-100 text-gray-600'
} }
if (!isOpen) return null if (!isOpen) return null

View File

@@ -4,7 +4,7 @@ import UserSelectionDialog, { type UserInfo as SelectedUserInfo } from '../UserS
interface CurrentUser { interface CurrentUser {
username: string username: string
userType: 'Admin' | 'User' | 'Guest' userType: 'Admin' | 'User'
} }
interface UnauthenticatedAppProps { interface UnauthenticatedAppProps {

View File

@@ -17,7 +17,7 @@ export interface CurrentUser {
export interface SelectedUserInfo { export interface SelectedUserInfo {
id: number id: number
username: string username: string
userType: 'Admin' | 'User' | 'Guest' userType: 'Admin' | 'User'
computerName?: string computerName?: string
} }

View File

@@ -3,7 +3,7 @@ import { useState, useCallback } from 'react'
interface UserInfo { interface UserInfo {
id: number id: number
username: string username: string
userType: 'Admin' | 'User' | 'Guest' userType: 'Admin' | 'User'
computerName?: string computerName?: string
} }

View File

@@ -10,7 +10,7 @@ import { create } from 'zustand'
interface UserInfo { interface UserInfo {
id: number id: number
username: string username: string
userType: 'Admin' | 'User' | 'Guest' userType: 'Admin' | 'User'
computerName?: string computerName?: string
} }