Skip to content

Commit 27220c2

Browse files
authored
Merge pull request #3174 from kobotoolbox/3150-self-service-sync-kobocat-xforms
Allow users to migrate their XForms from kobocat
2 parents 50313c1 + 648593c commit 27220c2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kpi/views/v2/user.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ def list(self, request, *args, **kwargs):
3232
url_path=r'migrate(?:/(?P<task_id>[\d\w\-]+))?')
3333
def migrate(self, request, task_id: str = None, **kwargs):
3434
"""
35-
A really basic endpoint what allows super users to migration projects
36-
from KoBoCAT.
35+
A temporary endpoint that allows superusers to migrate other users'
36+
projects, and users to migrate their own projects, from Kobocat to KPI.
37+
This is required while users transition from the legacy interface to
38+
the new.
3739
3840
1. Call this endpoint with `?username=<username>`
3941
2. Fetch url provided to check the state of the Celery task.
@@ -47,7 +49,12 @@ def migrate(self, request, task_id: str = None, **kwargs):
4749
4850
"""
4951

50-
if not request.user.is_superuser:
52+
request_user = request.user
53+
migrate_user = kwargs.get('username')
54+
if request_user.is_anonymous or (
55+
not request_user.is_superuser
56+
and request_user.username != migrate_user
57+
):
5158
raise exceptions.PermissionDenied()
5259

5360
if task_id:

0 commit comments

Comments
 (0)