mpeltriaux
87fae51144
* adds button and functionality for leaving a team * if the admin leaves the team, another user will be chosen as new admin automatically * improves Team (django) admin backend * better control over user adding-removing * only added team members are selectable as admin
110 lines
3.0 KiB
Python
110 lines
3.0 KiB
Python
from django.db import models
|
|
|
|
from konova.models import UuidModel
|
|
from konova.utils.mailer import Mailer
|
|
|
|
|
|
class Team(UuidModel):
|
|
""" Groups users in self managed teams. Can be used for multi-sharing of data
|
|
|
|
"""
|
|
name = models.CharField(max_length=500, null=True, blank=True)
|
|
description = models.TextField(null=True, blank=True)
|
|
users = models.ManyToManyField("user.User", blank=True, related_name="teams")
|
|
admin = models.ForeignKey("user.User", blank=True, null=True, related_name="+", on_delete=models.SET_NULL)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
def send_mail_shared_access_given_team(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of given shared access
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_access_given_team(obj_identifier, obj_title, self)
|
|
|
|
def send_mail_shared_access_removed(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of removed shared access
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_access_removed_team(obj_identifier, obj_title, self)
|
|
|
|
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of unrecorded data
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_data_unrecorded_team(obj_identifier, obj_title, self)
|
|
|
|
def send_mail_shared_data_recorded(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of unrecorded data
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_data_recorded_team(obj_identifier, obj_title, self)
|
|
|
|
def send_mail_shared_data_checked(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of checked data
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_data_checked_team(obj_identifier, obj_title, self)
|
|
|
|
def send_mail_shared_data_deleted(self, obj_identifier, obj_title):
|
|
""" Sends a mail to the team members in case of deleted data
|
|
|
|
Args:
|
|
obj_identifier ():
|
|
obj_title ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
mailer = Mailer()
|
|
mailer.send_mail_shared_data_deleted_team(obj_identifier, obj_title, self)
|
|
|
|
def remove_user(self, user):
|
|
""" Removes a user from the team
|
|
|
|
Args:
|
|
user (User): The user to be removed
|
|
|
|
Returns:
|
|
|
|
"""
|
|
self.users.remove(user)
|
|
if self.admin == user:
|
|
self.admin = self.users.first()
|
|
self.save()
|