mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
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
This commit is contained in:
1 parent
01d5304d25
commit
5153d49fa7
3 files changed
+112
-3
No files matched your search
@@ -9,6 +9,7 @@ import * as archiveService from '../services/archive'
|
||||
import { SettingsService } from '../services/settings'
|
||||
import { writeFileContent } from '../services/file-operations'
|
||||
import { opencodeServerManager } from '../services/opencode-single-server'
|
||||
import { proxyToOpenCodeWithDirectory } from '../services/proxy'
|
||||
import { logger } from '../utils/logger'
|
||||
import { getErrorMessage, getStatusCode } from '../utils/error-utils'
|
||||
import { getOpenCodeConfigFilePath, getReposPath } from '@opencode-manager/shared/config/env'
|
||||
@@ -359,6 +360,35 @@ app.get('/', async (c) => {
|
||||
return c.json({ error: getErrorMessage(error) }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/:id/reset-permissions', async (c) => {
|
||||
try {
|
||||
const id = parseInt(c.req.param('id'))
|
||||
const repo = db.getRepoById(database, id)
|
||||
|
||||
if (!repo) {
|
||||
return c.json({ error: 'Repo not found' }, 404)
|
||||
}
|
||||
|
||||
const response = await proxyToOpenCodeWithDirectory(
|
||||
'/instance/dispose',
|
||||
'POST',
|
||||
repo.fullPath
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error(`Failed to reset permissions for repo ${id}:`, errorText)
|
||||
return c.json({ error: 'Failed to reset permissions' }, 500)
|
||||
}
|
||||
|
||||
logger.info(`Reset permissions for repo ${id} (${repo.fullPath})`)
|
||||
return c.json({ success: true })
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to reset permissions:', error)
|
||||
return c.json({ error: getErrorMessage(error) }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -201,3 +201,14 @@ export async function updateRepoOrder(order: number[]): Promise<void> {
|
||||
throw new Error(error.error || 'Failed to update repo order')
|
||||
}
|
||||
}
|
||||
|
||||
export async function resetRepoPermissions(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos/${id}/reset-permissions`, {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json()
|
||||
throw new Error(error.error || 'Failed to reset permissions')
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useRef, useEffect, useCallback } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { getRepo } from "@/api/repos";
|
||||
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
||||
import { getRepo, resetRepoPermissions } from "@/api/repos";
|
||||
import { SessionList } from "@/components/session/SessionList";
|
||||
import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet";
|
||||
import { Header } from "@/components/ui/header";
|
||||
@@ -15,8 +15,17 @@ import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { BranchSwitcher } from "@/components/repo/BranchSwitcher";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Plug, FolderOpen, Plus, GitBranch, Loader2 } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Plug, FolderOpen, Plus, GitBranch, Loader2, ShieldOff } from "lucide-react";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
import { showToast } from "@/lib/toast";
|
||||
|
||||
export function RepoDetail() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
@@ -26,6 +35,7 @@ export function RepoDetail() {
|
||||
const [fileBrowserOpen, setFileBrowserOpen] = useState(false);
|
||||
const [switchConfigOpen, setSwitchConfigOpen] = useState(false);
|
||||
const [mcpDialogOpen, setMcpDialogOpen] = useState(false);
|
||||
const [resetPermissionsOpen, setResetPermissionsOpen] = useState(false);
|
||||
const pageRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleSwipeBack = useCallback(() => {
|
||||
@@ -63,6 +73,17 @@ export function RepoDetail() {
|
||||
|
||||
const createSessionMutation = useCreateSession(opcodeUrl, repoDirectory);
|
||||
|
||||
const resetPermissionsMutation = useMutation({
|
||||
mutationFn: () => resetRepoPermissions(repoId),
|
||||
onSuccess: () => {
|
||||
showToast.success("Permissions reset successfully");
|
||||
setResetPermissionsOpen(false);
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error("Failed to reset permissions");
|
||||
},
|
||||
});
|
||||
|
||||
const handleCreateSession = async (options?: {
|
||||
agentSlug?: string;
|
||||
promptSlug?: string;
|
||||
@@ -163,6 +184,15 @@ export function RepoDetail() {
|
||||
<FolderOpen className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Files</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setResetPermissionsOpen(true)}
|
||||
size="sm"
|
||||
className="hidden lg:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<ShieldOff className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Reset Permissions</span>
|
||||
</Button>
|
||||
<Header.MobileDropdown>
|
||||
{!isWorktree && currentBranch && (
|
||||
<>
|
||||
@@ -185,6 +215,9 @@ export function RepoDetail() {
|
||||
<DropdownMenuItem onClick={() => setFileBrowserOpen(true)}>
|
||||
<FolderOpen className="w-4 h-4 mr-2" /> Files
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setResetPermissionsOpen(true)}>
|
||||
<ShieldOff className="w-4 h-4 mr-2" /> Reset Permissions
|
||||
</DropdownMenuItem>
|
||||
</Header.MobileDropdown>
|
||||
<Button
|
||||
onClick={() => handleCreateSession()}
|
||||
@@ -236,6 +269,41 @@ export function RepoDetail() {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Dialog open={resetPermissionsOpen} onOpenChange={setResetPermissionsOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Reset Permissions</DialogTitle>
|
||||
<DialogDescription>
|
||||
This will clear all "Allow Always" permissions for this repository.
|
||||
You will be prompted again for permission when opencode needs to perform actions like running commands or editing files.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setResetPermissionsOpen(false)}
|
||||
disabled={resetPermissionsMutation.isPending}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => resetPermissionsMutation.mutate()}
|
||||
disabled={resetPermissionsMutation.isPending}
|
||||
>
|
||||
{resetPermissionsMutation.isPending ? (
|
||||
<>
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
Resetting...
|
||||
</>
|
||||
) : (
|
||||
"Reset Permissions"
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user