forked from github/plane
chore: cycle and module sidebar permission validation (#3095)
This commit is contained in:
parent
fe80ca3e1c
commit
b4f51cb5af
@ -30,6 +30,8 @@ import {
|
|||||||
} from "helpers/date-time.helper";
|
} from "helpers/date-time.helper";
|
||||||
// types
|
// types
|
||||||
import { ICycle } from "types";
|
import { ICycle } from "types";
|
||||||
|
// constants
|
||||||
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { CYCLE_STATUS } from "constants/cycle";
|
import { CYCLE_STATUS } from "constants/cycle";
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
const {
|
const {
|
||||||
cycle: cycleDetailsStore,
|
cycle: cycleDetailsStore,
|
||||||
trackEvent: { setTrackElement },
|
trackEvent: { setTrackElement },
|
||||||
|
user: { currentProjectRole },
|
||||||
} = useMobxStore();
|
} = useMobxStore();
|
||||||
|
|
||||||
const cycleDetails = cycleDetailsStore.cycle_details[cycleId] ?? undefined;
|
const cycleDetails = cycleDetailsStore.cycle_details[cycleId] ?? undefined;
|
||||||
@ -286,6 +289,8 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
: `${cycleDetails.total_issues}`
|
: `${cycleDetails.total_issues}`
|
||||||
: `${cycleDetails.completed_issues}/${cycleDetails.total_issues}`;
|
: `${cycleDetails.completed_issues}/${cycleDetails.total_issues}`;
|
||||||
|
|
||||||
|
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserWorkspaceRoles.MEMBER;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{cycleDetails && workspaceSlug && projectId && (
|
{cycleDetails && workspaceSlug && projectId && (
|
||||||
@ -312,7 +317,7 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<button onClick={handleCopyText}>
|
<button onClick={handleCopyText}>
|
||||||
<LinkIcon className="h-3 w-3 text-custom-text-300" />
|
<LinkIcon className="h-3 w-3 text-custom-text-300" />
|
||||||
</button>
|
</button>
|
||||||
{!isCompleted && (
|
{!isCompleted && isEditingAllowed && (
|
||||||
<CustomMenu width="lg" placement="bottom-end" ellipsis>
|
<CustomMenu width="lg" placement="bottom-end" ellipsis>
|
||||||
<CustomMenu.MenuItem
|
<CustomMenu.MenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@ -349,8 +354,10 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<div className="relative flex h-full w-52 items-center gap-2.5">
|
<div className="relative flex h-full w-52 items-center gap-2.5">
|
||||||
<Popover className="flex h-full items-center justify-center rounded-lg">
|
<Popover className="flex h-full items-center justify-center rounded-lg">
|
||||||
<Popover.Button
|
<Popover.Button
|
||||||
disabled={isCompleted ?? false}
|
className={`text-sm font-medium text-custom-text-300 ${
|
||||||
className="cursor-default text-sm font-medium text-custom-text-300"
|
isEditingAllowed ? "cursor-default" : "cursor-not-allowed"
|
||||||
|
}`}
|
||||||
|
disabled={isCompleted || !isEditingAllowed}
|
||||||
>
|
>
|
||||||
{areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")}
|
{areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")}
|
||||||
</Popover.Button>
|
</Popover.Button>
|
||||||
@ -385,8 +392,10 @@ export const CycleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<Popover className="flex h-full items-center justify-center rounded-lg">
|
<Popover className="flex h-full items-center justify-center rounded-lg">
|
||||||
<>
|
<>
|
||||||
<Popover.Button
|
<Popover.Button
|
||||||
disabled={isCompleted ?? false}
|
className={`text-sm font-medium text-custom-text-300 ${
|
||||||
className="cursor-default text-sm font-medium text-custom-text-300"
|
isEditingAllowed ? "cursor-default" : "cursor-not-allowed"
|
||||||
|
}`}
|
||||||
|
disabled={isCompleted ?? !isEditingAllowed}
|
||||||
>
|
>
|
||||||
{areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")}
|
{areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")}
|
||||||
</Popover.Button>
|
</Popover.Button>
|
||||||
|
@ -261,6 +261,8 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
: `${moduleDetails.total_issues}`
|
: `${moduleDetails.total_issues}`
|
||||||
: `${moduleDetails.completed_issues}/${moduleDetails.total_issues}`;
|
: `${moduleDetails.completed_issues}/${moduleDetails.total_issues}`;
|
||||||
|
|
||||||
|
const isEditingAllowed = !!userRole && userRole >= EUserWorkspaceRoles.MEMBER;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LinkModal
|
<LinkModal
|
||||||
@ -290,6 +292,7 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<button onClick={handleCopyText}>
|
<button onClick={handleCopyText}>
|
||||||
<LinkIcon className="h-3 w-3 text-custom-text-300" />
|
<LinkIcon className="h-3 w-3 text-custom-text-300" />
|
||||||
</button>
|
</button>
|
||||||
|
{isEditingAllowed && (
|
||||||
<CustomMenu width="lg" placement="bottom-end" ellipsis>
|
<CustomMenu width="lg" placement="bottom-end" ellipsis>
|
||||||
<CustomMenu.MenuItem onClick={() => setModuleDeleteModal(true)}>
|
<CustomMenu.MenuItem onClick={() => setModuleDeleteModal(true)}>
|
||||||
<span className="flex items-center justify-start gap-2">
|
<span className="flex items-center justify-start gap-2">
|
||||||
@ -298,6 +301,7 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
</span>
|
</span>
|
||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
</CustomMenu>
|
</CustomMenu>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -311,7 +315,9 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<CustomSelect
|
<CustomSelect
|
||||||
customButton={
|
customButton={
|
||||||
<span
|
<span
|
||||||
className="flex h-6 w-20 cursor-default items-center justify-center rounded-sm text-center text-xs"
|
className={`flex h-6 w-20 items-center justify-center rounded-sm text-center text-xs ${
|
||||||
|
isEditingAllowed ? "cursor-default" : "cursor-not-allowed"
|
||||||
|
}`}
|
||||||
style={{
|
style={{
|
||||||
color: moduleStatus ? moduleStatus.color : "#a3a3a2",
|
color: moduleStatus ? moduleStatus.color : "#a3a3a2",
|
||||||
backgroundColor: moduleStatus ? `${moduleStatus.color}20` : "#a3a3a220",
|
backgroundColor: moduleStatus ? `${moduleStatus.color}20` : "#a3a3a220",
|
||||||
@ -324,6 +330,7 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
onChange={(value: any) => {
|
onChange={(value: any) => {
|
||||||
submitChanges({ status: value });
|
submitChanges({ status: value });
|
||||||
}}
|
}}
|
||||||
|
disabled={!isEditingAllowed}
|
||||||
>
|
>
|
||||||
{MODULE_STATUS.map((status) => (
|
{MODULE_STATUS.map((status) => (
|
||||||
<CustomSelect.Option key={status.value} value={status.value}>
|
<CustomSelect.Option key={status.value} value={status.value}>
|
||||||
@ -339,7 +346,12 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
<div className="relative flex h-full w-52 items-center gap-2.5">
|
<div className="relative flex h-full w-52 items-center gap-2.5">
|
||||||
<Popover className="flex h-full items-center justify-center rounded-lg">
|
<Popover className="flex h-full items-center justify-center rounded-lg">
|
||||||
<Popover.Button className="cursor-default text-sm font-medium text-custom-text-300">
|
<Popover.Button
|
||||||
|
className={`text-sm font-medium text-custom-text-300 ${
|
||||||
|
isEditingAllowed ? "cursor-default" : "cursor-not-allowed"
|
||||||
|
}`}
|
||||||
|
disabled={!isEditingAllowed}
|
||||||
|
>
|
||||||
{areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")}
|
{areYearsEqual ? renderShortDate(startDate, "_ _") : renderShortMonthDate(startDate, "_ _")}
|
||||||
</Popover.Button>
|
</Popover.Button>
|
||||||
|
|
||||||
@ -371,7 +383,12 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<MoveRight className="h-4 w-4 text-custom-text-300" />
|
<MoveRight className="h-4 w-4 text-custom-text-300" />
|
||||||
<Popover className="flex h-full items-center justify-center rounded-lg">
|
<Popover className="flex h-full items-center justify-center rounded-lg">
|
||||||
<>
|
<>
|
||||||
<Popover.Button className="cursor-default text-sm font-medium text-custom-text-300">
|
<Popover.Button
|
||||||
|
className={`text-sm font-medium text-custom-text-300 ${
|
||||||
|
isEditingAllowed ? "cursor-default" : "cursor-not-allowed"
|
||||||
|
}`}
|
||||||
|
disabled={!isEditingAllowed}
|
||||||
|
>
|
||||||
{areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")}
|
{areYearsEqual ? renderShortDate(endDate, "_ _") : renderShortMonthDate(endDate, "_ _")}
|
||||||
</Popover.Button>
|
</Popover.Button>
|
||||||
|
|
||||||
@ -553,6 +570,7 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
<div className="mt-2 flex h-72 w-full flex-col space-y-3 overflow-y-auto">
|
<div className="mt-2 flex h-72 w-full flex-col space-y-3 overflow-y-auto">
|
||||||
{userRole && moduleDetails.link_module && moduleDetails.link_module.length > 0 ? (
|
{userRole && moduleDetails.link_module && moduleDetails.link_module.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
|
{isEditingAllowed && (
|
||||||
<div className="flex w-full items-center justify-end">
|
<div className="flex w-full items-center justify-end">
|
||||||
<button
|
<button
|
||||||
className="flex items-center gap-1.5 text-sm font-medium text-custom-primary-100"
|
className="flex items-center gap-1.5 text-sm font-medium text-custom-primary-100"
|
||||||
@ -562,6 +580,7 @@ export const ModuleDetailsSidebar: React.FC<Props> = observer((props) => {
|
|||||||
Add link
|
Add link
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<LinksList
|
<LinksList
|
||||||
links={moduleDetails.link_module}
|
links={moduleDetails.link_module}
|
||||||
|
Loading…
Reference in New Issue
Block a user