#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:
@@ -59,8 +59,9 @@ class CheckboxCompensationTableFilter(CheckboxTableFilter):
|
||||
"""
|
||||
if not value:
|
||||
return queryset.filter(
|
||||
intervention__users__in=[self.user], # requesting user has access
|
||||
)
|
||||
Q(intervention__users__in=[self.user]) | # requesting user has access
|
||||
Q(intervention__teams__users__in=[self.user])
|
||||
).distinct()
|
||||
else:
|
||||
return queryset
|
||||
|
||||
@@ -127,24 +128,6 @@ class CheckboxEcoAccountTableFilter(CheckboxTableFilter):
|
||||
)
|
||||
)
|
||||
|
||||
def filter_show_all(self, queryset, name, value) -> QuerySet:
|
||||
""" Filters queryset depending on value of 'show_all' setting
|
||||
|
||||
Args:
|
||||
queryset ():
|
||||
name ():
|
||||
value ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not value:
|
||||
return queryset.filter(
|
||||
users__in=[self.user], # requesting user has access
|
||||
)
|
||||
else:
|
||||
return queryset
|
||||
|
||||
def filter_only_show_unrecorded(self, queryset, name, value) -> QuerySet:
|
||||
""" Filters queryset depending on value of 'show_recorded' setting
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Created on: 16.11.21
|
||||
import shutil
|
||||
|
||||
from django.contrib import messages
|
||||
from user.models import User
|
||||
from user.models import User, Team
|
||||
from django.db import models, transaction
|
||||
from django.db.models import QuerySet, Sum
|
||||
from django.http import HttpRequest
|
||||
@@ -299,7 +299,7 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
# Compensations inherit their shared state from the interventions
|
||||
return self.intervention.is_shared_with(user)
|
||||
|
||||
def share_with(self, user: User):
|
||||
def share_with_user(self, user: User):
|
||||
""" Adds user to list of shared access users
|
||||
|
||||
Args:
|
||||
@@ -308,10 +308,9 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not self.intervention.is_shared_with(user):
|
||||
self.intervention.users.add(user)
|
||||
self.intervention.users.add(user)
|
||||
|
||||
def share_with_list(self, user_list: list):
|
||||
def share_with_user_list(self, user_list: list):
|
||||
""" Sets the list of shared access users
|
||||
|
||||
Args:
|
||||
@@ -322,6 +321,28 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
"""
|
||||
self.intervention.users.set(user_list)
|
||||
|
||||
def share_with_team(self, team: Team):
|
||||
""" Adds team to list of shared access teams
|
||||
|
||||
Args:
|
||||
team (Team): The team to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.intervention.teams.add(team)
|
||||
|
||||
def share_with_team_list(self, team_list: list):
|
||||
""" Sets the list of shared access teams
|
||||
|
||||
Args:
|
||||
team_list (list): The teams to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.intervention.teams.set(team_list)
|
||||
|
||||
@property
|
||||
def shared_users(self) -> QuerySet:
|
||||
""" Shortcut for fetching the users which have shared access on this object
|
||||
@@ -331,6 +352,15 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
"""
|
||||
return self.intervention.users.all()
|
||||
|
||||
@property
|
||||
def shared_teams(self) -> QuerySet:
|
||||
""" Shortcut for fetching the teams which have shared access on this object
|
||||
|
||||
Returns:
|
||||
users (QuerySet)
|
||||
"""
|
||||
return self.intervention.teams.all()
|
||||
|
||||
def get_documents(self) -> QuerySet:
|
||||
""" Getter for all documents of a compensation
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||
self.eco_account.set_recorded(self.superuser)
|
||||
self.intervention.share_with_user(self.superuser)
|
||||
self.eco_account.refresh_from_db()
|
||||
self.assertIn(self.superuser, self.intervention.is_shared_with(self.superuser))
|
||||
self.assertTrue(self.superuser, self.intervention.is_shared_with(self.superuser))
|
||||
|
||||
deduction = EcoAccountDeduction.objects.create(
|
||||
intervention=self.intervention,
|
||||
|
||||
Reference in New Issue
Block a user