Commit 67a50452f6484a3d6ba6e7447d9e4f9603d21468

Authored by Alexis Koralewski
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
src/core/pyros_django/user_manager/forms.py
... ... @@ -61,9 +61,13 @@ class PyrosUserCreationForm(forms.ModelForm):
61 61 '''
62 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 68 pyros_user = PyrosUser.objects.create(username=self.cleaned_data['email'], email=self.cleaned_data['email'], country=Country.objects.all()[0],
65 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 71 pyros_user.set_password(self.cleaned_data['password'])
68 72 pyros_user.first_name = self.cleaned_data['first_name']
69 73 pyros_user.last_name = self.cleaned_data['last_name']
... ... @@ -72,8 +76,8 @@ class PyrosUserCreationForm(forms.ModelForm):
72 76 UserLevel.objects.get(name = "Visitor").pyros_users.add(pyros_user)
73 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 81 # sending mail to new user
78 82 send_mail(
79 83 '[PyROS CC] Registration',
... ... @@ -85,9 +89,6 @@ class PyrosUserCreationForm(forms.ModelForm):
85 89  
86 90 domain = settings.DEFAULT_DOMAIN
87 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 92 # sending mail to admin
92 93 send_mail(
93 94 '[PyROS CC] New registration',
... ...
src/core/pyros_django/user_manager/templates/user_manager/user_detail.html
... ... @@ -77,9 +77,9 @@
77 77 {% endif %}
78 78 {% if CAN_VIEW_VALIDATOR %}
79 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 83 {% endif %}
84 84 {% if CAN_EDIT_USER %}
85 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 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 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 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 276 scientific_programs = []
276 277 for sp_period in sp_periods:
277 278  
... ... @@ -287,7 +288,8 @@ def user_detail_view(request,pk):
287 288 "CAN_VIEW_VALIDATOR": CAN_VIEW_VALIDATOR,
288 289 "CAN_DELETE_USER": CAN_DELETE_USER,
289 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 295 @login_required
... ...