Skip to content

Commit

Permalink
patron: change message on expired account
Browse files Browse the repository at this point in the history
* Closes #2920.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Apr 5, 2023
1 parent fe899d3 commit 7e86e34
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rero_ils/modules/patrons/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019-2022 RERO
# Copyright (C) 2019-2022 UCLouvain
# Copyright (C) 2019-2023 RERO
# Copyright (C) 2019-2023 UCLouvain
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -440,15 +440,15 @@ def get_circulation_messages(self, public=False):
# if patron is blocked - error type message
# if patron is blocked, no need to return any other circulation
# messages !
if self.is_blocked:
if not public and self.is_blocked:
return [{
'type': 'error',
'content': self.get_blocked_message(public)
}]

messages = []
# if patron expiration_date has reached - error type message
if self.is_expired:
if not public and self.is_expired:
messages.append({
'type': 'error',
'content': _('Patron rights expired.')
Expand Down Expand Up @@ -586,7 +586,7 @@ def can_request(cls, item, **kwargs):
if patron.is_blocked:
messages.append(patron.get_blocked_message())
if patron.is_expired:
messages.append(_('Patron rights expired.'))
messages.append(_('Patron account expired.'))

return not messages, messages

Expand Down
24 changes: 24 additions & 0 deletions rero_ils/modules/patrons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,27 @@ def get_institution_code(institution):
data['patron_types'] = patron_types

return jsonify(data)


@blueprint.add_app_template_global
def patron_message():
"""Get patron message."""
if not current_patrons:
return
data = {
'show_info': False,
'data': {}
}
for patron in current_patrons:
if (patron.is_blocked or patron.is_expired):
data['show_info'] = True
organisation = patron.organisation
data['data'][organisation['code']] = {
'name': organisation['name'],
'blocked': {
'is_blocked': patron.is_blocked,
'message': patron.get_blocked_message(public=True)
},
'is_expired': patron.is_expired
}
return data
4 changes: 4 additions & 0 deletions rero_ils/theme/assets/scss/rero_ils/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ header {
.rero-ils-second-menu:not(.d-none){
border-top: solid #F0F0F0 1px;
}

.patron-info-message {
background: rgba(255,243,205, 1);
}
52 changes: 52 additions & 0 deletions rero_ils/theme/templates/rero_ils/_patron_info_message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{# -*- coding: utf-8 -*-

RERO ILS
Copyright (C) 2023 RERO
Copyright (C) 2023 UCLouvain

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

#}
{% set patron_message = patron_message() %}
{% if patron_message and patron_message.show_info %}
<div class="patron-info-message">
<div class="container mt-0">
{% set view = viewcode or config.RERO_ILS_SEARCH_GLOBAL_VIEW_CODE %}
{% if view == config.RERO_ILS_SEARCH_GLOBAL_VIEW_CODE %}
<ul class="list-unstyled py-2 mb-0">
{% for key, patron in patron_message.data.items() %}
{% if patron.blocked.is_blocked or patron.is_expired %}
<li class="py-1">
<span class="font-weight-bold">{{ patron.name }}</span>
{% with data=patron %}
{%- include "rero_ils/_patron_info_message_data.html" -%}
{% endwith %}
</li>
{% endif %}
{% endfor %}
</ul>
{% else %}
{% if view in patron_message.data %}
{% set message = patron_message.data[view] %}
{% if message.blocked.is_blocked or message.is_expired %}
<div class="py-2">
{% with data=message %}
{%- include "rero_ils/_patron_info_message_data.html" -%}
{% endwith %}
</div>
{% endif %}
{% endif %}
{% endif %}
</div>
</div>
{% endif %}
25 changes: 25 additions & 0 deletions rero_ils/theme/templates/rero_ils/_patron_info_message_data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{# -*- coding: utf-8 -*-

RERO ILS
Copyright (C) 2023 RERO
Copyright (C) 2023 UCLouvain

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

#}
{% if data.blocked.is_blocked %}
<div class="message-blocked">{{ data.blocked.message }}</div>
{% endif %}
{% if data.is_expired %}
<div class="message-expired">{{ _('Your account has expired.') }} {{ _('Please contact your library.') }}</div>
{% endif %}
4 changes: 4 additions & 0 deletions rero_ils/theme/templates/rero_ils/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
</div>
</nav>

<!-- start info patron -->
{%- include "rero_ils/_patron_info_message.html" %}
<!-- end info patron -->

<!-- Info message (not in production) -->
{% if not config.RERO_ILS_STATE_PRODUCTION %}
<h5 class="text-center bg-danger text-white py-2 mb-0">
Expand Down
68 changes: 68 additions & 0 deletions tests/ui/test_patron_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2023 RERO
# Copyright (C) 2023 UCLouvain
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Tests message UI view for patrons."""

from bs4 import BeautifulSoup
from flask import url_for
from invenio_accounts.testutils import login_user_via_view


def test_info_message(app, client, patron_martigny, patron_martigny_data,
org_martigny_data):
"""Test info message."""
patron_martigny['patron']['blocked'] = True
patron_martigny['patron']['blocked_note'] = 'This is a blocked message.'
patron_martigny['patron']['expiration_date'] = '2022-12-31'
patron_martigny.update(patron_martigny, dbcommit=True, reindex=True)

blocked_message = patron_martigny['patron']['blocked_note']

# If the user is not identified, there is no user information
res = client.get('/')
soup = BeautifulSoup(res.data, 'html.parser')
assert soup.find('div', {"class": "patron-info-message"}) is None

login_user_via_view(
client,
email=patron_martigny_data['email'],
password=patron_martigny_data['password'])

# If the user is identified, we see the name of the organization
# and the message on the global view
res = client.get(url_for('rero_ils.index'))
soup = BeautifulSoup(res.data, 'html.parser')
li = soup.find('div', {"class": "patron-info-message"}).find('li')

assert org_martigny_data['name'] == li.find('span').text
assert f'Your account is currently blocked. Reason: {blocked_message}' \
== li.find('div', {"class": "message-blocked"}).text
assert 'Your account has expired. Please contact your library.'\
== li.find('div', {"class": "message-expired"}).text

# If the view of the organization, there is no name of it
res = client.get(url_for(
'rero_ils.index_with_view_code', viewcode=org_martigny_data['code']))
soup = BeautifulSoup(res.data, 'html.parser')
div = soup.find('div', {"class": "patron-info-message"})

assert div.find('span') is None
assert f'Your account is currently blocked. Reason: {blocked_message}' \
== div.find('div', {"class": "message-blocked"}).text
assert 'Your account has expired. Please contact your library.'\
== div.find('div', {"class": "message-expired"}).text

0 comments on commit 7e86e34

Please sign in to comment.