Refactoring
* moves updating of shared access users into Intervention
This commit is contained in:
@@ -135,45 +135,6 @@ class BaseObject(BaseResource):
|
||||
)
|
||||
self.log.add(user_action)
|
||||
|
||||
def is_shared_with(self, user: User):
|
||||
""" Access check
|
||||
|
||||
Checks whether a given user has access to this object
|
||||
|
||||
Args:
|
||||
user ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if isinstance(self, ShareableObjectMixin):
|
||||
return self.users.filter(id=user.id)
|
||||
else:
|
||||
return User.objects.none()
|
||||
|
||||
def share_with(self, user: User):
|
||||
""" Adds user to list of shared access users
|
||||
|
||||
Args:
|
||||
user (User): The user to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not self.is_shared_with(user):
|
||||
self.users.add(user)
|
||||
|
||||
def share_with_list(self, user_list: list):
|
||||
""" Sets the list of shared access users
|
||||
|
||||
Args:
|
||||
user_list (list): The users to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.users.set(user_list)
|
||||
|
||||
def generate_new_identifier(self) -> str:
|
||||
""" Generates a new identifier for the intervention object
|
||||
|
||||
@@ -398,4 +359,40 @@ class ShareableObjectMixin(models.Model):
|
||||
self.generate_access_token(make_unique, rec_depth)
|
||||
else:
|
||||
self.access_token = token
|
||||
self.save()
|
||||
self.save()
|
||||
|
||||
def is_shared_with(self, user: User):
|
||||
""" Access check
|
||||
|
||||
Checks whether a given user has access to this object
|
||||
|
||||
Args:
|
||||
user ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.users.filter(id=user.id)
|
||||
|
||||
def share_with(self, user: User):
|
||||
""" Adds user to list of shared access users
|
||||
|
||||
Args:
|
||||
user (User): The user to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not self.is_shared_with(user):
|
||||
self.users.add(user)
|
||||
|
||||
def share_with_list(self, user_list: list):
|
||||
""" Sets the list of shared access users
|
||||
|
||||
Args:
|
||||
user_list (list): The users to be added to the object
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.users.set(user_list)
|
||||
|
||||
Reference in New Issue
Block a user