-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[MAK-118] feat: implement project duplication feature #7441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
Conversation
…ssues consideration
""" WalkthroughA project duplication feature was introduced, enabling users to create a new project based on an existing template, including all related data and relationships. Backend logic supports deep cloning, while frontend components provide UI for duplicating projects from both the project settings and sidebar. Localization entries for the new action were also added. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend
participant Backend
User->>Frontend: Click "Duplicate project"
Frontend->>Frontend: Open CreateProjectModal (pre-filled with template)
User->>Frontend: Submit new project details
Frontend->>Backend: POST /projects/ (with template_id)
Backend->>Backend: duplicate_project(template, user, name, identifier)
Backend->>Frontend: Return new project data (201 Created)
Frontend->>User: Show duplicated project
Poem
""" 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ 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:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
apps/web/core/components/project/settings/duplicate-project-section.tsx (1)
24-24
: Remove unnecessary empty lineconst [isModalOpen, setIsModalOpen] = useState(false); - return (
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
apps/api/plane/app/views/project/base.py
(2 hunks)apps/web/app/(all)/[workspaceSlug]/(settings)/settings/projects/[projectId]/page.tsx
(2 hunks)apps/web/ce/components/projects/create/root.tsx
(2 hunks)apps/web/core/components/project/settings/duplicate-project-section.tsx
(1 hunks)apps/web/core/components/project/settings/index.ts
(1 hunks)apps/web/core/components/workspace/sidebar/projects-list-item.tsx
(5 hunks)packages/i18n/src/locales/en/translations.json
(2 hunks)
🧰 Additional context used
🧠 Learnings (3)
packages/i18n/src/locales/en/translations.json (2)
Learnt from: janreges
PR: makeplane/plane#6743
File: packages/i18n/src/store/index.ts:160-161
Timestamp: 2025-03-11T19:42:41.769Z
Learning: In the Plane project, the file 'packages/i18n/src/store/index.ts' already includes support for Polish language translations with the case "pl".
Learnt from: vamsikrishnamathala
PR: makeplane/plane#7092
File: web/core/components/issues/issue-detail-widgets/sub-issues/issues-list/root.tsx:109-113
Timestamp: 2025-05-22T11:21:49.370Z
Learning: Both translation keys "sub_work_item.empty_state.list_filters.action" and "sub_work_item.empty_state.sub_list_filters.action" have identical values across all language files in the Plane project, so they can be used interchangeably.
apps/web/core/components/workspace/sidebar/projects-list-item.tsx (1)
Learnt from: vamsikrishnamathala
PR: makeplane/plane#7061
File: web/core/components/workspace-notifications/root.tsx:18-18
Timestamp: 2025-05-14T13:16:23.323Z
Learning: In the Plane project codebase, the path alias `@/plane-web` resolves to the `ce` directory, making imports like `@/plane-web/hooks/use-notification-preview` correctly resolve to files in `web/ce/hooks/`.
apps/web/ce/components/projects/create/root.tsx (2)
Learnt from: vamsikrishnamathala
PR: makeplane/plane#7214
File: web/core/store/issue/helpers/base-issues.store.ts:117-117
Timestamp: 2025-06-16T07:23:39.497Z
Learning: In the updateIssueDates method of BaseIssuesStore (web/core/store/issue/helpers/base-issues.store.ts), the projectId parameter is intentionally made optional to support override implementations in subclasses. The base implementation requires projectId and includes an early return check, but making it optional allows derived classes to override the method with different parameter requirements.
Learnt from: prateekshourya29
PR: makeplane/plane#7363
File: apps/web/core/components/issues/select/dropdown.tsx:9-11
Timestamp: 2025-07-08T13:41:01.659Z
Learning: The `getProjectLabelIds` function in the label store handles undefined projectId internally, so it's safe to pass undefined values to it without explicit checks in the calling component.
🧬 Code Graph Analysis (2)
apps/web/app/(all)/[workspaceSlug]/(settings)/settings/projects/[projectId]/page.tsx (1)
apps/web/core/components/project/settings/duplicate-project-section.tsx (1)
DuplicateProjectSection
(15-66)
apps/api/plane/app/views/project/base.py (2)
apps/api/plane/db/models/issue.py (2)
Issue
(104-260)IssueUserProperty
(503-529)apps/api/plane/app/serializers/project.py (2)
create
(61-70)ProjectListSerializer
(88-110)
🔇 Additional comments (10)
packages/i18n/src/locales/en/translations.json (2)
193-193
: Translation entry correctly positioned and follows established patterns.The new translation key is appropriately placed alongside other project-related actions and maintains consistency with the existing naming conventions.
642-642
: Translation entry correctly placed within the actions object.The duplicate translation key in the actions object is appropriately positioned and follows the established pattern for context-specific translations.
apps/web/core/components/project/settings/index.ts (1)
4-4
: Export statement correctly added for new component.The new export follows the established pattern and appropriately exposes the DuplicateProjectSection component for use in other parts of the application.
apps/web/app/(all)/[workspaceSlug]/(settings)/settings/projects/[projectId]/page.tsx (2)
15-15
: Import correctly added for DuplicateProjectSection.The import is properly positioned within the existing imports and follows the established pattern.
82-85
: DuplicateProjectSection component correctly integrated.The component is properly positioned within the admin-only section and receives the appropriate props. The placement before archive and delete actions follows a logical UI flow.
apps/web/ce/components/projects/create/root.tsx (3)
28-28
: Optional templateId prop correctly added.The optional templateId prop is appropriately typed and positioned within the interface, allowing the component to support both regular project creation and duplication scenarios.
33-33
: Props correctly destructured including templateId.The templateId is properly destructured from props alongside the existing parameters.
68-71
: Template ID correctly added to form data when provided.The conditional logic appropriately adds the template_id to the form data when templateId is provided. The type assertion is acceptable here since template_id is only used for the API call and not part of the project model.
apps/web/core/components/workspace/sidebar/projects-list-item.tsx (2)
211-219
: Well-implemented modal integration!The conditional rendering with workspace slug check and proper prop passing follows the existing patterns in the codebase.
342-349
: Proper authorization check for duplicate action!The menu item correctly checks for user authorization before displaying the duplicate option, maintaining security consistency.
if template_id: | ||
template_project = Project.objects.filter( | ||
pk=template_id, | ||
workspace__slug=slug, | ||
).first() | ||
if not template_project: | ||
return Response( | ||
{"error": "Template project does not exist"}, | ||
status=status.HTTP_404_NOT_FOUND, | ||
) | ||
name = request.data.get("name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add permission check for template project access
The code validates template existence but doesn't verify if the user has permission to access the template project.
Add permission verification:
if template_id:
template_project = Project.objects.filter(
pk=template_id,
workspace__slug=slug,
).first()
if not template_project:
return Response(
{"error": "Template project does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
+
+ # Check if user has access to the template project
+ if not ProjectMember.objects.filter(
+ project=template_project,
+ member=request.user,
+ is_active=True
+ ).exists():
+ return Response(
+ {"error": "You don't have access to the template project"},
+ status=status.HTTP_403_FORBIDDEN,
+ )
📝 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 template_id: | |
template_project = Project.objects.filter( | |
pk=template_id, | |
workspace__slug=slug, | |
).first() | |
if not template_project: | |
return Response( | |
{"error": "Template project does not exist"}, | |
status=status.HTTP_404_NOT_FOUND, | |
) | |
name = request.data.get("name") | |
if template_id: | |
template_project = Project.objects.filter( | |
pk=template_id, | |
workspace__slug=slug, | |
).first() | |
if not template_project: | |
return Response( | |
{"error": "Template project does not exist"}, | |
status=status.HTTP_404_NOT_FOUND, | |
) | |
# Check if user has access to the template project | |
if not ProjectMember.objects.filter( | |
project=template_project, | |
member=request.user, | |
is_active=True | |
).exists(): | |
return Response( | |
{"error": "You don't have access to the template project"}, | |
status=status.HTTP_403_FORBIDDEN, | |
) | |
name = request.data.get("name") |
🤖 Prompt for AI Agents
In apps/api/plane/app/views/project/base.py around lines 348 to 358, the code
checks if the template project exists but does not verify if the requesting user
has permission to access it. To fix this, after retrieving the template_project,
add a permission check to confirm the user has the necessary access rights
(e.g., using a method like has_object_permission or a custom permission check).
If the user lacks permission, return an appropriate error response such as HTTP
403 Forbidden.
const projectDetails = getProjectById(projectId); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle undefined project details
getProjectById
might return undefined if the project doesn't exist or hasn't loaded yet.
Add null check:
const projectDetails = getProjectById(projectId);
const [isModalOpen, setIsModalOpen] = useState(false);
+if (!projectDetails) {
+ return null; // or a loading state
+}
Also applies to: 58-59
🤖 Prompt for AI Agents
In apps/web/core/components/project/settings/duplicate-project-section.tsx
around lines 20-21 and 58-59, the call to getProjectById(projectId) may return
undefined if the project is not found or not loaded. Add a null check after
calling getProjectById to verify projectDetails is defined before accessing its
properties or rendering dependent UI. If projectDetails is undefined, handle
this case gracefully, for example by returning null, showing a loading state, or
displaying an error message.
Description
This PR adds the ability to duplicate an existing project, including its:
The feature hooks directly into the existing project creation endpoint, using the optional template_id field. The selected project is then treated as a template and cloned accordingly. This enables users to create project templates with predefined structures and use them to quickly spin up new projects based on those templates.
The duplicated project:
archived_at
valueType of Change
Screenshots and Media (if applicable)
Test Scenarios
archived_at
is clearedReferences
Address #1481
Summary by CodeRabbit
New Features
User Interface
Localization