feat(infisical-pg): connected project api changes with frontend

This commit is contained in:
Akhil Mohan
2024-01-27 12:38:22 +05:30
parent 4f3582a98b
commit 8a6ab7f2f6
39 changed files with 343 additions and 339 deletions
+93 -93
View File
@@ -1,123 +1,123 @@
import { TRole } from "../roles/types";
import { TOrgRole, TProjectRole } from "../roles/types";
import { IdentityAuthMethod } from "./enums";
export type IdentityTrustedIp = {
id: string;
ipAddress: string;
type: "ipv4" | "ipv6";
prefix?: number;
}
id: string;
ipAddress: string;
type: "ipv4" | "ipv6";
prefix?: number;
};
export type Identity = {
id: string;
name: string;
authMethod?: IdentityAuthMethod;
createdAt: string;
updatedAt: string;
id: string;
name: string;
authMethod?: IdentityAuthMethod;
createdAt: string;
updatedAt: string;
};
export type IdentityMembershipOrg = {
id: string;
identity: Identity;
organization: string;
role: "admin" | "member" | "viewer" | "no-access" | "custom";
customRole?: TRole<string>;
createdAt: string;
updatedAt: string;
}
id: string;
identity: Identity;
organization: string;
role: "admin" | "member" | "viewer" | "no-access" | "custom";
customRole?: TOrgRole;
createdAt: string;
updatedAt: string;
};
export type IdentityMembership = {
id: string;
identity: Identity;
organization: string;
role: "admin" | "member" | "viewer" | "no-access" | "custom";
customRole?: TRole<string>;
createdAt: string;
updatedAt: string;
}
id: string;
identity: Identity;
organization: string;
role: "admin" | "member" | "viewer" | "no-access" | "custom";
customRole?: TProjectRole;
createdAt: string;
updatedAt: string;
};
export type CreateIdentityDTO = {
name: string;
organizationId: string;
role?: string;
}
name: string;
organizationId: string;
role?: string;
};
export type UpdateIdentityDTO = {
identityId: string;
name?: string;
role?: string;
organizationId: string;
}
identityId: string;
name?: string;
role?: string;
organizationId: string;
};
export type DeleteIdentityDTO = {
identityId: string;
organizationId: string;
}
identityId: string;
organizationId: string;
};
export type IdentityUniversalAuth = {
identityId: string;
clientId: string;
clientSecretTrustedIps: IdentityTrustedIp[];
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
accessTokenTrustedIps: IdentityTrustedIp[];
}
identityId: string;
clientId: string;
clientSecretTrustedIps: IdentityTrustedIp[];
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
accessTokenTrustedIps: IdentityTrustedIp[];
};
export type AddIdentityUniversalAuthDTO = {
organizationId: string;
identityId: string;
clientSecretTrustedIps: {
ipAddress: string;
}[];
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
accessTokenTrustedIps: {
ipAddress: string;
}[];
}
organizationId: string;
identityId: string;
clientSecretTrustedIps: {
ipAddress: string;
}[];
accessTokenTTL: number;
accessTokenMaxTTL: number;
accessTokenNumUsesLimit: number;
accessTokenTrustedIps: {
ipAddress: string;
}[];
};
export type UpdateIdentityUniversalAuthDTO = {
organizationId: string;
identityId: string;
clientSecretTrustedIps?: {
ipAddress: string;
}[];
accessTokenTTL?: number;
accessTokenMaxTTL?: number;
accessTokenNumUsesLimit?: number;
accessTokenTrustedIps?: {
ipAddress: string;
}[];
}
organizationId: string;
identityId: string;
clientSecretTrustedIps?: {
ipAddress: string;
}[];
accessTokenTTL?: number;
accessTokenMaxTTL?: number;
accessTokenNumUsesLimit?: number;
accessTokenTrustedIps?: {
ipAddress: string;
}[];
};
export type CreateIdentityUniversalAuthClientSecretDTO = {
identityId: string;
description?: string;
ttl?: number;
numUsesLimit?: number;
}
identityId: string;
description?: string;
ttl?: number;
numUsesLimit?: number;
};
export type ClientSecretData = {
id: string;
identityUniversalAuth: string;
isClientSecretRevoked: boolean;
description: string;
clientSecretPrefix: string;
clientSecretNumUses: number;
clientSecretNumUsesLimit: number;
clientSecretTTL: number;
createdAt: string;
updatedAt: string;
}
id: string;
identityUniversalAuth: string;
isClientSecretRevoked: boolean;
description: string;
clientSecretPrefix: string;
clientSecretNumUses: number;
clientSecretNumUsesLimit: number;
clientSecretTTL: number;
createdAt: string;
updatedAt: string;
};
export type CreateIdentityUniversalAuthClientSecretRes = {
clientSecret: string;
clientSecretData: ClientSecretData;
}
clientSecret: string;
clientSecretData: ClientSecretData;
};
export type DeleteIdentityUniversalAuthClientSecretDTO = {
identityId: string;
clientSecretId: string;
}
identityId: string;
clientSecretId: string;
};
+4 -4
View File
@@ -1,14 +1,14 @@
export {
useCreateOrgRole,
useCreateRole,
useCreateProjectRole,
useDeleteOrgRole,
useDeleteRole,
useDeleteProjectRole,
useUpdateOrgRole,
useUpdateRole
useUpdateProjectRole
} from "./mutation";
export {
useGetOrgRoles,
useGetRoles,
useGetProjectRoles,
useGetUserOrgPermissions,
useGetUserProjectPermissions
} from "./queries";
+40 -32
View File
@@ -6,45 +6,53 @@ import { apiRequest } from "@app/config/request";
import { roleQueryKeys } from "./queries";
import {
TCreateOrgRoleDTO,
TCreateRoleDTO,
TCreateProjectRoleDTO,
TDeleteOrgRoleDTO,
TDeleteRoleDTO,
TDeleteProjectRoleDTO,
TUpdateOrgRoleDTO,
TUpdateRoleDTO
TUpdateProjectRoleDTO
} from "./types";
export const useCreateRole = <T extends string | undefined>() => {
export const useCreateProjectRole = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (dto: TCreateRoleDTO<T>) => apiRequest.post("/api/v1/roles", dto),
onSuccess: (_, { orgId, workspaceId }) => {
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
}
});
};
export const useUpdateRole = <T extends string | undefined>() => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, ...dto }: TUpdateRoleDTO<T>) => apiRequest.patch(`/api/v1/roles/${id}`, dto),
onSuccess: (_, { orgId, workspaceId }) => {
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
}
});
};
export const useDeleteRole = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ orgId, id }: TDeleteRoleDTO) =>
apiRequest.delete(`/api/v1/roles/${id}`, {
data: { orgId }
mutationFn: ({ projectId, permissions, ...dto }: TCreateProjectRoleDTO) =>
apiRequest.post(`/api/ee/v1/workspace/${projectId}/roles`, {
...dto,
permissions: permissions.length ? packRules(permissions) : []
}),
onSuccess: (_, { orgId, workspaceId }) => {
queryClient.invalidateQueries(roleQueryKeys.getRoles({ orgId, workspaceId }));
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
}
});
};
export const useUpdateProjectRole = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, projectId, permissions, ...dto }: TUpdateProjectRoleDTO) =>
apiRequest.patch(`/api/ee/v1/workspace/${projectId}/roles/${id}`, {
...dto,
permissions: permissions?.length ? packRules(permissions) : []
}),
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
}
});
};
export const useDeleteProjectRole = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ projectId, id }: TDeleteProjectRoleDTO) =>
apiRequest.delete(`/api/ee/v1/workspace/${projectId}/roles/${id}`, {
data: { projectId }
}),
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(roleQueryKeys.getProjectRoles(projectId));
}
});
};
@@ -71,7 +79,7 @@ export const useUpdateOrgRole = () => {
mutationFn: ({ id, orgId, permissions, ...dto }: TUpdateOrgRoleDTO) =>
apiRequest.patch(`/api/ee/v1/organization/${orgId}/roles/${id}`, {
...dto,
permissions: permissions?.length ? packRules(permissions) : undefined
permissions: permissions?.length ? packRules(permissions) : []
}),
onSuccess: (_, { orgId }) => {
queryClient.invalidateQueries(roleQueryKeys.getOrgRoles(orgId));
+15 -20
View File
@@ -10,12 +10,11 @@ import { ProjectPermissionSet } from "@app/context/ProjectPermissionContext/type
import { OrgUser } from "../users/types";
import {
TGetRolesDTO,
TGetUserOrgPermissionsDTO,
TGetUserProjectPermissionDTO,
TOrgRole,
TPermission,
TRole
TProjectRole
} from "./types";
const $glob: FieldInstruction<string> = {
@@ -37,7 +36,7 @@ const glob: JsInterpreter<FieldCondition<string>> = (node, object, context) => {
const conditionsMatcher = buildMongoQueryMatcher({ $glob }, { glob });
export const roleQueryKeys = {
getRoles: ({ orgId, workspaceId }: TGetRolesDTO) => ["roles", { orgId, workspaceId }] as const,
getProjectRoles: (projectId: string) => ["roles", { projectId }] as const,
getOrgRoles: (orgId: string) => ["org-roles", { orgId }] as const,
getUserOrgPermissions: ({ orgId }: TGetUserOrgPermissionsDTO) =>
["user-permissions", { orgId }] as const,
@@ -45,25 +44,21 @@ export const roleQueryKeys = {
["user-project-permissions", { workspaceId }] as const
};
const getRoles = async ({ orgId, workspaceId }: TGetRolesDTO) => {
const { data } = await apiRequest.get<{ data: { roles: TRole<typeof workspaceId>[] } }>(
"/api/v1/roles",
{
params: {
workspaceId,
orgId
}
}
);
return data.data.roles;
const getProjectRoles = async (projectId: string) => {
const { data } = await apiRequest.get<{
data: { roles: Array<Omit<TProjectRole, "permissions"> & { permissions: unknown }> };
}>(`/api/ee/v1/workspace/${projectId}/roles`);
return data.data.roles.map(({ permissions, ...el }) => ({
...el,
permissions: unpackRules(permissions as PackRule<TPermission>[])
}));
};
export const useGetRoles = ({ orgId, workspaceId }: TGetRolesDTO) =>
export const useGetProjectRoles = (projectId: string) =>
useQuery({
queryKey: roleQueryKeys.getRoles({ orgId, workspaceId }),
queryFn: () => getRoles({ orgId, workspaceId }),
enabled: Boolean(orgId)
queryKey: roleQueryKeys.getProjectRoles(projectId),
queryFn: () => getProjectRoles(projectId),
enabled: Boolean(projectId)
});
const getOrgRoles = async (orgId: string) => {
@@ -109,7 +104,7 @@ export const useGetUserOrgPermissions = ({ orgId }: TGetUserOrgPermissionsDTO) =
const getUserProjectPermissions = async ({ workspaceId }: TGetUserProjectPermissionDTO) => {
const { data } = await apiRequest.get<{
data: { permissions: PackRule<RawRuleOf<MongoAbility<OrgPermissionSet>>>[] };
}>(`/api/v1/roles/workspace/${workspaceId}/permissions`, {});
}>(`/api/ee/v1/workspace/${workspaceId}/permissions`, {});
return data.data.permissions;
};
+26 -32
View File
@@ -1,19 +1,16 @@
export type TGetRolesDTO = {
orgId: string;
export type TGetProjectRolesDTO = {
workspaceId?: string;
};
// @depreciated
export type TRole<T extends string | undefined> = {
id: string;
organization: string;
workspace: T;
name: string;
description: string;
export type TProjectRole = {
slug: string;
permissions: T extends string ? TProjectPermission[] : TPermission[];
name: string;
projectId: string;
id: string;
createdAt: string;
updatedAt: string;
description?: string;
permissions: TPermission[];
};
export type TOrgRole = {
@@ -36,28 +33,7 @@ export type TPermission = {
export type TProjectPermission = {
conditions?: Record<string, any>;
action: string;
subject: string;
};
export type TCreateRoleDTO<T extends string | undefined> = {
orgId: string;
workspaceId?: T;
name: string;
description?: string;
slug: string;
permissions: T extends string ? TProjectPermission[] : TPermission[];
};
export type TUpdateRoleDTO<T extends string | undefined> = {
orgId: string;
id: string;
workspaceId?: T;
} & Partial<Omit<TCreateRoleDTO<T>, "orgId" | "workspaceId">>;
export type TDeleteRoleDTO = {
orgId: string;
id: string;
workspaceId?: string;
subject: [string];
};
export type TGetUserOrgPermissionsDTO = {
@@ -85,3 +61,21 @@ export type TDeleteOrgRoleDTO = {
orgId: string;
id: string;
};
export type TCreateProjectRoleDTO = {
projectId: string;
name: string;
description?: string;
slug: string;
permissions: TPermission[];
};
export type TUpdateProjectRoleDTO = {
projectId: string;
id: string;
} & Partial<Omit<TCreateOrgRoleDTO, "orgId">>;
export type TDeleteProjectRoleDTO = {
projectId: string;
id: string;
};
+3 -3
View File
@@ -196,7 +196,7 @@ export const useToggleAutoCapitalization = () => {
return useMutation<{}, {}, ToggleAutoCapitalizationDTO>({
mutationFn: ({ workspaceID, state }) =>
apiRequest.patch(`/api/v2/workspace/${workspaceID}/auto-capitalization`, {
apiRequest.post(`/api/v1/workspace/${workspaceID}/auto-capitalization`, {
autoCapitalization: state
}),
onSuccess: () => {
@@ -245,7 +245,7 @@ export const useReorderWsEnvironment = () => {
otherEnvironmentSlug,
otherEnvironmentName
}) => {
return apiRequest.patch(`/api/v2/workspace/${workspaceId}/environments`, {
return apiRequest.patch(`/api/v1/workspace/${workspaceId}/environments`, {
environmentSlug,
environmentName,
otherEnvironmentSlug,
@@ -263,7 +263,7 @@ export const useUpdateWsEnvironment = () => {
return useMutation<{}, {}, UpdateEnvironmentDTO>({
mutationFn: ({ workspaceId, id, name, slug }) => {
return apiRequest.put(`/api/v2/workspace/${workspaceId}/environments/${id}`, {
return apiRequest.patch(`/api/v1/workspace/${workspaceId}/environments/${id}`, {
name,
slug
});
+1 -1
View File
@@ -2,7 +2,7 @@ export type Workspace = {
__v: number;
id: string;
name: string;
organization: string;
orgId: string;
autoCapitalization: boolean;
environments: WorkspaceEnv[];
};
+7 -8
View File
@@ -4,7 +4,6 @@
/* eslint-disable vars-on-top */
/* eslint-disable no-var */
/* eslint-disable func-names */
// @ts-nocheck
import crypto from "crypto";
import { useEffect } from "react";
@@ -167,7 +166,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
}
};
const changeOrg = async (orgId) => {
const changeOrg = async (orgId: string) => {
localStorage.setItem("orgData.id", orgId);
router.push(`/org/${orgId}/overview`);
};
@@ -178,15 +177,15 @@ export const AppLayout = ({ children }: LayoutProps) => {
useEffect(() => {
// Put a user in an org if they're not in one yet
const putUserInOrg = async () => {
if (tempLocalStorage("orgData.id") === "") {
localStorage.setItem("orgData.id", orgs[0]?.id);
if (tempLocalStorage("orgData.id") === "" && orgs?.[0]?.id) {
localStorage.setItem("orgData.id", orgs?.[0]?.id);
}
if (
currentOrg &&
((workspaces?.length === 0 && router.asPath.includes("project")) ||
router.asPath.includes("/project/undefined") ||
(!orgs?.map((org) => org.id)?.includes(router.query.id) &&
(!orgs?.map((org) => org.id)?.includes(router.query.id as string) &&
!router.asPath.includes("project") &&
!router.asPath.includes("personal") &&
!router.asPath.includes("integration")))
@@ -320,7 +319,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
size="xs"
className="flex w-full items-center justify-start p-0 font-normal"
leftIcon={
currentOrg.id === org.id && (
currentOrg?.id === org.id && (
<FontAwesomeIcon icon={faCheck} className="mr-3 text-primary" />
)
}
@@ -433,7 +432,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
>
<div className="no-scrollbar::-webkit-scrollbar h-full no-scrollbar">
{workspaces
.filter((ws) => ws.organization === currentOrg?.id)
.filter((ws) => ws.orgId === currentOrg?.id)
.map(({ id, name }) => (
<SelectItem
key={`ws-layout-list-${id}`}
@@ -702,7 +701,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="p-1">
{supportOptions.map(([icon, text, url]) => (
<DropdownMenuItem key={url}>
<DropdownMenuItem key={url as string}>
<a
target="_blank"
rel="noopener noreferrer"
@@ -476,9 +476,8 @@ const OrganizationPage = withPermission(
const { workspaces, isLoading: isWorkspaceLoading } = useWorkspace();
const orgWorkspaces =
workspaces?.filter(
(workspace) => workspace.organization === localStorage.getItem("orgData.id")
) || [];
workspaces?.filter((workspace) => workspace.orgId === localStorage.getItem("orgData.id")) ||
[];
const currentOrg = String(router.query.id);
const { createNotification } = useNotificationContext();
const addWsUser = useAddUserToWs();
@@ -14,7 +14,7 @@ import {
SelectItem
} from "@app/components/v2";
import { useOrganization } from "@app/context";
import { useCreateIdentity, useGetRoles, useUpdateIdentity } from "@app/hooks/api";
import { useCreateIdentity, useGetOrgRoles, useUpdateIdentity } from "@app/hooks/api";
import { IdentityAuthMethod } from "@app/hooks/api/identities";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -46,9 +46,7 @@ export const IdentityModal = ({ popUp, handlePopUpOpen, handlePopUpToggle }: Pro
const { currentOrg } = useOrganization();
const orgId = currentOrg?.id || "";
const { data: roles } = useGetRoles({
orgId
});
const { data: roles } = useGetOrgRoles(orgId);
const { mutateAsync: createMutateAsync } = useCreateIdentity();
const { mutateAsync: updateMutateAsync } = useUpdateIdentity();
@@ -19,7 +19,7 @@ import {
Tr
} from "@app/components/v2";
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
import { useGetIdentityMembershipOrgs, useGetRoles, useUpdateIdentity } from "@app/hooks/api";
import { useGetIdentityMembershipOrgs, useGetOrgRoles, useUpdateIdentity } from "@app/hooks/api";
import { IdentityAuthMethod, identityAuthToNameMap } from "@app/hooks/api/identities";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -51,9 +51,7 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
const { mutateAsync: updateMutateAsync } = useUpdateIdentity();
const { data, isLoading } = useGetIdentityMembershipOrgs(orgId);
const { data: roles } = useGetRoles({
orgId
});
const { data: roles } = useGetOrgRoles(orgId);
const handleChangeRole = async ({ identityId, role }: { identityId: string; role: string }) => {
try {
@@ -32,7 +32,6 @@ import {
useFetchServerStatus,
useGetOrgRoles,
useGetOrgUsers,
useGetRoles,
useUpdateOrgUserRole
} from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -58,6 +57,7 @@ export const OrgMembersTable = ({ handlePopUpOpen, setCompleteInviteLink }: Prop
const orgId = currentOrg?.id || "";
const { data: roles, isLoading: isRolesLoading } = useGetOrgRoles(orgId);
console.log(roles);
const [searchMemberFilter, setSearchMemberFilter] = useState("");
@@ -61,11 +61,11 @@ import {
useUpdateOrgUserRole,
useUploadWsKey
} from "@app/hooks/api";
import { TRole } from "@app/hooks/api/roles/types";
import { TProjectRole } from "@app/hooks/api/roles/types";
import { useFetchServerStatus } from "@app/hooks/api/serverDetails";
type Props = {
roles?: TRole<undefined>[];
roles?: TProjectRole[];
isRolesLoading?: boolean;
};
@@ -10,7 +10,7 @@ import { useOrganization, useWorkspace } from "@app/context";
import {
useAddIdentityToWorkspace,
useGetIdentityMembershipOrgs,
useGetRoles,
useGetProjectRoles,
useGetWorkspaceIdentityMemberships
} from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -40,10 +40,7 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
const { data: identityMembershipOrgs } = useGetIdentityMembershipOrgs(orgId);
const { data: identityMemberships } = useGetWorkspaceIdentityMemberships(workspaceId);
const { data: roles } = useGetRoles({
orgId,
workspaceId
});
const { data: roles } = useGetProjectRoles(workspaceId);
const { mutateAsync: addIdentityToWorkspaceMutateAsync } = useAddIdentityToWorkspace();
@@ -171,7 +168,7 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
<div className="text-sm">
All identities in your organization have already been added to this project.
</div>
<Link href={`/org/${currentWorkspace?.organization}/members`}>
<Link href={`/org/${currentWorkspace?.orgId}/members`}>
<Button variant="outline_bg">Create a new identity</Button>
</Link>
</div>
@@ -18,14 +18,9 @@ import {
THead,
Tr
} from "@app/components/v2";
import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
import {
ProjectPermissionActions,
ProjectPermissionSub,
useOrganization,
useWorkspace
} from "@app/context";
import {
useGetRoles,
useGetProjectRoles,
useGetWorkspaceIdentityMemberships,
useUpdateIdentityWorkspaceRole
} from "@app/hooks/api";
@@ -43,16 +38,11 @@ type Props = {
export const IdentityTable = ({ handlePopUpOpen }: Props) => {
const { createNotification } = useNotificationContext();
const { currentOrg } = useOrganization();
const { currentWorkspace } = useWorkspace();
const orgId = currentOrg?.id || "";
const workspaceId = currentWorkspace?.id || "";
const { data, isLoading } = useGetWorkspaceIdentityMemberships(currentWorkspace?.id || "");
const { data: roles } = useGetRoles({
orgId,
workspaceId
});
const { data: roles } = useGetProjectRoles(workspaceId);
const { mutateAsync: updateMutateAsync } = useUpdateIdentityWorkspaceRole();
@@ -47,7 +47,7 @@ import {
useAddUserToWs,
useDeleteUserFromWorkspace,
useGetOrgUsers,
useGetRoles,
useGetProjectRoles,
useGetUserWsKey,
useGetWorkspaceUsers,
useUpdateUserWorkspaceRole,
@@ -73,10 +73,7 @@ export const MemberListTab = () => {
const orgId = currentOrg?.id || "";
const workspaceId = currentWorkspace?.id || "";
const { data: roles, isLoading: isRolesLoading } = useGetRoles({
orgId,
workspaceId
});
const { data: roles, isLoading: isRolesLoading } = useGetProjectRoles(workspaceId);
const { data: wsKey } = useGetUserWsKey(workspaceId);
const { data: members, isLoading: isMembersLoading } = useGetWorkspaceUsers(workspaceId);
@@ -433,7 +430,7 @@ export const MemberListTab = () => {
) : (
<div className="flex flex-col space-y-4">
<div>All the users in your organization are already invited.</div>
<Link href={`/org/${currentWorkspace?.organization}/members`}>
<Link href={`/org/${currentWorkspace?.orgId}/members`}>
<Button variant="outline_bg">Add users to organization</Button>
</Link>
</div>
@@ -3,7 +3,7 @@ import { motion } from "framer-motion";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
import { withProjectPermission } from "@app/hoc";
import { usePopUp } from "@app/hooks";
import { TRole } from "@app/hooks/api/roles/types";
import { TProjectRole } from "@app/hooks/api/roles/types";
import { ProjectRoleList } from "./components/ProjectRoleList";
import { ProjectRoleModifySection } from "./components/ProjectRoleModifySection";
@@ -21,7 +21,7 @@ export const ProjectRoleListTab = withProjectPermission(
exit={{ opacity: 0, translateX: 30 }}
>
<ProjectRoleModifySection
role={popUp.editRole.data as TRole<string>}
role={popUp.editRole.data as TProjectRole}
onGoBack={() => handlePopUpClose("editRole")}
/>
</motion.div>
@@ -18,42 +18,32 @@ import {
THead,
Tr
} from "@app/components/v2";
import {
ProjectPermissionActions,
ProjectPermissionSub,
useOrganization,
useWorkspace
} from "@app/context";
import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
import { usePopUp } from "@app/hooks";
import { useDeleteRole, useGetRoles } from "@app/hooks/api";
import { TRole } from "@app/hooks/api/roles/types";
import { useDeleteProjectRole, useGetProjectRoles } from "@app/hooks/api";
import { TProjectRole } from "@app/hooks/api/roles/types";
type Props = {
onSelectRole: (role?: TRole<string>) => void;
onSelectRole: (role?: TProjectRole) => void;
};
export const ProjectRoleList = ({ onSelectRole }: Props) => {
const [searchRoles, setSearchRoles] = useState("");
const { createNotification } = useNotificationContext();
const { popUp, handlePopUpOpen, handlePopUpClose } = usePopUp(["deleteRole"] as const);
const { currentOrg } = useOrganization();
const { currentWorkspace } = useWorkspace();
const orgId = currentOrg?.id || "";
const workspaceId = currentWorkspace?.id || "";
const { data: roles, isLoading: isRolesLoading } = useGetRoles({
orgId,
workspaceId
});
const { data: roles, isLoading: isRolesLoading } = useGetProjectRoles(workspaceId);
console.log(roles);
const { mutateAsync: deleteRole } = useDeleteRole();
const { mutateAsync: deleteRole } = useDeleteProjectRole();
const handleRoleDelete = async () => {
const { id } = popUp?.deleteRole?.data as TRole<string>;
const { id } = popUp?.deleteRole?.data as TProjectRole;
try {
await deleteRole({
orgId,
workspaceId,
projectId: workspaceId,
id
});
createNotification({ type: "success", text: "Successfully removed the role" });
@@ -99,7 +89,7 @@ export const ProjectRoleList = ({ onSelectRole }: Props) => {
</THead>
<TBody>
{isRolesLoading && <TableSkeleton columns={4} innerKey="org-roles" />}
{(roles as TRole<string>[])?.map((role) => {
{(roles as TProjectRole[])?.map((role) => {
const { id, name, slug } = role;
const isNonMutatable = ["admin", "member", "viewer", "no-access"].includes(slug);
@@ -157,9 +147,9 @@ export const ProjectRoleList = ({ onSelectRole }: Props) => {
<DeleteActionModal
isOpen={popUp.deleteRole.isOpen}
title={`Are you sure want to delete ${
(popUp?.deleteRole?.data as TRole<string>)?.name || " "
(popUp?.deleteRole?.data as TProjectRole)?.name || " "
} role?`}
deleteKey={(popUp?.deleteRole?.data as TRole<string>)?.slug || ""}
deleteKey={(popUp?.deleteRole?.data as TProjectRole)?.slug || ""}
onClose={() => handlePopUpClose("deleteRole")}
onDeleteApproved={handleRoleDelete}
/>
@@ -20,9 +20,9 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { Button, FormControl, Input } from "@app/components/v2";
import { ProjectPermissionSub, useOrganization, useWorkspace } from "@app/context";
import { useCreateRole, useUpdateRole } from "@app/hooks/api";
import { TRole } from "@app/hooks/api/roles/types";
import { ProjectPermissionSub, useWorkspace } from "@app/context";
import { useCreateProjectRole, useUpdateProjectRole } from "@app/hooks/api";
import { TProjectRole } from "@app/hooks/api/roles/types";
import { MultiEnvProjectPermission } from "./MultiEnvProjectPermission";
import {
@@ -111,7 +111,7 @@ const SINGLE_PERMISSION_LIST = [
] as const;
type Props = {
role?: TRole<string>;
role?: TProjectRole;
onGoBack: VoidFunction;
};
@@ -120,8 +120,6 @@ export const ProjectRoleModifySection = ({ role, onGoBack }: Props) => {
const isNewRole = !role?.slug;
const { createNotification } = useNotificationContext();
const { currentOrg } = useOrganization();
const orgId = currentOrg?.id || "";
const { currentWorkspace } = useWorkspace();
const workspaceId = currentWorkspace?.id || "";
@@ -135,17 +133,16 @@ export const ProjectRoleModifySection = ({ role, onGoBack }: Props) => {
defaultValues: role ? { ...role, permissions: rolePermission2Form(role.permissions) } : {},
resolver: zodResolver(formSchema)
});
const { mutateAsync: createRole } = useCreateRole();
const { mutateAsync: updateRole } = useUpdateRole();
const { mutateAsync: createRole } = useCreateProjectRole();
const { mutateAsync: updateRole } = useUpdateProjectRole();
const handleRoleUpdate = async (el: TFormSchema) => {
if (!role?.id) return;
try {
await updateRole({
orgId,
id: role?.id,
workspaceId,
projectId: workspaceId,
...el,
permissions: formRolePermission2API(el.permissions)
});
@@ -165,8 +162,7 @@ export const ProjectRoleModifySection = ({ role, onGoBack }: Props) => {
try {
await createRole({
orgId,
workspaceId,
projectId: workspaceId,
...el,
permissions: formRolePermission2API(el.permissions)
});
@@ -33,7 +33,7 @@ export const formSchema = z.object({
.object({
secrets: z.record(multiEnvPermissionSchema).optional(),
member: generalPermissionSchema,
"identity": generalPermissionSchema,
identity: generalPermissionSchema,
role: generalPermissionSchema,
integrations: generalPermissionSchema,
webhooks: generalPermissionSchema,
@@ -90,7 +90,10 @@ export const rolePermission2Form = (permissions: TProjectPermission[] = []) => {
const formVal: Record<string, any> = {};
permissions.forEach((permission) => {
const { subject, action } = permission;
const {
subject: [subject],
action
} = permission;
if (!formVal?.[subject]) formVal[subject] = {};
if (subject === "secrets") {
@@ -93,7 +93,7 @@ export const EnvironmentTable = ({ handlePopUpOpen }: Props) => {
{!isLoading &&
currentWorkspace &&
currentWorkspace.environments.map(({ name, slug, id }, pos) => (
<Tr key={name}>
<Tr key={id}>
<Td>{name}</Td>
<Td>{slug}</Td>
<Td className="flex items-center justify-end">
@@ -15,8 +15,8 @@ type Props = {
};
const schema = yup.object({
environmentName: yup.string().label("Environment Name").required(),
environmentSlug: yup.string().label("Environment Slug").required()
name: yup.string().label("Environment Name").required(),
slug: yup.string().label("Environment Slug").required()
});
export type FormData = yup.InferType<typeof schema>;
@@ -26,19 +26,20 @@ export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpTog
const { currentWorkspace } = useWorkspace();
const { mutateAsync, isLoading } = useUpdateWsEnvironment();
const { control, handleSubmit, reset } = useForm<FormData>({
resolver: yupResolver(schema)
resolver: yupResolver(schema),
values: popUp.updateEnv.data as FormData
});
const oldEnvId = (popUp?.updateEnv?.data as { id: string })?.id;
const onFormSubmit = async ({ environmentName, environmentSlug }: FormData) => {
const onFormSubmit = async ({ name, slug }: FormData) => {
try {
if (!currentWorkspace?.id) return;
await mutateAsync({
workspaceId: currentWorkspace.id,
name: environmentName,
slug: environmentSlug,
name,
slug,
id: oldEnvId
});
@@ -70,7 +71,7 @@ export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpTog
<Controller
control={control}
defaultValue=""
name="environmentName"
name="name"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Environment Name"
@@ -84,7 +85,7 @@ export const UpdateEnvironmentModal = ({ popUp, handlePopUpClose, handlePopUpTog
<Controller
control={control}
defaultValue=""
name="environmentSlug"
name="slug"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Environment Slug"