mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Fix/permission dialog id bug (#71)
* Fix permission dialog using wrong ID and add typed permission labels - Fix critical bug: pass permission.id instead of permission.permission when responding - Replace hardcoded switch statement with PERMISSION_LABELS derived from OpenCode types - Add all permission types from PermissionConfig schema * Add per-repo reset permissions feature - Add POST /api/repos/:id/reset-permissions endpoint that disposes OpenCode instance - Add resetRepoPermissions API function in frontend - Add Reset Permissions button in RepoDetail header and mobile dropdown - Add confirmation dialog explaining the action clears Allow Always permissions * Improve OpenCode config error handling and UI responsiveness
This commit is contained in:
1 parent
2bd2b024b8
commit
d035e196bd
9 files changed
+206
-53
No files matched your search
@@ -61,7 +61,7 @@ export function OpenCodeConfigEditor({
|
||||
setEditErrorLine(line)
|
||||
setEditError('Invalid JSON/JSONC format')
|
||||
} else {
|
||||
setEditError(error instanceof Error ? error.message : 'Failed to update config')
|
||||
setEditError('Failed to save. Please check your changes and try again.')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,14 +70,14 @@ export function OpenCodeConfigEditor({
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent mobileFullscreen className="h-[90vh] max-w-6xl gap-0 flex flex-col p-0 sm:p-6">
|
||||
<DialogContent mobileFullscreen className="gap-0 flex flex-col p-0 md:p-6 w-full min-w-0 sm:max-w-4xl">
|
||||
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
|
||||
<DialogTitle className="text-lg sm:text-xl font-semibold">
|
||||
{`Edit Config: ${config.name}`}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex-1 p-0 sm:p-4 overflow-hidden relative">
|
||||
<div className="flex-1 p-0 sm:p-4 overflow-hidden relative w-full">
|
||||
<Textarea
|
||||
id="edit-config-content"
|
||||
ref={editTextareaRef}
|
||||
|
||||
@@ -115,12 +115,16 @@ export function OpenCodeConfigManager() {
|
||||
},
|
||||
})
|
||||
|
||||
const getApiErrorMessage = (error: unknown, fallback: string): string => {
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { details?: string; error?: string } } }).response
|
||||
return response?.data?.details || response?.data?.error || fallback
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
const getRestartErrorMessage = (error: unknown): string => {
|
||||
return error && typeof error === 'object' && 'response' in error
|
||||
? ((error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.details
|
||||
|| (error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.error
|
||||
|| 'Failed to restart OpenCode server')
|
||||
: 'Failed to restart OpenCode server'
|
||||
return getApiErrorMessage(error, 'Failed to restart OpenCode server')
|
||||
}
|
||||
|
||||
const rollbackMutation = useMutation({
|
||||
@@ -184,7 +188,7 @@ export function OpenCodeConfigManager() {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
} catch (error) {
|
||||
console.error('Failed to update config:', error)
|
||||
showToast.error('Failed to update config', { id: 'update-restart' })
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to update config'), { id: 'update-restart' })
|
||||
} finally {
|
||||
setIsUpdating(false)
|
||||
}
|
||||
@@ -238,7 +242,7 @@ export function OpenCodeConfigManager() {
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
} catch (error) {
|
||||
console.error('Failed to create config:', error)
|
||||
showToast.error('Failed to create configuration', { id: 'create-config' })
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to create configuration'), { id: 'create-config' })
|
||||
throw error
|
||||
} finally {
|
||||
setIsUpdating(false)
|
||||
@@ -272,12 +276,7 @@ export function OpenCodeConfigManager() {
|
||||
showToast.success('Default config updated and server reloaded', { id: 'set-default' })
|
||||
} catch (error) {
|
||||
console.error('Failed to set default config:', error)
|
||||
const errorMessage = error && typeof error === 'object' && 'response' in error
|
||||
? ((error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.details
|
||||
|| (error as { response?: { data?: { details?: string; error?: string } } }).response?.data?.error
|
||||
|| 'Failed to set default config')
|
||||
: 'Failed to set default config'
|
||||
showToast.error(errorMessage, { id: 'set-default' })
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to set default config'), { id: 'set-default' })
|
||||
} finally {
|
||||
setIsUpdating(false)
|
||||
}
|
||||
@@ -504,11 +503,8 @@ export function OpenCodeConfigManager() {
|
||||
showToast.success(successMsg, { id: 'edit-config' })
|
||||
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('restart')) {
|
||||
showToast.error(getRestartErrorMessage(error), { id: 'edit-config' })
|
||||
} else {
|
||||
showToast.error('Failed to save configuration', { id: 'edit-config' })
|
||||
}
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to save configuration'), { id: 'edit-config' })
|
||||
throw error
|
||||
}
|
||||
}}
|
||||
isUpdating={isUpdating}
|
||||
|
||||
Reference in new issue
Block a user