Skip to content

Commit

Permalink
Merge pull request #390 from City-of-Turku/develop
Browse files Browse the repository at this point in the history
Release tku-v1.13

Notable changes:
- fix to resource staff emails field
- removed "is staff" status from RA user forms
  • Loading branch information
SanttuA authored Sep 9, 2024
2 parents 4063eb3 + 5c360b4 commit f1da6d4
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ msgid "You must end the reservation after it has begun"
msgstr "Varauksen loppuaika ei voi olla ennen alkuaikaa"

msgid "Begin and end time must match time slots"
msgstr "Tarkista aikarajoitteet"
msgstr "Aloitus- ja lopetusajan on vastattava määritettyjä aikaslotteja"

msgid "This unit does not allow overlapping reservations for its resources"
msgstr "Tämä toimipiste ei salli päällekkäisiä varauksia resurssien välillä"
Expand Down
12 changes: 12 additions & 0 deletions resources/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ..models.utils import generate_id
from munigeo.models import Municipality
from rest_framework.authtoken.admin import Token
from respa_admin.forms import RespaMultiEmailField

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -144,12 +145,23 @@ def hard_delete_resources(modeladmin, request, queryset):
hard_delete_resources.short_description = _('Hard delete selected resources')


class ResourceAdminForm(forms.ModelForm):
resource_staff_emails = RespaMultiEmailField(
required=False,
label=_('E-mail addresses for client correspondence')
)
class Meta:
model = Resource
fields = '__all__'

class ResourceAdmin(PopulateCreatedAndModifiedMixin, CommonExcludeMixin,
TranslationAdmin, HttpsFriendlyGeoAdmin):
default_lon = 2478871 # Central Railway Station in EPSG:3857
default_lat = 8501259
default_zoom = 12

form = ResourceAdminForm

list_display = ('name', 'unit', '_public', 'reservable', 'soft_deleted')
list_filter = ('unit', '_public', 'reservable', 'soft_deleted')
list_select_related = ('unit',)
Expand Down
3 changes: 3 additions & 0 deletions resources/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ def get_db_prep_value(self, value, connection, prepared):
if isinstance(value, list):
return '\n'.join(value)
return value

def from_db_value(self, value, *args, **kwargs):
return self.to_python(value)
2 changes: 1 addition & 1 deletion respa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = 'tku-v1.12'
__version__ = 'tku-v1.13'

VERSION = __version__
3 changes: 3 additions & 0 deletions respa_admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def to_python(self, value):
if isinstance(value, list):
return value
return [val.strip() for val in value.splitlines() if val]

def prepare_value(self, value):
return self.to_python(value)


class ResourceForm(forms.ModelForm):
Expand Down
8 changes: 4 additions & 4 deletions respa_admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ <h2 class="pull-left">{% trans 'unit authorizations'|capfirst %}</h2>
</div>
</div>
<div class="col-md-8">
<div>
<span class="{% if unit_user.is_staff %}shape-success{% else %}shape-danger{% endif %}"></span>
<span>{% trans 'Staff' %}</span>
</div>
<div>
<span class="{% if user_can_approve %}shape-success{% else %}shape-danger{% endif %}"></span>
<span>{% trans 'Can approve reservations' %}</span>
Expand Down
4 changes: 0 additions & 4 deletions respa_admin/templates/respa_admin/resources/_user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ <h2 class="pull-left">{% trans 'Users by search term' %}: {{ search_query }} ({{
<span>{{ user.email }}</span>
</div>
<div class="col-md-3">
<div>
<span class="{% if user.is_staff %}shape-success{% else %}shape-danger{% endif %}"></span>
<span>{% trans 'Staff' %}</span>
</div>
</div>
{% if user != request.user or request.user.is_superuser %}
<div class="col-md-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ <h2>{% trans "User profile" %}</h2>
<span>{{ user_object.email }}</span>
<div>
{% include "respa_admin/forms/_errors.html" with field=form.is_staff %}
{{ form.is_staff }}
</div>
</div>
</div>
Expand Down
23 changes: 12 additions & 11 deletions respa_admin/views/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,6 @@ def _validate_forms(self, form, unit_authorization_formset):
valid_form = form.is_valid()
valid_unit_authorization_formset = unit_authorization_formset.is_valid()

if valid_unit_authorization_formset:
perms_are_empty_or_marked_for_deletion = all(
{"DELETE": True}.items() <= dict.items() or len(dict) == 0
for dict in unit_authorization_formset.cleaned_data
)

if not form.cleaned_data['is_staff'] and not perms_are_empty_or_marked_for_deletion:
form.add_error(None, _('You can\'t remove staff status from user with existing permissions'))
return False

return valid_form and valid_unit_authorization_formset

def get_context_data(self, **kwargs):
Expand All @@ -161,6 +151,17 @@ def post(self, request, *args, **kwargs):
return self.forms_valid(form, unit_authorization_formset)
else:
return self.forms_invalid(form, unit_authorization_formset)

def _manage_staff_status(self):
if not UnitAuthorization.objects.for_user(self.object).exists():
self.object.is_staff = False
self.object.save()
return

if not self.object.is_staff:
self.object.is_staff = True
self.object.save()
return

def forms_valid(self, form, unit_authorization_formset):
user = self.request.user
Expand Down Expand Up @@ -191,7 +192,7 @@ def forms_valid(self, form, unit_authorization_formset):
for _, unit_auths in itertools.groupby(unit_auths, lambda unit_auth: unit_auth.subject):
max(unit_auths)._ensure_lower_auth()


self._manage_staff_status()
return HttpResponseRedirect(self.get_success_url())

def forms_invalid(self, form, unit_authorization_formset):
Expand Down

0 comments on commit f1da6d4

Please sign in to comment.