User can delete mails permanently from bin #669
User can delete mails permanently from bin #669Adarsh9977 wants to merge 4 commits intoMail-0:mainfrom
Conversation
|
@Adarsh9977 is attempting to deploy a commit to the Zero Team on Vercel. A member of the Team first needs to authorize it. |
## Walkthrough
This update introduces a new capability for permanently deleting email threads from the bin in the mail application. It adds an asynchronous `deleteThread` action, integrates a "Delete from Bin" menu option within the thread context menu (visible when in the bin folder), and provides user feedback through localized toast notifications. The OAuth scopes for the Google authentication provider are expanded to enable broader mail access. New English localization strings are added to support the new deletion-related actions and messages.
## Changes
| File(s) | Change Summary |
|----------------------------------------------|----------------------------------------------------------------------------------------------------|
| apps/mail/actions/mail.ts | Added `deleteThread` async function to delete an email thread by ID with error handling. |
| apps/mail/components/context/thread-context.tsx | Added `handleDelete` handler and integrated "Delete from Bin" menu option into `ThreadContextMenu`.|
| apps/mail/lib/auth-providers.ts | Expanded Google OAuth scopes to include `https://mail.google.com` for full mail access. |
| apps/mail/locales/en.json | Added localization strings for mail deletion actions and "Delete from Bin" menu label. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant User
participant UI (ThreadContextMenu)
participant Actions (deleteThread)
participant Driver
participant Toast
User->>UI (ThreadContextMenu): Selects "Delete from Bin"
UI (ThreadContextMenu)->>Toast: Show "Deleting mail..." (loading)
UI (ThreadContextMenu)->>Actions (deleteThread): Call with threadId
Actions (deleteThread)->>Driver: delete(threadId)
Driver-->>Actions (deleteThread): Success/Failure
Actions (deleteThread)-->>UI (ThreadContextMenu): Return result
UI (ThreadContextMenu)->>Toast: Show "Mail deleted" or "Failed to delete mail"
UI (ThreadContextMenu)->>UI (ThreadContextMenu): Refresh data (mutate)Possibly related PRs
Suggested reviewers
Poem
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/mail/actions/mail.ts(1 hunks)apps/mail/components/context/thread-context.tsx(3 hunks)apps/mail/lib/auth-providers.ts(1 hunks)apps/mail/locales/en.json(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/mail/components/context/thread-context.tsx (1)
apps/mail/actions/mail.ts (1)
deleteThread(158-169)
🔇 Additional comments (5)
apps/mail/lib/auth-providers.ts (1)
51-51:Details
❌ Incorrect review comment
Expanded OAuth scope adds broader Gmail access
The addition of
'https://mail.google.com'scope significantly increases the permissions requested from users. This scope grants full access to Gmail, which is more expansive than needed for just deleting emails from the bin.Consider evaluating whether a more limited scope could achieve the same goal:
🌐 Web query:
What is the minimum OAuth scope needed for Gmail API to delete messages permanently?💡 Result:
To delete Gmail messages permanently using the Gmail API, the required OAuth 2.0 scope is
https://mail.google.com/, which provides full access to Gmail accounts, including the ability to immediately and permanently delete messages, bypassing the Trash folder[1][6][9]. This is a restricted scope, so it requires additional verification from Google if used in a production application.Citations:
- 1: https://developers.google.com/gmail/api/reference/rest/v1/users.messages/delete
- 2: https://developers.google.com/gmail/api/auth/scopes
- 3: https://scipython.com/blog/deleting-gmail-messages-by-label-with-the-google-api/
- 4: https://wordpress.org/support/topic/gmail-api-scope/
- 5: https://againstdata.com/security
- 6: https://support.google.com/cloud/answer/13807380
- 7: https://groups.google.com/g/google-apps-manager/c/UG0K4qyW-Ok
- 8: https://support.google.com/cloud/answer/13463817
- 9: https://googleapis.dev/dotnet/Google.Apis.Gmail.v1/latest/api/Google.Apis.Gmail.v1.GmailService.Scope.html
- 10: https://developers.google.com/identity/protocols/oauth2/scopes
Clarification on Gmail OAuth Scope Usage
After verifying the API requirements, the web search confirms that to permanently delete Gmail messages (i.e., bypass the Trash), the minimum OAuth 2.0 scope required is indeed
https://mail.google.com/. Although this scope grants full access to Gmail, it is necessary for that specific deletion functionality. In other words, the current code at line 51 is correct for its intended purpose, and no reduction in permissions is possible if permanent deletion is required.Likely an incorrect or invalid review comment.
apps/mail/locales/en.json (2)
22-24: LGTM! Appropriate localization for mail deletion actions.The added status messages for deleting mail are clear and consistent with the existing localization pattern.
251-251: LGTM! Clear menu item label for bin deletion.The "Delete from Bin" label clearly communicates the action to users.
apps/mail/actions/mail.ts (1)
158-169:Details
✅ Verification successful
Verify deletion implementation in mail driver
The
deleteThreadfunction is well-structured and follows the pattern of other functions in this file. However, we should verify that the mail driver'sdeletemethod is properly implemented to permanently delete emails rather than just moving them to the bin.
🏁 Script executed:
#!/bin/bash # Check for delete implementation in mail drivers rg -A 5 "delete\(.*\)" --glob 'apps/mail/**/*.ts'Length of output: 2803
Action: Confirmed permanent deletion implementation
The mail driver's deletion logic was verified. In particular, the implementation in
apps/mail/app/api/driver/google.tsuses the Gmail API’susers.messages.deletemethod—which permanently deletes the message—while the type declarations inapps/mail/app/api/driver/types.tsproperly define the deletion interface. No changes are required in thedeleteThreadfunction inapps/mail/actions/mail.ts.apps/mail/components/context/thread-context.tsx (1)
38-38: LGTM! Appropriate import of the deleteThread action.The new import adds the required functionality without unnecessary changes.
Description
User now able to delete his mails permanently from bin
Type of Change
Please delete options that are not relevant.
Present workflow
Screen.Recording.2025-04-15.at.5.12.38.PM.mov
Upgraded workflow
Screen.Recording.2025-04-15.at.5.14.13.PM.mov
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit