Skip to content
Snippets Groups Projects
Commit efd13acc authored by Carlos Vega's avatar Carlos Vega
Browse files

added a way to retrieve the permissions of the worker for a certain study

parent bf279d6f
No related branches found
No related tags found
1 merge request!192Feature/add way to change password and PERMISSIONS
...@@ -18,6 +18,7 @@ from web.models.holiday import Holiday ...@@ -18,6 +18,7 @@ from web.models.holiday import Holiday
from web.models.availability import Availability from web.models.availability import Availability
from web.models.appointment import Appointment from web.models.appointment import Appointment
from web.models.appointment_type_link import AppointmentTypeLink from web.models.appointment_type_link import AppointmentTypeLink
from django.contrib.auth.models import Permission
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -227,6 +228,25 @@ class Worker(models.Model): ...@@ -227,6 +228,25 @@ class Worker(models.Model):
return office_availability.get_availability_percentage(only_working_hours=True) return office_availability.get_availability_percentage(only_working_hours=True)
def get_permissions(self, study):
if self.user.is_superuser:
return set([p.codename for p in Permission.objects.all()])
roles = self.roles.filter(study=study)
if roles.count() == 0:
return set()
return set(p.codename for p in roles[0].permissions.all())
def has_perm(self, codename, study):
roles = self.roles.filter(study=study)
if roles.count() == 0:
return False
if role[0].permissions.filter(codename=codename).all().count() > 0:
return True
else:
return False
@property @property
def role(self): def role(self):
roles = self.roles.filter(study=GLOBAL_STUDY_ID) roles = self.roles.filter(study=GLOBAL_STUDY_ID)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment