From f010a3a932da8fdbee5610c9b56e144f92b6f822 Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Sun, 28 Jan 2024 23:13:31 +0530 Subject: [PATCH] feat: changed blind index banner for everyone --- .../secret-blind-index-service.ts | 5 +---- .../permissions/ProjectPermissionCan.tsx | 2 +- .../ProjectPermissionContext.tsx | 6 +++++- .../withProjectPermission.tsx | 8 ++++---- frontend/src/hooks/api/roles/queries.tsx | 13 ++++++++----- frontend/src/hooks/api/users/types.ts | 9 +++++++++ .../CloudIntegrationSection.tsx | 4 ++-- .../SecretApprovalPolicyList.tsx | 2 +- .../components/SecretApprovalPolicyRow.tsx | 2 +- .../src/views/SecretMainPage/SecretMainPage.tsx | 2 +- .../SecretListView/SecretDetaiSidebar.tsx | 2 +- .../components/SecretListView/SecretItem.tsx | 2 +- .../ProjectIndexSecretsSection.tsx | 16 +++++++++++++--- .../SecretRotationPage/SecretRotationPage.tsx | 2 +- .../EnvironmentSection/EnvironmentSection.tsx | 4 ++-- .../SecretTagsSection/SecretTagsSection.tsx | 17 +++++++++++------ 16 files changed, 62 insertions(+), 34 deletions(-) diff --git a/backend/src/services/secret-blind-index/secret-blind-index-service.ts b/backend/src/services/secret-blind-index/secret-blind-index-service.ts index 215e54992..0c18ddedc 100644 --- a/backend/src/services/secret-blind-index/secret-blind-index-service.ts +++ b/backend/src/services/secret-blind-index/secret-blind-index-service.ts @@ -29,10 +29,7 @@ export const secretBlindIndexServiceFactory = ({ projectId, actorId }: TGetProjectBlindIndexStatusDTO) => { - const { membership } = await permissionService.getProjectPermission(actor, actorId, projectId); - if (membership?.role !== ProjectMembershipRole.Admin) { - throw new UnauthorizedError({ message: "User must be admin" }); - } + await permissionService.getProjectPermission(actor, actorId, projectId); const secretCount = await secretBlindIndexDAL.countOfSecretsWithNullSecretBlindIndex(projectId); return Number(secretCount); diff --git a/frontend/src/components/permissions/ProjectPermissionCan.tsx b/frontend/src/components/permissions/ProjectPermissionCan.tsx index aa64c33d7..f1af141f2 100644 --- a/frontend/src/components/permissions/ProjectPermissionCan.tsx +++ b/frontend/src/components/permissions/ProjectPermissionCan.tsx @@ -25,7 +25,7 @@ export const ProjectPermissionCan: FunctionComponent = ({ allowedLabel, ...props }) => { - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); return ( {(isAllowed, ability) => { diff --git a/frontend/src/context/ProjectPermissionContext/ProjectPermissionContext.tsx b/frontend/src/context/ProjectPermissionContext/ProjectPermissionContext.tsx index cb6ef9b97..a7023a867 100644 --- a/frontend/src/context/ProjectPermissionContext/ProjectPermissionContext.tsx +++ b/frontend/src/context/ProjectPermissionContext/ProjectPermissionContext.tsx @@ -1,6 +1,7 @@ import { createContext, ReactNode, useContext } from "react"; import { useGetUserProjectPermissions } from "@app/hooks/api"; +import { TProjectMembership } from "@app/hooks/api/users/types"; import { useWorkspace } from "../WorkspaceContext"; import { TProjectPermission } from "./types"; @@ -9,7 +10,10 @@ type Props = { children: ReactNode; }; -const ProjectPermissionContext = createContext(null); +const ProjectPermissionContext = createContext(null); export const ProjectPermissionProvider = ({ children }: Props): JSX.Element => { const { currentWorkspace, isLoading: isWsLoading } = useWorkspace(); diff --git a/frontend/src/hoc/withProjectPermission/withProjectPermission.tsx b/frontend/src/hoc/withProjectPermission/withProjectPermission.tsx index 911703973..103ff61b7 100644 --- a/frontend/src/hoc/withProjectPermission/withProjectPermission.tsx +++ b/frontend/src/hoc/withProjectPermission/withProjectPermission.tsx @@ -21,7 +21,7 @@ export const withProjectPermission = ["abilities"]> ) => { const HOC = (hocProps: T) => { - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); // akhilmhdh: Set as any due to casl/react ts type bug // REASON: casl due to its type checking can't seem to union even if union intersection is applied @@ -29,13 +29,13 @@ export const withProjectPermission =
@@ -43,7 +43,7 @@ export const withProjectPermission =
-
Permission Denied
+
Permission Denied
You do not have permission to this page.
Kindly contact your organization administrator diff --git a/frontend/src/hooks/api/roles/queries.tsx b/frontend/src/hooks/api/roles/queries.tsx index 38d020491..8647353cb 100644 --- a/frontend/src/hooks/api/roles/queries.tsx +++ b/frontend/src/hooks/api/roles/queries.tsx @@ -8,7 +8,7 @@ import { apiRequest } from "@app/config/request"; import { OrgPermissionSet } from "@app/context/OrgPermissionContext/types"; import { ProjectPermissionSet } from "@app/context/ProjectPermissionContext/types"; -import { OrgUser } from "../users/types"; +import { OrgUser, TProjectMembership } from "../users/types"; import { TGetUserOrgPermissionsDTO, TGetUserProjectPermissionDTO, @@ -104,10 +104,13 @@ export const useGetUserOrgPermissions = ({ orgId }: TGetUserOrgPermissionsDTO) = const getUserProjectPermissions = async ({ workspaceId }: TGetUserProjectPermissionDTO) => { const { data } = await apiRequest.get<{ - data: { permissions: PackRule>>[] }; + data: { + permissions: PackRule>>[]; + membership: TProjectMembership; + }; }>(`/api/v1/workspace/${workspaceId}/permissions`, {}); - return data.data.permissions; + return data.data; }; export const useGetUserProjectPermissions = ({ workspaceId }: TGetUserProjectPermissionDTO) => @@ -116,8 +119,8 @@ export const useGetUserProjectPermissions = ({ workspaceId }: TGetUserProjectPer queryFn: () => getUserProjectPermissions({ workspaceId }), enabled: Boolean(workspaceId), select: (data) => { - const rule = unpackRules>>(data); + const rule = unpackRules>>(data.permissions); const ability = createMongoAbility(rule, { conditionsMatcher }); - return ability; + return { permission: ability, membership: data.membership }; } }); diff --git a/frontend/src/hooks/api/users/types.ts b/frontend/src/hooks/api/users/types.ts index 47c733885..ebddefb14 100644 --- a/frontend/src/hooks/api/users/types.ts +++ b/frontend/src/hooks/api/users/types.ts @@ -52,6 +52,15 @@ export type OrgUser = { roleId: string; }; +export type TProjectMembership = { + id: string; + role: string; + createdAt: string; + updatedAt: string; + projectId: string; + roleId: string; +}; + export type TWorkspaceUser = OrgUser; export type AddUserToWsDTO = { diff --git a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx index b0abc2603..a1b9787dd 100644 --- a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx +++ b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx @@ -30,7 +30,7 @@ export const CloudIntegrationSection = ({ const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "deleteConfirmation" ] as const); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); const { createNotification } = useNotificationContext(); const isEmpty = !isLoading && !cloudIntegrations?.length; @@ -43,7 +43,7 @@ export const CloudIntegrationSection = ({

{t("integrations.cloud-integrations")}

{t("integrations.click-to-start")}

-
+
{isLoading && Array.from({ length: 12 }).map((_, index) => ( diff --git a/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/SecretApprovalPolicyList.tsx b/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/SecretApprovalPolicyList.tsx index 27f649bdd..11927a2b1 100644 --- a/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/SecretApprovalPolicyList.tsx +++ b/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/SecretApprovalPolicyList.tsx @@ -44,7 +44,7 @@ export const SecretApprovalPolicyList = ({ workspaceId }: Props) => { "deletePolicy", "upgradePlan" ] as const); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); const { subscription } = useSubscription(); const { createNotification } = useNotificationContext(); diff --git a/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/components/SecretApprovalPolicyRow.tsx b/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/components/SecretApprovalPolicyRow.tsx index 072156b61..c256af1c7 100644 --- a/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/components/SecretApprovalPolicyRow.tsx +++ b/frontend/src/views/SecretApprovalPage/components/SecretApprovalPolicyList/components/SecretApprovalPolicyRow.tsx @@ -36,7 +36,7 @@ export const SecretApprovalPolicyRow = ({ }: Props) => { const [selectedApprovers, setSelectedApprovers] = useState([]); const { mutate: updateSecretApprovalPolicy, isLoading } = useUpdateSecretApprovalPolicy(); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); return ( diff --git a/frontend/src/views/SecretMainPage/SecretMainPage.tsx b/frontend/src/views/SecretMainPage/SecretMainPage.tsx index d3c1a5b93..f538a4c0a 100644 --- a/frontend/src/views/SecretMainPage/SecretMainPage.tsx +++ b/frontend/src/views/SecretMainPage/SecretMainPage.tsx @@ -48,7 +48,7 @@ export const SecretMainPage = () => { const { t } = useTranslation(); const { currentWorkspace } = useWorkspace(); const router = useRouter(); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); const [isVisible, setIsVisible] = useState(false); const [sortDir, setSortDir] = useState(SortDir.ASC); diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx index a86a6b096..1130c9d14 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/SecretDetaiSidebar.tsx @@ -81,7 +81,7 @@ export const SecretDetailSidebar = ({ resolver: zodResolver(formSchema), values: secret }); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); const cannotEditSecret = permission.cannot( ProjectPermissionActions.Edit, subject(ProjectPermissionSub.Secrets, { environment, secretPath }) diff --git a/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx b/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx index aec0573ef..ecd35abf8 100644 --- a/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx +++ b/frontend/src/views/SecretMainPage/components/SecretListView/SecretItem.tsx @@ -85,7 +85,7 @@ export const SecretItem = memo( secretPath }: Props) => { const { currentWorkspace } = useWorkspace(); - const permission = useProjectPermission(); + const { permission } = useProjectPermission(); const isReadOnly = permission.can( ProjectPermissionActions.Read, diff --git a/frontend/src/views/SecretOverviewPage/components/ProjectIndexSecretsSection/ProjectIndexSecretsSection.tsx b/frontend/src/views/SecretOverviewPage/components/ProjectIndexSecretsSection/ProjectIndexSecretsSection.tsx index 2210171b0..bbc2fb49a 100644 --- a/frontend/src/views/SecretOverviewPage/components/ProjectIndexSecretsSection/ProjectIndexSecretsSection.tsx +++ b/frontend/src/views/SecretOverviewPage/components/ProjectIndexSecretsSection/ProjectIndexSecretsSection.tsx @@ -4,9 +4,15 @@ import { decryptSymmetric } from "@app/components/utilities/cryptography/crypto"; import { Button, Spinner } from "@app/components/v2"; -import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context"; +import { + ProjectPermissionActions, + ProjectPermissionSub, + useProjectPermission, + useWorkspace +} from "@app/context"; import { useToggle } from "@app/hooks"; import { useGetWorkspaceIndexStatus, useNameWorkspaceSecrets } from "@app/hooks/api"; +import { ProjectMembershipRole } from "@app/hooks/api/roles/types"; import { UserWsKeyPair } from "@app/hooks/api/types"; import { fetchWorkspaceSecrets } from "@app/hooks/api/workspace/queries"; @@ -18,6 +24,7 @@ type Props = { export const ProjectIndexSecretsSection = ({ decryptFileKey }: Props) => { const { currentWorkspace } = useWorkspace(); + const { membership } = useProjectPermission(); const { data: isBlindIndexed, isLoading: isBlindIndexedLoading } = useGetWorkspaceIndexStatus( currentWorkspace?.id ?? "" ); @@ -78,13 +85,16 @@ export const ProjectIndexSecretsSection = ({ decryptFileKey }: Props) => {

Your project was created before the introduction of blind indexing. To continue accessing secrets by name through the SDK, public API and web dashboard, please enable blind indexing.{" "} - This is a one time process. + + This is a one time process.{" "} + {membership.role !== ProjectMembershipRole.Admin && "Admin only operation"} +

{(isAllowed) => (