Skip to content
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

[Feature] Transfer project ownership #4743

Merged
merged 162 commits into from
Mar 22, 2024

Conversation

noliveleger
Copy link
Contributor

@noliveleger noliveleger commented Nov 29, 2023

Description

Allow users to transfer their project to another user

Notes

The back end support several projects at once per invite but the UI only support one project per invite.
Once a project is being transferred, it sends emails to previous owner and new owner.
it also adds in-app message to all other users who have access to that the project.

In this PR, deployment__identifier (i.e. link to KoboCAT form representation) to is removed from asset back-end response when project is deployed. It's not 100% related to transfer but the link was based on owner's username. So it should have been updated too. Since the endpoint has been removed in a previous version, the link returns a 404.

@noliveleger noliveleger changed the title Feature/transfer project ownership [Feature] Transfer project ownership Nov 29, 2023
noliveleger and others added 26 commits November 29, 2023 14:40
…oolbox/kpi into feature/transfer-project-ownership
…oolbox/kpi into feature/transfer-project-ownership
@noliveleger noliveleger changed the base branch from main to refactor-counter-shadow-models February 28, 2024 16:26
@noliveleger noliveleger force-pushed the refactor-counter-shadow-models branch from d275485 to 752d7eb Compare February 28, 2024 16:35
…roject-ownership

 # Conflicts:
 #	kobo/apps/superuser_stats/tasks.py
 #	kpi/deployment_backends/kc_access/shadow_models.py
 #	kpi/deployment_backends/kobocat_backend.py
@noliveleger noliveleger changed the base branch from refactor-counter-shadow-models to refactor-api-v2-urls February 28, 2024 16:57
@noliveleger noliveleger changed the base branch from refactor-api-v2-urls to lint-format-pre-transfer-project-ownership February 28, 2024 17:15
@noliveleger noliveleger force-pushed the lint-format-pre-transfer-project-ownership branch from 48ac7a5 to 44f5855 Compare February 28, 2024 17:20
@noliveleger noliveleger changed the base branch from lint-format-pre-transfer-project-ownership to main February 28, 2024 17:20
@noliveleger noliveleger changed the base branch from main to lint-format-pre-transfer-project-ownership February 28, 2024 17:20
@noliveleger noliveleger requested review from bufke and removed request for jnm February 28, 2024 17:57
Base automatically changed from lint-format-pre-transfer-project-ownership to release/2.024.09 March 11, 2024 14:30
 Conflicts:
	jsapp/js/project/projectTopTabs.component.tsx
Copy link
Contributor

@bufke bufke left a comment

Choose a reason for hiding this comment

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

Let's discuss the models before moving on to the other code.

kobo/apps/help/models.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/base.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/choices.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/invite.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/transfer.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/choices.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/transfer.py Outdated Show resolved Hide resolved
kobo/apps/project_ownership/models/transfer.py Outdated Show resolved Hide resolved
@noliveleger noliveleger force-pushed the feature/transfer-project-ownership branch from 1f12a60 to 9e239d7 Compare March 14, 2024 15:43
@noliveleger noliveleger requested a review from bufke March 14, 2024 15:55
@@ -43,6 +43,9 @@ class InAppMessage(AbstractMarkdownxModel):
valid_from = models.DateTimeField(default=EPOCH_BEGINNING)
valid_until = models.DateTimeField(default=EPOCH_BEGINNING)
last_editor = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
# We do not want to use a generic foreign key or tightly couple this model
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand our opinion on generic foreign key, what we dislike is that it points to a django content type which itself is in the database. That adds complexity with no apparent benefit to us. We know the model's name. It never changes. We prefer to reference the model by name instead of a on the dynamic generated ID from content types. Or to say this in a more practical way - gfk's break under certain conditions, such as transferring data from one Django DB to another. There is no guarantee that the content type ID's would line up consistently.

We remain at the risk of it losing the relationship if we did intentionally change the model name/label without a data migration. But in this case, it's fine. Go ahead and loose the connection for some old in app message. Better than a database hitting constraints and erroring out hard.

I'm 100% for this concept. But we do deviate from Django's design. Let's add more detail here (or somewhere?) explaining why we created our own solution to something that comes out of the box with Django. We may end up using it again later.

@jnm I'd be curious on your opinion of this approach.

value = t(value)

try:
transfer = Transfer.objects.get(pk=transfer_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 glad to see it handles a lack of referential integrity, which my suggested design presents us with.

with transaction.atomic():
self._reassign_project_permissions(update_deployment=False)
self._sent_app_in_messages()
# FIXME - Draft stay in queue forever
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean that you'll fix it in this PR? You marked it as ready for review so I want wondering.

@noliveleger noliveleger requested a review from bufke March 19, 2024 19:11
@bufke
Copy link
Contributor

bufke commented Mar 21, 2024

It's failing to deploy to staging but looks unrelated.

@noliveleger noliveleger merged commit 5bd75ca into release/2.024.09 Mar 22, 2024
4 checks passed
@noliveleger noliveleger deleted the feature/transfer-project-ownership branch March 22, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes related to API endpoints Back end Front end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants