[WEB-3744] Append the deleted_at timestamp to workspace slug when it is deleted#6862
Conversation
|
Pull Request Linked with Plane Work Items Comment Automatically Generated by Plane |
WalkthroughThis pull request introduces a new management command that updates the slug of a soft-deleted workspace by appending its deletion epoch timestamp. The command accepts a workspace slug and an optional dry-run flag to simulate the update. In addition, the Workspace model now overrides its delete method to append the timestamp to the slug during soft deletion and updates its user preferences by adding two new keys. Error handling has been improved to provide detailed feedback in different execution scenarios. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Command
participant WorkspaceModel
participant DB
User->>Command: Execute command with slug and optional --dry-run flag
Command->>WorkspaceModel: Retrieve workspace by slug
alt Workspace not found or not soft-deleted
WorkspaceModel--)Command: Return error/warning
Command->>User: Display error/warning message
else Valid soft-deleted workspace
Command->>WorkspaceModel: Get deletion timestamp
alt --dry-run enabled
Command->>User: Display simulated new slug
else
Command->>DB: Begin transaction
DB->>WorkspaceModel: Update slug with appended timestamp
Command->>DB: Commit transaction
Command->>User: Display success message
end
end
sequenceDiagram
participant Caller
participant WorkspaceInstance
participant DB
Caller->>WorkspaceInstance: Call delete(soft=True)
WorkspaceInstance->>WorkspaceInstance: Invoke parent delete method
WorkspaceInstance->>WorkspaceInstance: Check for soft delete condition (presence of deleted_at)
WorkspaceInstance->>WorkspaceInstance: Append epoch timestamp to slug
WorkspaceInstance->>DB: Save updated workspace
DB->>Caller: Return deletion result
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
apiserver/plane/db/models/workspace.py (2)
4-6: Clean up unused importsSeveral imports are added but not used in the code:
timemoduledjango.utils.timezonetyping.Tupleandtyping.Dict-import time -from django.utils import timezone -from typing import Optional, Any, Tuple, Dict +from typing import Optional, Any🧰 Tools
🪛 Ruff (0.8.2)
4-4:
timeimported but unusedRemove unused import:
time(F401)
5-5:
django.utils.timezoneimported but unusedRemove unused import:
django.utils.timezone(F401)
6-6:
typing.Tupleimported but unusedRemove unused import
(F401)
6-6:
typing.Dictimported but unusedRemove unused import
(F401)
155-181: LGTM! Overriding delete to preserve unique slugsThis implementation correctly modifies the workspace slug during soft deletion by appending a timestamp, ensuring that the slug remains unique. This is essential for allowing new workspaces to be created later with previously used slugs.
Consider shortening line 163 to comply with the line length limit:
- Override the delete method to append epoch timestamp to the slug when soft deleting. + Override the delete method to append epoch timestamp to the slug when soft deleting. + This ensures slug uniqueness after deletion.🧰 Tools
🪛 Ruff (0.8.2)
163-163: Line too long (92 > 88)
(E501)
apiserver/plane/db/management/commands/update_deleted_workspace_slug.py (4)
1-5: Remove unused importThe
timemodule is imported but not used in this file.-import time from django.core.management.base import BaseCommand from django.db import transaction from plane.db.models import Workspace🧰 Tools
🪛 Ruff (0.8.2)
1-1:
timeimported but unusedRemove unused import:
time(F401)
7-21: Well-structured management command with clear help text and argumentsThe command provides a clear description of its purpose and properly defines the required arguments. The dry-run option is a good practice for potentially destructive operations.
Shorten the help text to comply with line length limits:
- help = "Updates the slug of a soft-deleted workspace by appending the epoch timestamp" + help = "Update soft-deleted workspace slugs by adding timestamp"🧰 Tools
🪛 Ruff (0.8.2)
8-8: Line too long (90 > 88)
(E501)
27-52: Good error handling with informative messagesThe command includes comprehensive validation checks:
- Verifies the workspace exists
- Confirms the workspace is actually soft-deleted
- Checks if the slug already has a timestamp appended
These checks prevent unnecessary operations and provide clear feedback to the user.
Consider shortening the longer lines to comply with the style guide:
- f"Workspace '{workspace.name}' (slug: {workspace.slug}) is not deleted." + f"Workspace '{workspace.name}' is not deleted."- f"Workspace '{workspace.name}' (slug: {workspace.slug}) already has a timestamp appended." + f"Workspace '{workspace.name}' already has a timestamp appended."🧰 Tools
🪛 Ruff (0.8.2)
39-39: Line too long (92 > 88)
(E501)
48-48: Line too long (110 > 88)
(E501)
53-78: Transaction-based approach with proper success/error handlingThe implementation correctly uses a database transaction to ensure atomicity when updating the workspace slug. The dry-run option provides a safe way to preview changes before applying them.
The success message on line 70 needs correction - it's showing the old slug as both the original and new value:
- f"Updated workspace '{workspace.name}' slug from '{workspace.slug}' to '{new_slug}'" + f"Updated workspace '{workspace.name}' slug to '{new_slug}'"Also, consider shortening line 61 to comply with the style guide:
- f"Would update workspace '{workspace.name}' slug from '{workspace.slug}' to '{new_slug}'" + f"Would update workspace '{workspace.name}' slug to '{new_slug}'"🧰 Tools
🪛 Ruff (0.8.2)
61-61: Line too long (105 > 88)
(E501)
70-70: Line too long (112 > 88)
(E501)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apiserver/plane/db/management/commands/update_deleted_workspace_slug.py(1 hunks)apiserver/plane/db/models/workspace.py(3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apiserver/plane/db/management/commands/update_deleted_workspace_slug.py (1)
apiserver/plane/db/models/workspace.py (2)
Workspace(117-187)save(201-204)
🪛 Ruff (0.8.2)
apiserver/plane/db/management/commands/update_deleted_workspace_slug.py
1-1: time imported but unused
Remove unused import: time
(F401)
8-8: Line too long (90 > 88)
(E501)
39-39: Line too long (92 > 88)
(E501)
48-48: Line too long (110 > 88)
(E501)
61-61: Line too long (105 > 88)
(E501)
70-70: Line too long (112 > 88)
(E501)
apiserver/plane/db/models/workspace.py
4-4: time imported but unused
Remove unused import: time
(F401)
5-5: django.utils.timezone imported but unused
Remove unused import: django.utils.timezone
(F401)
6-6: typing.Tuple imported but unused
Remove unused import
(F401)
6-6: typing.Dict imported but unused
Remove unused import
(F401)
163-163: Line too long (92 > 88)
(E501)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (python)
🔇 Additional comments (1)
apiserver/plane/db/models/workspace.py (1)
425-431: LGTM! Added new user preference keysThe new
DRAFTSandYOUR_WORKkeys have been added to the UserPreferenceKeys enum, which expands the options for user preferences.
…'s soft deleted (#6862)
Description
This releases the slug of a soft deleted workspace to be used again.
Type of Change
Screenshots and Media (if applicable)
Test Scenarios
References