feat(auth): separate source control write permissions (#9787)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
28ce9d1c17
commit
2eda8ac6a3
59 files changed
+3628
-315
No files matched your search
@@ -1,5 +1,12 @@
|
||||
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
|
||||
import { isAtomCommandInterrupted } from "@t3tools/client-runtime/state/runtime";
|
||||
import {
|
||||
AuthOrchestrationOperateScope,
|
||||
type EnvironmentId,
|
||||
type ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
isAtomCommandInterrupted,
|
||||
squashAtomCommandFailure,
|
||||
} from "@t3tools/client-runtime/state/runtime";
|
||||
import { useDebouncedValue } from "@tanstack/react-pacer";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
@@ -12,6 +19,7 @@ import { cn } from "~/lib/utils";
|
||||
import { parsePullRequestReference } from "~/pullRequestReference";
|
||||
import { getSourceControlPresentation } from "~/sourceControlPresentation";
|
||||
import { useEnvironmentQuery } from "~/state/query";
|
||||
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
|
||||
import { vcsEnvironment } from "~/state/vcs";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
@@ -49,6 +57,7 @@ export function PullRequestThreadDialog({
|
||||
const [reference, setReference] = useState(initialReference ?? "");
|
||||
const [referenceDirty, setReferenceDirty] = useState(false);
|
||||
const [preparingMode, setPreparingMode] = useState<"local" | "worktree" | null>(null);
|
||||
const [prepareErrorMessage, setPrepareErrorMessage] = useState<string | null>(null);
|
||||
const [debouncedReference, referenceDebouncer] = useDebouncedValue(
|
||||
reference,
|
||||
{ wait: 450 },
|
||||
@@ -102,6 +111,7 @@ export function PullRequestThreadDialog({
|
||||
);
|
||||
}, [parsedReference, sourceControlScope]);
|
||||
const preparePullRequestThreadAction = usePreparePullRequestThreadAction(sourceControlScope);
|
||||
const canOperateThread = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope);
|
||||
|
||||
const liveResolvedPullRequest =
|
||||
parsedReference !== null && parsedReference === parsedDebouncedReference
|
||||
@@ -131,6 +141,13 @@ export function PullRequestThreadDialog({
|
||||
|
||||
const handleConfirm = useCallback(
|
||||
async (mode: "local" | "worktree") => {
|
||||
if (!preparePullRequestThreadAction.isAllowed) return;
|
||||
if (
|
||||
mode === "worktree" &&
|
||||
!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!parsedReference) {
|
||||
setReferenceDirty(true);
|
||||
return;
|
||||
@@ -138,6 +155,7 @@ export function PullRequestThreadDialog({
|
||||
if (!parsedReference || !resolvedPullRequest || !cwd) {
|
||||
return;
|
||||
}
|
||||
setPrepareErrorMessage(null);
|
||||
setPreparingMode(mode);
|
||||
const result = await preparePullRequestThreadAction.run({
|
||||
reference: parsedReference,
|
||||
@@ -148,6 +166,13 @@ export function PullRequestThreadDialog({
|
||||
if (result._tag === "Failure") {
|
||||
if (isAtomCommandInterrupted(result)) {
|
||||
preparePullRequestThreadAction.resetError();
|
||||
} else {
|
||||
const error = squashAtomCommandFailure(result);
|
||||
setPrepareErrorMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: `Failed to prepare ${terminology.singular} thread.`,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -159,11 +184,13 @@ export function PullRequestThreadDialog({
|
||||
},
|
||||
[
|
||||
cwd,
|
||||
environmentId,
|
||||
onOpenChange,
|
||||
onPrepared,
|
||||
parsedReference,
|
||||
preparePullRequestThreadAction,
|
||||
resolvedPullRequest,
|
||||
terminology.singular,
|
||||
threadId,
|
||||
],
|
||||
);
|
||||
@@ -177,6 +204,7 @@ export function PullRequestThreadDialog({
|
||||
: null;
|
||||
const errorMessage =
|
||||
validationMessage ??
|
||||
prepareErrorMessage ??
|
||||
(resolvedPullRequest === null && pullRequestResolution.error
|
||||
? pullRequestResolution.error
|
||||
: preparePullRequestThreadAction.error instanceof Error
|
||||
@@ -273,10 +301,9 @@ export function PullRequestThreadDialog({
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
void handleConfirm("local");
|
||||
}}
|
||||
onClick={() => handleConfirm("local")}
|
||||
disabled={
|
||||
!preparePullRequestThreadAction.isAllowed ||
|
||||
!cwd ||
|
||||
!resolvedPullRequest ||
|
||||
isResolving ||
|
||||
@@ -288,10 +315,10 @@ export function PullRequestThreadDialog({
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
void handleConfirm("worktree");
|
||||
}}
|
||||
onClick={() => handleConfirm("worktree")}
|
||||
disabled={
|
||||
!preparePullRequestThreadAction.isAllowed ||
|
||||
!canOperateThread ||
|
||||
!cwd ||
|
||||
!resolvedPullRequest ||
|
||||
isResolving ||
|
||||
|
||||
Reference in new issue
Block a user