fix: Hide org tab when you are team admin (#14627)

* fix: hide-tab-on-fe

* fix: backend pulling back info if the user dont have perms
This commit is contained in:
sean-brydon
2024-04-17 10:38:12 +01:00
committed by GitHub
parent ae64d7ba82
commit 4aeb6b7c9b
2 changed files with 22 additions and 6 deletions
@@ -74,10 +74,21 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
const { data: currentOrg } = trpc.viewer.organizations.listCurrent.useQuery(undefined, {
enabled: !!session.data?.user?.org,
});
const isOrgOwner = currentOrg && currentOrg.user.role === MembershipRole.OWNER;
// Check current org role and not team role
const isOrgAdminOrOwner =
currentOrg &&
(currentOrg.user.role === MembershipRole.OWNER || currentOrg.user.role === MembershipRole.ADMIN);
const canSeeOrganization = !!(
props?.orgMembers &&
props.orgMembers?.length > 0 &&
currentOrg?.isPrivate &&
isOrgAdminOrOwner
);
const [modalImportMode, setModalInputMode] = useState<ModalMode>(
props?.orgMembers && props.orgMembers?.length > 0 ? "ORGANIZATION" : "INDIVIDUAL"
canSeeOrganization ? "ORGANIZATION" : "INDIVIDUAL"
);
const createInviteMutation = trpc.viewer.teams.createInvite.useMutation({
@@ -98,12 +109,12 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
];
// Adjust options for organizations where the user isn't the owner
if (isOrg && !isOrgOwner) {
if (isOrg && !isOrgAdminOrOwner) {
return options.filter((option) => option.value !== MembershipRole.OWNER);
}
return options;
}, [t, isOrgOwner, isOrg]);
}, [t, isOrgAdminOrOwner, isOrg]);
const toggleGroupOptions = useMemo(() => {
const array = [
@@ -114,7 +125,7 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
},
{ value: "BULK", label: t("invite_team_bulk_segment"), iconLeft: <Icon name="users" /> },
];
if (props?.orgMembers && props.orgMembers?.length > 0) {
if (canSeeOrganization) {
array.unshift({
value: "ORGANIZATION",
label: t("organization"),
@@ -122,7 +133,7 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
});
}
return array;
}, [t, props.orgMembers]);
}, [t, canSeeOrganization]);
const newMemberFormMethods = useForm<NewMemberForm>();
@@ -15,6 +15,11 @@ export const getMembersHandler = async ({ input, ctx }: CreateOptions) => {
if (!ctx.user.organizationId) return [];
const isOrgPrivate = ctx.user.organization.isPrivate;
const isOrgAdmin = ctx.user.organization.isOrgAdmin;
if (isOrgPrivate && !isOrgAdmin) return [];
const teamQuery = await prisma.team.findUnique({
where: {
id: ctx.user.organizationId,