mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 16:27:40 +00:00
fix: check create member permission for invite ability
This commit is contained in:
+30
-2
@@ -7,7 +7,13 @@ import { z } from "zod";
|
|||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { Button, FilterableSelect, FormControl, Modal, ModalContent } from "@app/components/v2";
|
import { Button, FilterableSelect, FormControl, Modal, ModalContent } from "@app/components/v2";
|
||||||
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
import { CreatableSelect } from "@app/components/v2/CreatableSelect";
|
||||||
import { useOrganization, useWorkspace } from "@app/context";
|
import {
|
||||||
|
OrgPermissionActions,
|
||||||
|
OrgPermissionSubjects,
|
||||||
|
useOrganization,
|
||||||
|
useOrgPermission,
|
||||||
|
useWorkspace
|
||||||
|
} from "@app/context";
|
||||||
import {
|
import {
|
||||||
useAddUsersToOrg,
|
useAddUsersToOrg,
|
||||||
useGetOrgUsers,
|
useGetOrgUsers,
|
||||||
@@ -42,6 +48,7 @@ export const AddMemberModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { currentOrg } = useOrganization();
|
const { currentOrg } = useOrganization();
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
const { permission } = useOrgPermission();
|
||||||
|
|
||||||
const orgId = currentOrg?.id || "";
|
const orgId = currentOrg?.id || "";
|
||||||
const workspaceId = currentWorkspace?.id || "";
|
const workspaceId = currentWorkspace?.id || "";
|
||||||
@@ -140,6 +147,11 @@ export const AddMemberModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
|
|
||||||
const { append } = useFieldArray<TAddMemberForm>({ control, name: "orgMemberships" });
|
const { append } = useFieldArray<TAddMemberForm>({ control, name: "orgMemberships" });
|
||||||
|
|
||||||
|
const canInviteNewMembers = permission.can(
|
||||||
|
OrgPermissionActions.Create,
|
||||||
|
OrgPermissionSubjects.Member
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={popUp?.addMember?.isOpen}
|
isOpen={popUp?.addMember?.isOpen}
|
||||||
@@ -161,8 +173,13 @@ export const AddMemberModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
isError={!!errors.orgMemberships?.length}
|
isError={!!errors.orgMemberships?.length}
|
||||||
errorText={errors.orgMemberships?.[0]?.message}
|
errorText={errors.orgMemberships?.[0]?.message}
|
||||||
label="Invite users to project"
|
label="Invite users to project"
|
||||||
helperText="You can invite new users to your organzation by typing out their email address"
|
helperText={
|
||||||
|
canInviteNewMembers
|
||||||
|
? "You can invite new users to your organization by typing out their email address"
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
|
{canInviteNewMembers ? (
|
||||||
<CreatableSelect
|
<CreatableSelect
|
||||||
/* eslint-disable-next-line react/no-unstable-nested-components */
|
/* eslint-disable-next-line react/no-unstable-nested-components */
|
||||||
noOptionsMessage={() => (
|
noOptionsMessage={() => (
|
||||||
@@ -208,6 +225,17 @@ export const AddMemberModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
value={field.value}
|
value={field.value}
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<FilterableSelect
|
||||||
|
className="w-full"
|
||||||
|
placeholder="Add one or more users..."
|
||||||
|
isMulti
|
||||||
|
name="members"
|
||||||
|
options={filteredOrgUsers}
|
||||||
|
value={field.value}
|
||||||
|
onChange={field.onChange}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user