Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.24 on 2026-07-02 04:15
import django.db.models.deletion
from django.db import migrations
from django.db import models
Comment thread
ArthurMousatov marked this conversation as resolved.


class Migration(migrations.Migration):
Comment thread
ArthurMousatov marked this conversation as resolved.

dependencies = [
("contentcuration", "0167_add_organization"),
]

operations = [
migrations.AddField(
model_name="invitation",
name="organization",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="contentcuration.organization",
),
),
]
44 changes: 37 additions & 7 deletions contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@
from contentcuration.constants import feedback
from contentcuration.constants import user_history
from contentcuration.constants.contentnode import kind_activity_map
from contentcuration.constants.organization_roles import ORGANIZATION_ADMIN
from contentcuration.constants.organization_roles import ORGANIZATION_EDITOR
from contentcuration.constants.organization_roles import organization_role_choices
from contentcuration.constants.organization_roles import ORGANIZATION_ROLE_STATUS_ACTIVE
from contentcuration.constants.organization_roles import (
organization_role_status_choices,
)
from contentcuration.constants.organization_roles import (
ORGANIZATION_ROLE_STATUS_PENDING,
)
from contentcuration.constants.organization_roles import ORGANIZATION_VIEWER
from contentcuration.db.models.expressions import Array
from contentcuration.db.models.functions import ArrayRemove
from contentcuration.db.models.functions import Unnest
Expand All @@ -102,6 +106,7 @@

EDIT_ACCESS = "edit"
VIEW_ACCESS = "view"
ADMIN_ACCESS = "admin"

DEFAULT_CONTENT_DEFAULTS = {
"license": None,
Expand Down Expand Up @@ -3730,6 +3735,9 @@ class Invitation(models.Model):
)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True, null=True)
organization = models.ForeignKey(
Comment thread
ArthurMousatov marked this conversation as resolved.
"Organization", null=True, blank=True, on_delete=models.CASCADE
)

class Meta:
Comment thread
ArthurMousatov marked this conversation as resolved.
Comment thread
ArthurMousatov marked this conversation as resolved.
verbose_name = "Invitation"
Expand All @@ -3738,13 +3746,35 @@ class Meta:
def accept(self):
user = User.objects.filter(email__iexact=self.email).first()
if self.channel:
# channel is a nullable field, so check that it exists.
if self.share_mode == VIEW_ACCESS:
self.channel.editors.remove(user)
self.channel.viewers.add(user)
else:
self.channel.viewers.remove(user)
self.channel.editors.add(user)
self._accept_channel_invitation(user)
if self.organization:
self._accept_organization_invitation(user)

def _accept_channel_invitation(self, user):
if self.share_mode == VIEW_ACCESS:
self.channel.editors.remove(user)
self.channel.viewers.add(user)
else:
self.channel.viewers.remove(user)
Comment thread
ArthurMousatov marked this conversation as resolved.
self.channel.editors.add(user)

def _accept_organization_invitation(self, user):
Comment thread
ArthurMousatov marked this conversation as resolved.
role = None
if self.share_mode == VIEW_ACCESS:
role = ORGANIZATION_VIEWER
elif self.share_mode == EDIT_ACCESS:
role = ORGANIZATION_EDITOR
elif self.share_mode == ADMIN_ACCESS:
role = ORGANIZATION_ADMIN
else:
raise ValidationError(f"Invalid share_mode: {self.share_mode}")
Comment thread
ArthurMousatov marked this conversation as resolved.
Comment thread
ArthurMousatov marked this conversation as resolved.

update_create_defaults = {"role": role, "status": ORGANIZATION_ROLE_STATUS_ACTIVE}
OrganizationRole.objects.update_or_create(
user=user,
organization=self.organization,
defaults=update_create_defaults,
)

@classmethod
def filter_edit_queryset(cls, queryset, user):
Expand Down