mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-10-31 15:50:03 +01:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			238ba78f4f
			...
			9e7f7df721
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 9e7f7df721 | ||
|  | 62baad7b69 | ||
|  | 6e49140900 | ||
|  | e5567c6c8a | 
| @@ -15,7 +15,6 @@ from django.utils.translation import gettext_lazy as _ | |||||||
| from note.models import NoteSpecial, Alias | from note.models import NoteSpecial, Alias | ||||||
| from note_kfet.inputs import Autocomplete, AmountInput | from note_kfet.inputs import Autocomplete, AmountInput | ||||||
| from permission.models import PermissionMask, Role | from permission.models import PermissionMask, Role | ||||||
| from permission.backends import PermissionBackend |  | ||||||
| from PIL import Image, ImageSequence | from PIL import Image, ImageSequence | ||||||
|  |  | ||||||
| from .models import Profile, Club, Membership | from .models import Profile, Club, Membership | ||||||
| @@ -68,14 +67,6 @@ class ProfileForm(forms.ModelForm): | |||||||
|         self.fields['address'].widget.attrs.update({"placeholder": "4 avenue des Sciences, 91190 GIF-SUR-YVETTE"}) |         self.fields['address'].widget.attrs.update({"placeholder": "4 avenue des Sciences, 91190 GIF-SUR-YVETTE"}) | ||||||
|         self.fields['promotion'].widget.attrs.update({"max": timezone.now().year}) |         self.fields['promotion'].widget.attrs.update({"max": timezone.now().year}) | ||||||
|  |  | ||||||
|     def clean(self): |  | ||||||
|         """Force the values of fields that the user does not have permission to modify..""" |  | ||||||
|         cleaned_data = super().clean() |  | ||||||
|         for field_name in self.fields.keys(): |  | ||||||
|             if not PermissionBackend.check_perm(self.request, f"member.change_profile_{field_name}", self.instance): |  | ||||||
|                 cleaned_data[field_name] = getattr(self.instance, field_name)  # Force the old value |  | ||||||
|         return cleaned_data |  | ||||||
|  |  | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|     def save(self, commit=True): |     def save(self, commit=True): | ||||||
|         if not self.instance.section or (("department" in self.changed_data |         if not self.instance.section or (("department" in self.changed_data | ||||||
|   | |||||||
| @@ -79,12 +79,16 @@ class UserUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView): | |||||||
|             del profile_form.fields["last_report"] |             del profile_form.fields["last_report"] | ||||||
|  |  | ||||||
|         fields_to_check = list(profile_form.fields.keys()) |         fields_to_check = list(profile_form.fields.keys()) | ||||||
|  |         fields_modifiable = False  | ||||||
|  |  | ||||||
|         # Delete the fields for which the user does not have the permission to modify |         # Delete the fields for which the user does not have the permission to modify | ||||||
|         for field_name in fields_to_check: |         for field_name in fields_to_check: | ||||||
|             if not PermissionBackend.check_perm(self.request, f"member.change_profile_{field_name}", context['user_object'].profile): |             if not PermissionBackend.check_perm(self.request, f"member.change_profile_{field_name}", context['user_object'].profile): | ||||||
|                 profile_form.fields[field_name].widget = forms.HiddenInput() |                 profile_form.fields[field_name].widget = forms.HiddenInput() | ||||||
|  |             else : | ||||||
|  |                 fields_modifiable = True | ||||||
|  |  | ||||||
|  |         if fields_modifiable : | ||||||
|             context['profile_form'] = profile_form |             context['profile_form'] = profile_form | ||||||
|  |  | ||||||
|         return context |         return context | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user