Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed RA user can approve reservation issues #280

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion respa_admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,13 @@
user_has_unit_group_auth = self.request.user.unit_group_authorizations.to_unit(unit).admin_level().exists()
can_approve_initial_value = permission_checker.has_perm(
"unit:can_approve_reservation", self.instance.subject
) or self.instance.subject.is_manager(self.instance.authorized)
)
if not user_has_unit_auth and not user_has_unit_group_auth:
self.fields['subject'].disabled = True
self.fields['level'].disabled = True
self.fields['can_approve_reservation'].disabled = True
self.is_disabled = True
self.fields['can_approve_reservation'].widget.attrs['data-unit-id'] = f'{unit.id}'

Check warning on line 742 in respa_admin/forms.py

View check run for this annotation

Codecov / codecov/patch

respa_admin/forms.py#L742

Added line #L742 was not covered by tests
self.fields['can_approve_reservation'].initial = can_approve_initial_value

def clean(self):
Expand All @@ -750,6 +751,8 @@
if not user_has_unit_auth and not user_has_unit_group_auth:
self.add_error('subject', _('You can\'t add, change or delete permissions to unit you are not admin of'))
self.cleaned_data[DELETION_FIELD_NAME] = False
if self.cleaned_data[DELETION_FIELD_NAME]:
self.cleaned_data['can_approve_reservation'] = False

Check warning on line 755 in respa_admin/forms.py

View check run for this annotation

Codecov / codecov/patch

respa_admin/forms.py#L755

Added line #L755 was not covered by tests
return cleaned_data

class Meta:
Expand Down
18 changes: 17 additions & 1 deletion respa_admin/static_src/js/userForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,25 @@ function updateAllPermissionMgmtFormIndices() {
}
}

function canApproveReservationsListener() {
$('[id*="-can_approve_reservation"]').on('click', handleCanApproveReservationsChange);
}

function handleCanApproveReservationsChange(event) {
const unitId = $(this).closest('.custom-checkbox').attr('data-unit-id')
const value = event.currentTarget.checked
if (unitId) {
const $inputs = $('[data-unit-id="' + unitId + '"]');
$inputs.prop('checked', value)
}

initializeUserForm();
}

export function initializeUserFormEventHandlers() {
enableRemovePermission();
enableAddNewPermission();
setEmptyPermissionItem();
isStaffCheckboxListener();
}
canApproveReservationsListener();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2 class="pull-left">{% trans 'Unit management' %}</h2>
{% if unit_auths|length > 6 %}style="min-height: 690px;"{% endif %}>
{% for authorization in unit_auths %}
{% with authorization.authorized as unit_user %}
{% user_has_permission unit_user 'can_approve_reservation' unit as user_can_approve %}
{% user_has_permission unit_user 'unit:can_approve_reservation' unit as user_can_approve %}
<div class="row panel management-list list-item" data-paginator-item="true">
<div class="col-md-2">
<span>{{ unit_user.first_name }} {{ unit_user.last_name }}</span>
Expand Down
4 changes: 2 additions & 2 deletions respa_admin/templatetags/templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

@register.simple_tag
def user_has_permission(user, permission, obj):
return user.has_perm(permission, obj) or obj.is_manager(user)
return user.has_perm(permission, obj)

Check warning on line 44 in respa_admin/templatetags/templatetags.py

View check run for this annotation

Codecov / codecov/patch

respa_admin/templatetags/templatetags.py#L44

Added line #L44 was not covered by tests


@register.filter
Expand All @@ -51,4 +51,4 @@

@register.filter
def remove_empty(collection):
return [value for value in collection if bool(value)]
return [value for value in collection if bool(value)]
Loading