diff --git a/src/core/pyros_django/user_manager/forms.py b/src/core/pyros_django/user_manager/forms.py index 49a7c6c..dd519ec 100644 --- a/src/core/pyros_django/user_manager/forms.py +++ b/src/core/pyros_django/user_manager/forms.py @@ -61,9 +61,13 @@ class PyrosUserCreationForm(forms.ModelForm): ''' Creates a User and a PyrosUser in DB ''' + wished_roles = "" + for role in self.cleaned_data["roles"]: + wished_roles+= f"{role} " + # 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 pyros_user = PyrosUser.objects.create(username=self.cleaned_data['email'], email=self.cleaned_data['email'], country=Country.objects.all()[0], tel=self.cleaned_data['tel'], laboratory=self.cleaned_data['laboratory'], - address=self.cleaned_data['address'], institute=self.cleaned_data["institute"], motive_of_registration=self.cleaned_data["reason"]) + address=self.cleaned_data['address'], institute=self.cleaned_data["institute"], motive_of_registration=self.cleaned_data["reason"]+f"\n, Wished role(s) : {wished_roles}") pyros_user.set_password(self.cleaned_data['password']) pyros_user.first_name = self.cleaned_data['first_name'] pyros_user.last_name = self.cleaned_data['last_name'] @@ -72,8 +76,8 @@ class PyrosUserCreationForm(forms.ModelForm): UserLevel.objects.get(name = "Visitor").pyros_users.add(pyros_user) pyros_user.save() - # get list of admin and Unit-PI users - unit_PI = PyrosUser.objects.filter(user_level__name="Unit-PI").distinct().values_list("email",flat=True) + # get list of Unit-PI and Unit-board users + unit_PI = PyrosUser.objects.filter(user_level__name__in=("Unit-PI","Unit-board")).distinct().values_list("email",flat=True) # sending mail to new user send_mail( '[PyROS CC] Registration', @@ -85,9 +89,6 @@ class PyrosUserCreationForm(forms.ModelForm): domain = settings.DEFAULT_DOMAIN url = f"{domain}{reverse('user_detail',args=(pyros_user.pk,))}" - wished_roles = "" - for role in self.cleaned_data["roles"]: - wished_roles+= f"{role} " # sending mail to admin send_mail( '[PyROS CC] New registration', diff --git a/src/core/pyros_django/user_manager/templates/user_manager/user_detail.html b/src/core/pyros_django/user_manager/templates/user_manager/user_detail.html index 3e29ee1..472ccf3 100644 --- a/src/core/pyros_django/user_manager/templates/user_manager/user_detail.html +++ b/src/core/pyros_django/user_manager/templates/user_manager/user_detail.html @@ -77,9 +77,9 @@ {% endif %} {% if CAN_VIEW_VALIDATOR %}

Validator : {{ user.validator }}

- {% if user.motive_of_registration|length > 0 %} -

Motive of registration : {{ user.motive_of_registration }}

- {% endif %} + {% endif %} + {% if CAN_VIEW_MOTIVE_OF_REGISTRATION %} +

Motive of registration : {{ user.motive_of_registration|linebreaks }}

{% endif %} {% if CAN_EDIT_USER %} Edit diff --git a/src/core/pyros_django/user_manager/views.py b/src/core/pyros_django/user_manager/views.py index 8d03253..cca8719 100644 --- a/src/core/pyros_django/user_manager/views.py +++ b/src/core/pyros_django/user_manager/views.py @@ -272,6 +272,7 @@ def user_detail_view(request,pk): 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 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 CAN_EDIT_USER = request.user.id == pk or request.session.get("role") in ("Admin","Unit-PI","Unit-board") + CAN_VIEW_MOTIVE_OF_REGISTRATION = request.session.get("role") in ("Admin","Unit-PI","Unit-board") and len(user.motive_of_registration) > 0 scientific_programs = [] for sp_period in sp_periods: @@ -287,7 +288,8 @@ def user_detail_view(request,pk): "CAN_VIEW_VALIDATOR": CAN_VIEW_VALIDATOR, "CAN_DELETE_USER": CAN_DELETE_USER, "CAN_ACTIVATE_USER": CAN_ACTIVATE_USER, - "CAN_EDIT_USER": CAN_EDIT_USER + "CAN_EDIT_USER": CAN_EDIT_USER, + "CAN_VIEW_MOTIVE_OF_REGISTRATION":CAN_VIEW_MOTIVE_OF_REGISTRATION }) @login_required -- libgit2 0.21.2