Skip to content

Commit 03f7c04

Browse files
fix(settings): respect environment permissions for GitHub account rules
1 parent fae10e3 commit 03f7c04

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

‎apps/mobile/src/features/settings/SettingsGitHubAccountsRouteScreen.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type GitHubHostGroup,
1010
} from "@t3tools/client-runtime/github-accounts";
1111
import { readGitHubSettings } from "@t3tools/client-runtime/source-control-clients";
12-
import { AuthSettingsWriteScope, type ProjectId } from "@t3tools/contracts";
12+
import { type ProjectId } from "@t3tools/contracts";
1313
import { useState } from "react";
1414
import { View } from "react-native";
1515
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -19,7 +19,6 @@ import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
1919
import { environmentProjects } from "../../state/projects";
2020
import { useEnvironmentQuery } from "../../state/query";
2121
import { serverEnvironment } from "../../state/server";
22-
import { useEnvironmentsWithScope } from "../../state/session";
2322
import { sourceControlEnvironment } from "../../state/sourceControl";
2423
import { useAtomCommand } from "../../state/use-atom-command";
2524
import {
@@ -67,9 +66,7 @@ function useGitHubAccountChoices(environment: SettingsTarget) {
6766
sourceControlEnvironment.discovery({ environmentId, input: {} }),
6867
);
6968
const projects = useAtomValue(environmentProjects.environmentProjectsAtom(environmentId));
70-
const writable = useEnvironmentsWithScope([environment], AuthSettingsWriteScope).has(
71-
environmentId,
72-
);
69+
const writable = useAtomValue(serverEnvironment.updateSettings.permissionAtom(environmentId));
7370
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
7471
label: "save GitHub account settings",
7572
reportFailure: true,
@@ -180,9 +177,7 @@ function HostAccounts(props: {
180177
choice?.account !== undefined && group.selectable.includes(choice.account)
181178
? choice.account
182179
: null;
183-
// What an owner without a rule reads as: the host's pinned login, else gh's active one.
184180
const hostAccount = pinned ?? group.activeAccount;
185-
// Repositories a project gave a rule of its own, which wins over its owner's.
186181
const repositories = Object.keys(choice?.repositories ?? {}).sort((left, right) =>
187182
left.localeCompare(right),
188183
);

‎apps/web/src/components/settings/GitHubAccountSettings.tsx‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export function GitHubAccountSettings({
164164
const hosts = github.hosts;
165165
const projects = useAtomValue(environmentProjects.environmentProjectsAtom(environmentId));
166166
const identities = projects.map((project) => project.repositoryIdentity);
167+
const writable = useAtomValue(serverEnvironment.updateSettings.permissionAtom(environmentId));
167168
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
168169
label: "save GitHub account settings",
169170
});
@@ -226,7 +227,6 @@ export function GitHubAccountSettings({
226227
revealed={revealed}
227228
/>
228229
);
229-
// What an owner without a rule reads as: the host's pinned login, else gh's active one.
230230
const hostAccount = pinned === DEFAULT_ACCOUNT ? group.activeAccount : pinned;
231231
const multiple = group.selectable.length > 1;
232232
const owners = multiple
@@ -249,7 +249,7 @@ export function GitHubAccountSettings({
249249
</div>
250250
<Switch
251251
checked={enabled}
252-
disabled={saving}
252+
disabled={saving || !writable}
253253
aria-label={`Use GitHub on ${group.host}`}
254254
onCheckedChange={(checked) => void save(group.host, { enabled: checked })}
255255
/>
@@ -262,7 +262,7 @@ export function GitHubAccountSettings({
262262
accounts={group.selectable}
263263
defaultLabel={activeLabel}
264264
revealed={revealed}
265-
disabled={saving}
265+
disabled={saving || !writable}
266266
ariaLabel={`GitHub account for ${group.host}`}
267267
onChange={(account) => void save(group.host, { account })}
268268
/>
@@ -276,7 +276,7 @@ export function GitHubAccountSettings({
276276
<Button
277277
size="xs"
278278
variant="outline"
279-
disabled={saving}
279+
disabled={saving || !writable}
280280
onClick={() => void save(group.host, { account: null })}
281281
>
282282
Use active login
@@ -305,7 +305,7 @@ export function GitHubAccountSettings({
305305
<DefaultLabel prefix="Default" account={hostAccount} revealed={revealed} />
306306
}
307307
revealed={revealed}
308-
disabled={saving}
308+
disabled={saving || !writable}
309309
ariaLabel={`GitHub account for ${owner} on ${group.host}`}
310310
staleWarning={`This login is no longer signed in, so ${owner} uses the default account.`}
311311
onChange={(account) =>
@@ -334,7 +334,7 @@ export function GitHubAccountSettings({
334334
/>
335335
}
336336
revealed={revealed}
337-
disabled={saving}
337+
disabled={saving || !writable}
338338
ariaLabel={`GitHub account for ${repository} on ${group.host}`}
339339
staleWarning={`This login is no longer signed in, so ${repository} reads as its owner's account.`}
340340
onChange={(account) =>
@@ -373,6 +373,7 @@ export function ProjectGitHubAccountRow({
373373
);
374374
const projects = useAtomValue(environmentProjects.environmentProjectsAtom(environmentId));
375375
const hosts = useEnvironmentSettings(environmentId, readGitHubSettings).hosts;
376+
const writable = useAtomValue(serverEnvironment.updateSettings.permissionAtom(environmentId));
376377
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
377378
label: "save GitHub account settings",
378379
});
@@ -449,7 +450,12 @@ export function ProjectGitHubAccountRow({
449450
{revealed ? <EyeOffIcon /> : <EyeIcon />}
450451
</Button>
451452
{stale ? (
452-
<Button size="xs" variant="outline" disabled={saving} onClick={() => void save(null)}>
453+
<Button
454+
size="xs"
455+
variant="outline"
456+
disabled={saving || !writable}
457+
onClick={() => void save(null)}
458+
>
453459
Clear override
454460
</Button>
455461
) : null}
@@ -460,7 +466,7 @@ export function ProjectGitHubAccountRow({
460466
<DefaultLabel prefix="Owner's account" account={ownerAccount} revealed={revealed} />
461467
}
462468
revealed={revealed}
463-
disabled={saving}
469+
disabled={saving || !writable}
464470
ariaLabel={`GitHub account for ${repository.repository}`}
465471
onChange={(account) => void save(account)}
466472
/>

0 commit comments

Comments
 (0)