Skip to content

[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

Open
wants to merge 6 commits into
base: preview
Choose a base branch
from

Conversation

duydl
Copy link

@duydl duydl commented Jul 18, 2025

Description

This PR adds the ability to duplicate an existing project, including its:

  • Project metadata (with a new name and identifier)
  • States
  • Modules (and their members)
  • Issues (excluding assignees and other per-user context)
  • Issue–Module relations
  • Issue labels
  • Parent–child issue relationships
  • Views?
  • Pages?

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:

  • Will have a unique name and identifier (enforced)
  • Will not inherit the archived_at value
  • Is created with the current user as admin and issue property owner
  • Skips issue assignees, votes, reactions, attachments, comments, etc.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

image image

Test Scenarios

  • Duplicated a project with:
    • Multiple states
    • Nested issues with parent–child relationships
    • Assigned modules with members
  • Confirmed that:
    • archived_at is cleared
    • States and issues are mapped correctly
    • Module–issue links are preserved using new IDs

References

Address #1481

Summary by CodeRabbit

  • New Features

    • Introduced the ability to duplicate existing projects, including their states, modules, and issues, while preserving relationships and ownership.
    • Added a "Duplicate project" option in the project settings and sidebar, allowing users to easily create a copy of a project via a modal interface.
    • Enhanced project creation to support initializing new projects from a template.
  • User Interface

    • Added a dedicated section and button for duplicating projects in the project settings page.
    • Included a "Duplicate project" action in the project sidebar menu for quick access.
  • Localization

    • Added new English translations for "Duplicate project" in relevant UI areas.

@CLAassistant
Copy link

CLAassistant commented Jul 18, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

"""

Walkthrough

A 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

File(s) Change Summary
apps/api/plane/app/views/project/base.py Added duplicate_project function for deep cloning projects; updated ProjectViewSet.create to support templates.
apps/web/app/(all)/[workspaceSlug]/(settings)/settings/projects/[projectId]/page.tsx Imported and rendered DuplicateProjectSection in the admin project settings page.
apps/web/ce/components/projects/create/root.tsx Extended CreateProjectForm props to accept optional templateId; included it in form submission if present.
apps/web/core/components/project/settings/duplicate-project-section.tsx Introduced new DuplicateProjectSection component with UI for duplicating projects via modal.
apps/web/core/components/project/settings/index.ts Exported the new duplicate-project-section module.
apps/web/core/components/workspace/sidebar/projects-list-item.tsx Added "duplicate project" menu item and modal to sidebar project items for authorized users.
packages/i18n/src/locales/en/translations.json Added English translations for "duplicate_project" at top-level and within "common.actions".

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
Loading

Poem

🐇
A hop, a skip, a project anew,
With just one click, templates grew!
From sidebar or settings, the magic appears,
Duplicating dreams, banishing fears.
Now every bunny can multiply—
Projects with ease, oh my, oh my!

"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12cc3f5 and 920d9e5.

📒 Files selected for processing (1)
  • apps/api/plane/app/views/project/base.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/plane/app/views/project/base.py
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 line

 const [isModalOpen, setIsModalOpen] = useState(false);
 
-
 return (
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df4ea1f and 12cc3f5.

📒 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.

Comment on lines +348 to +358
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +20 to +21
const projectDetails = getProjectById(projectId);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants