Commit 67a50452f6484a3d6ba6e7447d9e4f9603d21468
1 parent
81f42637
Exists in
dev
Add variable to check who can see motive of registration for an user (Admin,Unit…
…-PI,Unit-board), Add Wished roles values into motive of registration
Showing
3 changed files
with
13 additions
and
10 deletions
Show diff stats
src/core/pyros_django/user_manager/forms.py
@@ -61,9 +61,13 @@ class PyrosUserCreationForm(forms.ModelForm): | @@ -61,9 +61,13 @@ class PyrosUserCreationForm(forms.ModelForm): | ||
61 | ''' | 61 | ''' |
62 | Creates a User and a PyrosUser in DB | 62 | Creates a User and a PyrosUser in DB |
63 | ''' | 63 | ''' |
64 | + wished_roles = "" | ||
65 | + for role in self.cleaned_data["roles"]: | ||
66 | + wished_roles+= f"{role} " | ||
67 | + # we're adding the wished roles to the motive of registration so the unit-pi and unit-board can find this information later without reading again the email | ||
64 | pyros_user = PyrosUser.objects.create(username=self.cleaned_data['email'], email=self.cleaned_data['email'], country=Country.objects.all()[0], | 68 | pyros_user = PyrosUser.objects.create(username=self.cleaned_data['email'], email=self.cleaned_data['email'], country=Country.objects.all()[0], |
65 | tel=self.cleaned_data['tel'], laboratory=self.cleaned_data['laboratory'], | 69 | tel=self.cleaned_data['tel'], laboratory=self.cleaned_data['laboratory'], |
66 | - address=self.cleaned_data['address'], institute=self.cleaned_data["institute"], motive_of_registration=self.cleaned_data["reason"]) | 70 | + address=self.cleaned_data['address'], institute=self.cleaned_data["institute"], motive_of_registration=self.cleaned_data["reason"]+f"\n, Wished role(s) : {wished_roles}") |
67 | pyros_user.set_password(self.cleaned_data['password']) | 71 | pyros_user.set_password(self.cleaned_data['password']) |
68 | pyros_user.first_name = self.cleaned_data['first_name'] | 72 | pyros_user.first_name = self.cleaned_data['first_name'] |
69 | pyros_user.last_name = self.cleaned_data['last_name'] | 73 | pyros_user.last_name = self.cleaned_data['last_name'] |
@@ -72,8 +76,8 @@ class PyrosUserCreationForm(forms.ModelForm): | @@ -72,8 +76,8 @@ class PyrosUserCreationForm(forms.ModelForm): | ||
72 | UserLevel.objects.get(name = "Visitor").pyros_users.add(pyros_user) | 76 | UserLevel.objects.get(name = "Visitor").pyros_users.add(pyros_user) |
73 | pyros_user.save() | 77 | pyros_user.save() |
74 | 78 | ||
75 | - # get list of admin and Unit-PI users | ||
76 | - unit_PI = PyrosUser.objects.filter(user_level__name="Unit-PI").distinct().values_list("email",flat=True) | 79 | + # get list of Unit-PI and Unit-board users |
80 | + unit_PI = PyrosUser.objects.filter(user_level__name__in=("Unit-PI","Unit-board")).distinct().values_list("email",flat=True) | ||
77 | # sending mail to new user | 81 | # sending mail to new user |
78 | send_mail( | 82 | send_mail( |
79 | '[PyROS CC] Registration', | 83 | '[PyROS CC] Registration', |
@@ -85,9 +89,6 @@ class PyrosUserCreationForm(forms.ModelForm): | @@ -85,9 +89,6 @@ class PyrosUserCreationForm(forms.ModelForm): | ||
85 | 89 | ||
86 | domain = settings.DEFAULT_DOMAIN | 90 | domain = settings.DEFAULT_DOMAIN |
87 | url = f"{domain}{reverse('user_detail',args=(pyros_user.pk,))}" | 91 | url = f"{domain}{reverse('user_detail',args=(pyros_user.pk,))}" |
88 | - wished_roles = "" | ||
89 | - for role in self.cleaned_data["roles"]: | ||
90 | - wished_roles+= f"{role} " | ||
91 | # sending mail to admin | 92 | # sending mail to admin |
92 | send_mail( | 93 | send_mail( |
93 | '[PyROS CC] New registration', | 94 | '[PyROS CC] New registration', |
src/core/pyros_django/user_manager/templates/user_manager/user_detail.html
@@ -77,9 +77,9 @@ | @@ -77,9 +77,9 @@ | ||
77 | {% endif %} | 77 | {% endif %} |
78 | {% if CAN_VIEW_VALIDATOR %} | 78 | {% if CAN_VIEW_VALIDATOR %} |
79 | <p><strong>Validator : </strong>{{ user.validator }}</p> | 79 | <p><strong>Validator : </strong>{{ user.validator }}</p> |
80 | - {% if user.motive_of_registration|length > 0 %} | ||
81 | - <p><strong>Motive of registration : </strong>{{ user.motive_of_registration }}</p> | ||
82 | - {% endif %} | 80 | + {% endif %} |
81 | + {% if CAN_VIEW_MOTIVE_OF_REGISTRATION %} | ||
82 | + <p><strong>Motive of registration : </strong>{{ user.motive_of_registration|linebreaks }}</p> | ||
83 | {% endif %} | 83 | {% endif %} |
84 | {% if CAN_EDIT_USER %} | 84 | {% if CAN_EDIT_USER %} |
85 | <a href="{% url "user-edit" user.pk %}" class="btn btn-info" role="button">Edit</a> | 85 | <a href="{% url "user-edit" user.pk %}" class="btn btn-info" role="button">Edit</a> |
src/core/pyros_django/user_manager/views.py
@@ -272,6 +272,7 @@ def user_detail_view(request,pk): | @@ -272,6 +272,7 @@ def user_detail_view(request,pk): | ||
272 | CAN_DELETE_USER = not is_last_user and request.session.get("role") in ("Admin","Unit-PI","Unit-board") and not user.is_superuser and request.user != user | 272 | CAN_DELETE_USER = not is_last_user and request.session.get("role") in ("Admin","Unit-PI","Unit-board") and not user.is_superuser and request.user != user |
273 | CAN_ACTIVATE_USER = not is_last_user and request.session.get("role") in ("Admin","Unit-PI","Unit-board") and not user.is_superuser and request.user != user | 273 | CAN_ACTIVATE_USER = not is_last_user and request.session.get("role") in ("Admin","Unit-PI","Unit-board") and not user.is_superuser and request.user != user |
274 | CAN_EDIT_USER = request.user.id == pk or request.session.get("role") in ("Admin","Unit-PI","Unit-board") | 274 | CAN_EDIT_USER = request.user.id == pk or request.session.get("role") in ("Admin","Unit-PI","Unit-board") |
275 | + CAN_VIEW_MOTIVE_OF_REGISTRATION = request.session.get("role") in ("Admin","Unit-PI","Unit-board") and len(user.motive_of_registration) > 0 | ||
275 | scientific_programs = [] | 276 | scientific_programs = [] |
276 | for sp_period in sp_periods: | 277 | for sp_period in sp_periods: |
277 | 278 | ||
@@ -287,7 +288,8 @@ def user_detail_view(request,pk): | @@ -287,7 +288,8 @@ def user_detail_view(request,pk): | ||
287 | "CAN_VIEW_VALIDATOR": CAN_VIEW_VALIDATOR, | 288 | "CAN_VIEW_VALIDATOR": CAN_VIEW_VALIDATOR, |
288 | "CAN_DELETE_USER": CAN_DELETE_USER, | 289 | "CAN_DELETE_USER": CAN_DELETE_USER, |
289 | "CAN_ACTIVATE_USER": CAN_ACTIVATE_USER, | 290 | "CAN_ACTIVATE_USER": CAN_ACTIVATE_USER, |
290 | - "CAN_EDIT_USER": CAN_EDIT_USER | 291 | + "CAN_EDIT_USER": CAN_EDIT_USER, |
292 | + "CAN_VIEW_MOTIVE_OF_REGISTRATION":CAN_VIEW_MOTIVE_OF_REGISTRATION | ||
291 | }) | 293 | }) |
292 | 294 | ||
293 | @login_required | 295 | @login_required |