Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/policies/RoleRestrictions.tsx
2501 views
1
/**
2
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
8
import { useState } from "react";
9
import { Button } from "@podkit/buttons/Button";
10
import { ConfigurationSettingsField } from "../../repositories/detail/ConfigurationSettingsField";
11
import { useMutation } from "@tanstack/react-query";
12
import type { PlainMessage } from "@bufbuild/protobuf";
13
import { Link } from "react-router-dom";
14
import {
15
OrganizationRoleRestrictionModal,
16
OrganizationRoleRestrictionModalProps,
17
OrgMemberPermissionRestrictionsOptions,
18
} from "../../components/OrgMemberPermissionsOptions";
19
import { LightbulbIcon } from "lucide-react";
20
import { Heading3, Subheading } from "@podkit/typography/Headings";
21
22
type RolePermissionsRestrictionsProps = {
23
settings: OrganizationSettings | undefined;
24
isOwner: boolean;
25
handleUpdateTeamSettings: (
26
newSettings: Partial<PlainMessage<OrganizationSettings>>,
27
options?: { throwMutateError?: boolean },
28
) => Promise<void>;
29
};
30
export const RolePermissionsRestrictions = ({
31
settings,
32
isOwner,
33
handleUpdateTeamSettings,
34
}: RolePermissionsRestrictionsProps) => {
35
const [showModal, setShowModal] = useState(false);
36
37
const updateMutation: OrganizationRoleRestrictionModalProps["updateMutation"] = useMutation({
38
mutationFn: async ({ roleRestrictions }) => {
39
await handleUpdateTeamSettings({ roleRestrictions }, { throwMutateError: true });
40
},
41
});
42
43
return (
44
<ConfigurationSettingsField>
45
<Heading3>Roles allowed to start workspaces from non-imported repos</Heading3>
46
<Subheading className="mb-2">
47
Restrict specific roles from initiating workspaces using non-imported repositories. This setting
48
requires <span className="font-medium">Owner</span> permissions to modify.
49
<br />
50
<span className="flex flex-row items-center gap-1 my-2">
51
<LightbulbIcon size={20} />{" "}
52
<span>
53
Tip: Imported repositories are those listed under{" "}
54
<Link to={"/repositories"} className="gp-link">
55
Repository settings
56
</Link>
57
.
58
</span>
59
</span>
60
</Subheading>
61
62
<OrgMemberPermissionRestrictionsOptions roleRestrictions={settings?.roleRestrictions ?? []} />
63
64
{isOwner && (
65
<Button className="mt-6" onClick={() => setShowModal(true)}>
66
Manage Permissions
67
</Button>
68
)}
69
70
{showModal && (
71
<OrganizationRoleRestrictionModal
72
isLoading={false}
73
defaultClass={""}
74
roleRestrictions={settings?.roleRestrictions ?? []}
75
showSetDefaultButton={false}
76
showSwitchTitle={false}
77
allowedClasses={[]}
78
updateMutation={updateMutation}
79
onClose={() => setShowModal(false)}
80
/>
81
)}
82
</ConfigurationSettingsField>
83
);
84
};
85
86