#101 Team sharing tests
* adds tests for team sharing * extends the API for team sharing support * adds shared_teams property shortcut for ShareableObjectMixin * adds full support for team-based sharing to all views and functions * simplifies ShareModalForm * adds/updates translations
This commit is contained in:
@@ -501,30 +501,37 @@ class ShareableObjectMixin(models.Model):
|
||||
form_data = form.cleaned_data
|
||||
|
||||
# Fetch selected teams and find out which user IDs are in removed teams -> mails need to be sent
|
||||
accessing_teams = form_data["team_select"]
|
||||
accessing_teams = form_data["teams"]
|
||||
removed_team_users = self.teams.all().exclude(
|
||||
id__in=accessing_teams
|
||||
).values_list("users__id", flat=True)
|
||||
|
||||
new_accessing_users = list(form_data["user_select"].values_list("id", flat=True))
|
||||
keep_accessing_users = form_data["users"]
|
||||
accessing_users = keep_accessing_users + new_accessing_users
|
||||
users = User.objects.filter(
|
||||
id__in=accessing_users
|
||||
accessing_team_users = User.objects.filter(
|
||||
id__in=accessing_teams.values_list("users", flat=True)
|
||||
)
|
||||
new_team_users = accessing_team_users.exclude(
|
||||
id__in=self.shared_users
|
||||
).values_list("id", flat=True)
|
||||
|
||||
# Fetch selected users
|
||||
accessing_users = form_data["users"]
|
||||
removed_users = self.users.all().exclude(
|
||||
id__in=accessing_users
|
||||
).values_list("id", flat=True)
|
||||
new_users = accessing_users.exclude(
|
||||
id__in=self.shared_users
|
||||
).values_list("id", flat=True)
|
||||
|
||||
new_users = new_users.union(new_team_users)
|
||||
removed_users = removed_users.union(removed_team_users)
|
||||
|
||||
# Send mails
|
||||
for user_id in removed_users:
|
||||
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user_id)
|
||||
for user_id in new_accessing_users:
|
||||
for user_id in new_users:
|
||||
celery_send_mail_shared_access_given.delay(self.identifier, self.title, user_id)
|
||||
|
||||
# Set new shared users
|
||||
self.share_with_user_list(users)
|
||||
self.share_with_user_list(accessing_users)
|
||||
self.share_with_team_list(accessing_teams)
|
||||
|
||||
@property
|
||||
@@ -536,6 +543,15 @@ class ShareableObjectMixin(models.Model):
|
||||
"""
|
||||
return self.users.all()
|
||||
|
||||
@property
|
||||
def shared_teams(self) -> QuerySet:
|
||||
""" Shortcut for fetching the teams which have shared access on this object
|
||||
|
||||
Returns:
|
||||
teams (QuerySet)
|
||||
"""
|
||||
return self.teams.all()
|
||||
|
||||
@abstractmethod
|
||||
def get_share_url(self):
|
||||
""" Returns the share url for the object
|
||||
|
||||
Reference in New Issue
Block a user