nephila / python-taiga

:evergreen_tree: Python module for communicating with the Taiga API
https://python-taiga.readthedocs.io
MIT License
94 stars 41 forks source link

Project duplication #161

Closed psybers closed 6 months ago

psybers commented 6 months ago

Description

I'd like to request the ability to duplicate a project.

See the Taiga REST API description: https://docs.taiga.io/api.html#projects-duplicate

Use cases

Every semester I set up a new Taiga for my courses. Although I use a built-in template as a starting point, I modify a lot of the other settings (points, colors, etc.). As such, the ability to start a new project from an existing project is important to save time. This ability is available from the Taiga UI interface.

Proposed solution

The API could be extended to add a duplicate() method to Project. Something like this:

project = api.projects.get_by_slug('nephila')
new_project = project.duplicate('new project name')
...

Alternatives

Could also support the export/import features of Taiga, allowing creation of a new project via export and then import:

This may also be a nice feature to have, but for this use case it is a lot simpler to just support duplicate().

psybers commented 6 months ago

It's ugly, but for the moment I am using something like this:

import types

def duplicate(self, name, description, is_private, users=[]):
    payload = {
        "name": name,
        "description": description,
        "is_private": is_private,
        "users": users,
    }
    response = self.requester.post("/projects/{id}/duplicate", payload=payload, id=self.id)
    return self.parse(self.requester, response.json())

project = api.projects.get_by_slug('nephila')
project.duplicate = types.MethodType(duplicate, project)

print(project.duplicate(description='this is a test', is_private=True, name='testing2'))

Seems to work. Note that the API requires all four fields in the payload (but users can be an empty list - it will always add yourself when you duplicate so I assume this is extra users that gain access).

psybers commented 6 months ago

I started working on this. Haven't had time to read contributing docs or write tests, but seems to work.

psybers@025f2dcb8a9cf5b85c3226495525be60fab07a70

If I get time I might polish it up and PR. Feel free to use that code if you want to add it yourselves.