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

selfcheck: add column for comments #2744

Merged
merged 1 commit into from
Mar 10, 2022
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
49 changes: 49 additions & 0 deletions rero_ils/alembic/b90f8b148948_add_column_to_selfcheck_terminals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2022 RERO
# Copyright (C) 2022 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/>.

"""Add column to selfcheck_terminals."""

from logging import getLogger

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = 'b90f8b148948'
down_revision = '54134957af7d'
branch_labels = ()
depends_on = None

LOGGER = getLogger('alembic')


def upgrade():
"""Upgrade database."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('selfcheck_terminals', sa.Column('comments', sa.Text(),
nullable=True))
LOGGER.info(f'column added.')
# ### end Alembic commands ###


def downgrade():
"""Downgrade database."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('selfcheck_terminals', 'comments')
LOGGER.info(f'column dropped.')
# ### end Alembic commands ###
15 changes: 12 additions & 3 deletions rero_ils/modules/selfcheck/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
@click.option(
'-t', '--access_token', 'access_token', required=False,
help='personalized access_token.')
@click.option(
'-c', '--comments', 'comments', required=False,
help='comments for selfcheck terminal.')
@with_appcontext
def create_terminal(name, user, location_pid, scopes, internal,
access_token):
access_token, comments):
"""Create a personal OAuth token."""
# avoid circular import
from rero_ils.modules.cli.utils import create_personal
Expand Down Expand Up @@ -83,7 +86,8 @@ def create_terminal(name, user, location_pid, scopes, internal,
access_token=access_token,
organisation_pid=location.organisation['pid'],
library_pid=location.library['pid'],
location_pid=location_pid
location_pid=location_pid,
comments=comments
)
db.session.add(selfcheck_terminal)
db.session.commit()
Expand All @@ -104,6 +108,7 @@ def list_terminal():
click.echo(f'\tlocation_pid : {terminal.location_pid}')
click.echo(f'\tactive : {terminal.active}')
click.echo(f'\tlast login : {terminal.last_login_at}')
click.echo(f'\tcomments : {terminal.comments}')


@click.command('update_terminal')
Expand All @@ -112,8 +117,10 @@ def list_terminal():
@click.option('-d', '--disable', 'disable', is_flag=True, default=False)
@click.option('-l', '--loc-pid', 'location_pid')
@click.option('-t', '--access-token', 'access_token')
@click.option('-c', '--comments', 'comments')
@with_appcontext
def update_terminal(name, enable, disable, location_pid, access_token):
def update_terminal(name, enable, disable, location_pid, access_token,
comments):
"""Update the given terminal."""
terminal = SelfcheckTerminal.find_terminal(name=name)
if terminal:
Expand All @@ -137,6 +144,8 @@ def update_terminal(name, enable, disable, location_pid, access_token):
f'{access_token}',
fg='yellow'
)
if comments:
terminal.comments = comments
db.session.merge(terminal)
db.session.commit()
click.secho(f'{name} updated', fg='green')
1 change: 1 addition & 0 deletions rero_ils/modules/selfcheck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SelfcheckTerminal(db.Model):
active = db.Column(db.Boolean(name='active'), default=True)
last_login_at = db.Column(db.DateTime)
last_login_ip = db.Column(IPAddressType, nullable=True)
comments = db.Column(db.Text, nullable=True)

@classmethod
def find_terminal(cls, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions tests/api/selfcheck/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_selfcheckuser(app):
organisation_pid='org1',
library_pid='lib1',
location_pid='loc1',
comments='a new comment',
)
# 1. test create selfcheck user
assert not selfcheck_terminal.active
Expand All @@ -54,6 +55,7 @@ def test_selfcheckuser(app):
organisation_pid='org1',
library_pid='lib1',
location_pid='loc1',
comments='an updated comment',
)
db.session.merge(selfcheck_terminal_patch)
db.session.commit()
Expand All @@ -65,6 +67,7 @@ def test_selfcheckuser(app):
organisation_pid='org1',
library_pid='lib1',
location_pid='loc2',
comments='a third comment',
)
db.session.add(selfcheck_terminal)
pytest.raises(IntegrityError, db.session.commit)