[WEB-2189] fix: issue peek overview and issue detail unauthorised delete action#5341
Conversation
WalkthroughThe recent changes enhance the asynchronous handling of issue deletion across multiple components, improving control flow and user experience. By restructuring promise chains, these adjustments ensure that subsequent actions—such as event capturing and state updates—occur only after successful deletions. This approach increases code reliability, readability, and maintainability, while also implementing user permission checks to prevent unauthorized actions. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant IssueOperations
participant EventCapture
participant StateManagement
participant PermissionCheck
User->>IssueOperations: Request to remove issue
PermissionCheck->>User: Check permissions
alt Authorized
IssueOperations-->>User: Remove issue
IssueOperations->>EventCapture: Capture removal event
EventCapture-->>IssueOperations: Event captured
IssueOperations->>StateManagement: Update state
StateManagement-->>IssueOperations: State updated
else Unauthorized
PermissionCheck-->>User: Notify permission error
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- web/core/components/issues/issue-detail-widgets/relations/helper.tsx (1 hunks)
- web/core/components/issues/issue-detail-widgets/sub-issues/helper.tsx (1 hunks)
- web/core/components/issues/issue-detail/issue-detail-quick-actions.tsx (1 hunks)
- web/core/components/issues/peek-overview/root.tsx (3 hunks)
- web/core/components/issues/peek-overview/view.tsx (1 hunks)
Additional context used
Biome
web/core/components/issues/peek-overview/root.tsx
[error] 50-50: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (4)
web/core/components/issues/issue-detail-widgets/relations/helper.tsx (1)
73-78: LGTM! Verify the function usage in the codebase.The restructuring of the
removefunction to use a promise chain improves the control flow and readability. Ensure that all usages ofremovein the codebase are correctly handling the promise.Verification successful
Promise Handling Verified for
issueOperations.removeThe usages of
issueOperations.removein the codebase correctly handle the promise withawait, ensuring proper asynchronous control flow.
web/core/components/issues/peek-overview/view.tsxweb/core/components/issues/issue-detail-widgets/relations/content.tsxScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `remove` match the expected usage pattern. # Test: Search for the function usage. Expect: Proper handling of the promise chain. rg --type javascript -A 5 $'remove($_, $_, $_)'Length of output: 83
Script:
#!/bin/bash # Description: Verify all function calls to `remove` match the expected usage pattern. # Test: Search for the function usage in the codebase. Expect: Proper handling of the promise chain. rg -A 5 'remove('Length of output: 84
Script:
#!/bin/bash # Description: Verify all function calls to `remove` match the expected usage pattern. # Test: Search for the function usage in the codebase. Expect: Proper handling of the promise chain. rg -A 5 'remove\('Length of output: 15848
Script:
#!/bin/bash # Description: Verify specific usage of `issueOperations.remove` for proper promise handling. # Test: Search for the specific usage of `issueOperations.remove` in the codebase. rg -A 5 'issueOperations\.remove\('Length of output: 1122
web/core/components/issues/issue-detail-widgets/sub-issues/helper.tsx (1)
153-159: LGTM! Verify the function usage in the codebase.The restructuring of the
deleteSubIssuefunction to use a promise chain enhances the control flow and readability. Ensure that all usages ofdeleteSubIssuein the codebase are correctly handling the promise.web/core/components/issues/issue-detail/issue-detail-quick-actions.tsx (1)
81-92: LGTM! Verify the function usage in the codebase.The restructuring of the
handleDeleteIssuefunction to use a promise chain improves the control flow and reliability. Ensure that all usages ofhandleDeleteIssuein the codebase are correctly handling the promise.Verification successful
Function Usage Verified
The
handleDeleteIssuefunction is used correctly across the codebase, with proper handling of promises in contexts where it is invoked.
web/core/components/issues/issue-layouts/kanban/base-kanban-root.tsxweb/core/components/issues/relations/issue-list-item.tsxweb/core/components/issues/issue-detail/issue-detail-quick-actions.tsxScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `handleDeleteIssue` match the expected usage pattern. # Test: Search for the function usage. Expect: Proper handling of the promise chain. rg --type javascript -A 5 $'handleDeleteIssue($_)'Length of output: 86
Script:
#!/bin/bash # Corrected script to search for the function usage of `handleDeleteIssue`. # Search for all occurrences of `handleDeleteIssue` in the codebase. rg 'handleDeleteIssue' -A 5Length of output: 3878
web/core/components/issues/peek-overview/view.tsx (1)
134-134: Verify UI behavior after issue removal.The
onSubmithandler for theDeleteIssueModalhas been changed to an async function, but it no longer callsremoveRoutePeekId()after the issue is removed. Verify that the UI updates correctly after an issue is deleted.
|
|
||
| const removeRoutePeekId = () => { | ||
| setPeekIssue(undefined); | ||
| if (embedIssue) embedRemoveCurrentNotification && embedRemoveCurrentNotification(); |
There was a problem hiding this comment.
Use optional chaining for safer code.
The line can be simplified using optional chaining to prevent potential runtime errors.
- if (embedIssue) embedRemoveCurrentNotification && embedRemoveCurrentNotification();
+ if (embedIssue) embedRemoveCurrentNotification?.();Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (embedIssue) embedRemoveCurrentNotification && embedRemoveCurrentNotification(); | |
| if (embedIssue) embedRemoveCurrentNotification?.(); |
Tools
Biome
[error] 50-50: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- web/core/components/issues/delete-issue-modal.tsx (4 hunks)
Additional comments not posted (4)
web/core/components/issues/delete-issue-modal.tsx (4)
11-11: Import changes look good.The addition of
useUserenhances the functionality by incorporating user-specific permissions.
29-29: State and store hook changes look good.The use of
useUserto retrievecurrentUserandcanPerformProjectAdminActionsis appropriate for managing user permissions.
40-41: Authorization logic looks good.The derived values
isIssueCreatorandauthorizedeffectively determine user permissions for deleting issues.
51-58: Permission check and toast notifications are well-implemented.The
handleIssueDeletefunction now correctly checks for user authorization and provides appropriate feedback through toast notifications.
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- web/core/components/issues/delete-issue-modal.tsx (4 hunks)
Additional comments not posted (5)
web/core/components/issues/delete-issue-modal.tsx (5)
11-11: Import ofuseUserhook is appropriate.The addition of the
useUserhook is necessary for implementing user-specific permission checks.
29-29: Usage ofuseUserhook is correct.The
currentUserandcanPerformProjectAdminActionsproperties are correctly used for permission checks.
40-41: Derived values for authorization are well-implemented.The
isIssueCreatorandauthorizedvariables are correctly calculated to determine user permissions.
50-59: Permission check inhandleIssueDeleteis correctly implemented.The function correctly checks for user authorization before proceeding with the delete action, displaying an error toast if unauthorized.
Line range hint
59-79:
Toast notifications and error handling are well-implemented.The function provides clear feedback through toast notifications for both success and error scenarios, enhancing user experience.
Changes:
This PR resolves an issue with unauthorized delete actions in PeekOverview and Issue Details. Previously, when an unauthorized user attempted to delete an issue, sub-issue, or relation from PeekOverview or Issue detail pages, they would receive two conflicting toast alerts—one indicating success and the other an error. I have made the necessary changes to ensure the correct toast alert is displayed, accurately reflecting the outcome of the action.
Reference:
[WEB-2189]
Media:
Summary by CodeRabbit
New Features
Bug Fixes