Skip to content

Commit fe2d854

Browse files
anmolsinghbhatialifeiscontent
authored andcommitted
[WEB-3410] fix: work item permission and validation (#6621)
* fix: work item permission and validation * fix: command palette * chore: code refactor
1 parent dce45c5 commit fe2d854

File tree

9 files changed

+47
-29
lines changed

9 files changed

+47
-29
lines changed

web/ce/components/command-palette/modals/issue-level.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,22 @@ import useSWR from "swr";
55
import { BulkDeleteIssuesModal } from "@/components/core";
66
import { CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues";
77
// constants
8-
import { ISSUE_DETAILS } from "@/constants/fetch-keys";
98
// hooks
10-
import { useCommandPalette, useUser } from "@/hooks/store";
9+
import { useCommandPalette, useIssueDetail, useUser } from "@/hooks/store";
1110
import { useAppRouter } from "@/hooks/use-app-router";
1211
import { useIssuesStore } from "@/hooks/use-issue-layout-store";
13-
// services
14-
import { IssueService } from "@/services/issue";
15-
16-
// services
17-
const issueService = new IssueService();
1812

1913
export const IssueLevelModals = observer(() => {
2014
// router
2115
const pathname = usePathname();
22-
const { workspaceSlug, projectId, issueId, cycleId, moduleId } = useParams();
16+
const { workspaceSlug, projectId: paramsProjectId, workItem, cycleId, moduleId } = useParams();
2317
const router = useAppRouter();
2418
// store hooks
2519
const { data: currentUser } = useUser();
2620
const {
2721
issues: { removeIssue },
2822
} = useIssuesStore();
23+
const { fetchIssueWithIdentifier } = useIssueDetail();
2924
const {
3025
isCreateIssueModalOpen,
3126
toggleCreateIssueModal,
@@ -37,13 +32,19 @@ export const IssueLevelModals = observer(() => {
3732
// derived values
3833
const isDraftIssue = pathname?.includes("draft-issues") || false;
3934

35+
const projectIdentifier = workItem?.toString().split("-")[0];
36+
const sequence_id = workItem?.toString().split("-")[1];
37+
4038
const { data: issueDetails } = useSWR(
41-
workspaceSlug && projectId && issueId ? ISSUE_DETAILS(issueId as string) : null,
42-
workspaceSlug && projectId && issueId
43-
? () => issueService.retrieve(workspaceSlug as string, projectId as string, issueId as string)
39+
workspaceSlug && workItem ? `ISSUE_DETAIL_${workspaceSlug}_${projectIdentifier}_${sequence_id}` : null,
40+
workspaceSlug && workItem
41+
? () => fetchIssueWithIdentifier(workspaceSlug.toString(), projectIdentifier, sequence_id)
4442
: null
4543
);
4644

45+
const issueId = issueDetails?.id;
46+
const projectId = paramsProjectId ?? issueDetails?.project_id;
47+
4748
return (
4849
<>
4950
<CreateUpdateIssueModal

web/core/components/command-palette/actions/issue-actions/actions-list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ type Props = {
2424
export const CommandPaletteIssueActions: React.FC<Props> = observer((props) => {
2525
const { closePalette, issueDetails, pages, setPages, setPlaceholder, setSearchTerm } = props;
2626
// router
27-
const { workspaceSlug, projectId, issueId } = useParams();
27+
const { workspaceSlug } = useParams();
2828
// hooks
2929
const { updateIssue } = useIssueDetail();
3030
const { toggleCommandPaletteModal, toggleDeleteIssueModal } = useCommandPalette();
3131
const { data: currentUser } = useUser();
32+
// derived values
33+
const issueId = issueDetails?.id;
34+
const projectId = issueDetails?.project_id;
3235

3336
const handleUpdateIssue = async (formData: Partial<TIssue>) => {
3437
if (!workspaceSlug || !projectId || !issueDetails) return;

web/core/components/command-palette/actions/issue-actions/change-assignee.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ type Props = { closePalette: () => void; issue: TIssue };
1818
export const ChangeIssueAssignee: React.FC<Props> = observer((props) => {
1919
const { closePalette, issue } = props;
2020
// router params
21-
const { workspaceSlug, projectId } = useParams();
21+
const { workspaceSlug } = useParams();
2222
// store
2323
const { updateIssue } = useIssueDetail();
2424
const {
25-
project: { projectMemberIds, getProjectMemberDetails },
25+
project: { getProjectMemberIds, getProjectMemberDetails },
2626
} = useMember();
27+
// derived values
28+
const projectId = issue?.project_id ?? "";
29+
const projectMemberIds = getProjectMemberIds(projectId);
2730

2831
const options =
2932
projectMemberIds

web/core/components/command-palette/actions/issue-actions/change-priority.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ type Props = { closePalette: () => void; issue: TIssue };
2020
export const ChangeIssuePriority: React.FC<Props> = observer((props) => {
2121
const { closePalette, issue } = props;
2222
// router params
23-
const { workspaceSlug, projectId } = useParams();
23+
const { workspaceSlug } = useParams();
24+
// store hooks
2425
const { updateIssue } = useIssueDetail();
26+
// derived values
27+
const projectId = issue?.project_id;
2528

2629
const submitChanges = async (formData: Partial<TIssue>) => {
2730
if (!workspaceSlug || !projectId || !issue) return;

web/core/components/command-palette/actions/issue-actions/change-state.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ type Props = { closePalette: () => void; issue: TIssue };
1717
export const ChangeIssueState: React.FC<Props> = observer((props) => {
1818
const { closePalette, issue } = props;
1919
// router params
20-
const { workspaceSlug, projectId } = useParams();
20+
const { workspaceSlug } = useParams();
2121
// store hooks
2222
const { updateIssue } = useIssueDetail();
23-
const { projectStates } = useProjectState();
23+
const { getProjectStates } = useProjectState();
24+
// derived values
25+
const projectId = issue?.project_id;
26+
const projectStates = getProjectStates(projectId);
2427

2528
const submitChanges = async (formData: Partial<TIssue>) => {
2629
if (!workspaceSlug || !projectId || !issue) return;

web/core/components/command-palette/command-palette.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
export const CommandPalette: FC = observer(() => {
3232
// router params
33-
const { workspaceSlug, projectId, issueId } = useParams();
33+
const { workspaceSlug, projectId, workItem } = useParams();
3434
// store hooks
3535
const { toggleSidebar } = useAppTheme();
3636
const { setTrackElement } = useEventTracker();
@@ -51,7 +51,7 @@ export const CommandPalette: FC = observer(() => {
5151
const canPerformProjectAdminActions = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT);
5252

5353
const copyIssueUrlToClipboard = useCallback(() => {
54-
if (!issueId) return;
54+
if (!workItem) return;
5555

5656
const url = new URL(window.location.href);
5757
copyTextToClipboard(url.href)
@@ -67,7 +67,7 @@ export const CommandPalette: FC = observer(() => {
6767
title: "Some error occurred",
6868
});
6969
});
70-
}, [issueId]);
70+
}, [workItem]);
7171

7272
// auth
7373
const performProjectCreateActions = useCallback(

web/core/components/issues/delete-issue-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useEffect, useState } from "react";
44
// types
5-
import { PROJECT_ERROR_MESSAGES ,EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
5+
import { PROJECT_ERROR_MESSAGES, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
66
import { useTranslation } from "@plane/i18n";
77
import { TDeDupeIssue, TIssue } from "@plane/types";
88
// ui

web/core/components/issues/issue-detail/issue-activity/activity/actions/label.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ export const IssueLabelActivity: FC<TIssueLabelActivity> = observer((props) => {
1414
const {
1515
activity: { getActivityById },
1616
} = useIssueDetail();
17-
const { projectLabels } = useLabel();
17+
const { getLabelById } = useLabel();
1818

1919
const activity = getActivityById(activityId);
20+
const oldLabelColor = getLabelById(activity?.old_identifier ?? "")?.color;
21+
const newLabelColor = getLabelById(activity?.new_identifier ?? "")?.color;
2022

2123
if (!activity) return <></>;
2224
return (
@@ -29,11 +31,7 @@ export const IssueLabelActivity: FC<TIssueLabelActivity> = observer((props) => {
2931
{activity.old_value === "" ? `added a new label ` : `removed the label `}
3032
<LabelActivityChip
3133
name={activity.old_value === "" ? activity.new_value : activity.old_value}
32-
color={
33-
activity.old_value === ""
34-
? projectLabels?.find((l) => l.id === activity.new_identifier)?.color
35-
: projectLabels?.find((l) => l.id === activity.old_identifier)?.color
36-
}
34+
color={activity.old_value === "" ? newLabelColor : oldLabelColor}
3735
/>
3836
{showIssue && (activity.old_value === "" ? ` to ` : ` from `)}
3937
{showIssue && <IssueLink activityId={activityId} />}

web/core/components/issues/issue-detail/issue-detail-quick-actions.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,17 @@ export const IssueDetailQuickActions: FC<Props> = observer((props) => {
170170
};
171171

172172
// auth
173-
const isEditable = allowPermissions([EUserPermissions.ADMIN, EUserPermissions.MEMBER], EUserPermissionsLevel.PROJECT);
173+
const isEditable = allowPermissions(
174+
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
175+
EUserPermissionsLevel.PROJECT,
176+
workspaceSlug,
177+
projectId
178+
);
174179
const canRestoreIssue = allowPermissions(
175180
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
176-
EUserPermissionsLevel.PROJECT
181+
EUserPermissionsLevel.PROJECT,
182+
workspaceSlug,
183+
projectId
177184
);
178185
const isArchivingAllowed = !issue?.archived_at && isEditable;
179186
const isInArchivableGroup = !!stateDetails && ARCHIVABLE_STATE_GROUPS.includes(stateDetails?.group);

0 commit comments

Comments
 (0)