Skip to content

Commit

Permalink
Merge branch 'release/0.4.4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mblomdahl committed Oct 25, 2017
2 parents 2c66443 + 870b88d commit 86b824f
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 33 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ DB Models
Changelog
=========

v. 0.4.4
--------

* Data import updates (`#44 <https://github.com/libris/xl_auth/issues/44>`_)
* UI adjustments; irrelevant permissions no longer shown to cataloging admins, using
term "sigel" instead of "kod"
* Ansible provisioning updated to use Nginx reverse proxy and SSL
(`#39 <https://github.com/libris/xl_auth/issues/39>`_)


v. 0.4.3
--------

Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/xl_auth/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
interactive: yes
tty: yes
detach: no
command: import_data --verbose --admin-email [email protected]
command: import_data --verbose --admin-email [email protected] --wipe-permissions
links:
- postgres
env:
Expand Down
20 changes: 10 additions & 10 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: xl_auth 0.4.3\n"
"Project-Id-Version: xl_auth 0.4.4\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2017-10-24 06:53+0200\n"
"POT-Creation-Date: 2017-10-25 13:18+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -115,16 +115,16 @@ msgstr ""
#: tests/end2end/test_editing_user.py:45 xl_auth/templates/permissions/home.html:30
#: xl_auth/templates/permissions/home.html:31 xl_auth/templates/permissions/home.html:32
#: xl_auth/templates/users/home.html:33 xl_auth/templates/users/home.html:76
#: xl_auth/templates/users/profile.html:55 xl_auth/templates/users/profile.html:58
#: xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:58 xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:65
msgid "Yes"
msgstr ""

#: tests/end2end/test_editing_user.py:45 xl_auth/templates/permissions/home.html:30
#: xl_auth/templates/permissions/home.html:31 xl_auth/templates/permissions/home.html:32
#: xl_auth/templates/users/home.html:33 xl_auth/templates/users/home.html:76
#: xl_auth/templates/users/profile.html:55 xl_auth/templates/users/profile.html:58
#: xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:58 xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:65
msgid "No"
msgstr ""

Expand Down Expand Up @@ -295,17 +295,17 @@ msgid "Collection"
msgstr ""

#: xl_auth/permission/forms.py:22 xl_auth/templates/permissions/home.html:18
#: xl_auth/templates/users/profile.html:44
#: xl_auth/templates/users/profile.html:45
msgid "Registrant"
msgstr ""

#: xl_auth/permission/forms.py:23 xl_auth/templates/permissions/home.html:19
#: xl_auth/templates/users/profile.html:45
#: xl_auth/templates/users/profile.html:46
msgid "Cataloger"
msgstr ""

#: xl_auth/permission/forms.py:24 xl_auth/templates/permissions/home.html:20
#: xl_auth/templates/users/profile.html:46
#: xl_auth/templates/users/profile.html:48
msgid "Cataloguing Administrator"
msgstr ""

Expand Down Expand Up @@ -534,7 +534,7 @@ msgstr ""

#: xl_auth/templates/users/profile.html:35
msgid ""
"Note: <em>Cataloguing Admin</em> is a new privilege that, in the tear future, will allow you to "
"Note: <em>Cataloguing Admin</em> is a new privilege that, in the near future, will allow you to "
"create new user accounts and grant registrant/cataloger privileges to others. "
msgstr ""

Expand Down
102 changes: 98 additions & 4 deletions xl_auth/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ def urls(url, order):


@click.command()
@click.option('-v', '--verbose', default=False, is_flag=True, help='Increase verbosity')
@click.option('--admin-email', required=True, default=None, help='Email for admin')
@click.option('-v', '--verbose', default=False, is_flag=True, help='Increase verbosity.')
@click.option('--wipe-permissions', default=False, is_flag=True, help='Wipe outdated permissions')
@with_appcontext
def import_data(admin_email, verbose):
def import_data(verbose, admin_email, wipe_permissions):
"""Read data from Voyager dump and BibDB API to create DB entities.
Creates:
Expand Down Expand Up @@ -258,7 +259,7 @@ def _get_collection_details_from_bibdb(code):

def _get_voyager_data():
raw_voyager_sigels_and_locations = requests.get(
'https://github.com/libris/xl_auth/files/1406251/171023_KB--sigel_locations.txt'
'https://github.com/libris/xl_auth/files/1414385/171025_KB--sigel_locations.txt'
).content.decode('latin-1').splitlines()
voyager_sigels_and_collections = dict()
voyager_main_sigels, voyager_location_sigels = set(), set()
Expand Down Expand Up @@ -388,6 +389,32 @@ def _generate_xl_auth_cataloging_admins_and_collections(bibdb_cataloging_admin_t
'cataloging_admins': xl_auth_cataloging_admins
}

def _get_manually_added_permissions():
emails_and_collection_codes = requests.get(
'https://docs.google.com/spreadsheets/d/e/2PACX-1vT2TjS_L9_J5LJztfKWo0UxQD-RCZo3bheFIH'
'Ouz2Gu-aGcd7IrlDzHDmQ2yL726z0BnSc47vasL0l3/pub?gid=0&single=true&output=tsv'
).content.decode('utf-8').splitlines()

manual_additions = []
for add_row in emails_and_collection_codes[1:]:
add_email, add_code, _ = add_row.split('\t')
manual_additions.append((add_email.strip(), add_code.strip()))

return manual_additions

def _get_manually_deleted_permissions():
emails_and_collection_codes = requests.get(
'https://docs.google.com/spreadsheets/d/e/2PACX-1vT2TjS_L9_J5LJztfKWo0UxQD-RCZo3bheFIH'
'Ouz2Gu-aGcd7IrlDzHDmQ2yL726z0BnSc47vasL0l3/pub?gid=518641812&single=true&output=tsv'
).content.decode('utf-8').splitlines()

manual_deletions = []
for del_row in emails_and_collection_codes[1:]:
del_email, del_code, _ = del_row.split('\t')
manual_deletions.append((del_email.strip(), del_code.strip()))

return manual_deletions

# Get admin user
admin = User.query.filter_by(email=admin_email).first()

Expand Down Expand Up @@ -445,6 +472,9 @@ def _generate_xl_auth_cataloging_admins_and_collections(bibdb_cataloging_admin_t
user = User.create(email=email, full_name=full_name, active=False)
user.save()

old_permissions = Permission.query.all()
current_permissions, new_permissions, removed_permissions = [], [], []

# Store permissions.
for email, collections in xl_auth['cataloging_admins'].items():
user = User.query.filter_by(email=email).first()
Expand All @@ -458,7 +488,71 @@ def _generate_xl_auth_cataloging_admins_and_collections(bibdb_cataloging_admin_t
continue
permission = Permission.query.filter_by(user_id=user.id,
collection_id=collection.id).first()
if not permission:
if permission:
current_permissions.append(permission)
else:
permission = Permission.create(user=user, collection=collection, registrant=True,
cataloger=True, cataloging_admin=True)
permission.save()
new_permissions.append(permission)

# Apply manual additions.
for email, code in _get_manually_added_permissions():
user = User.query.filter(User.email.ilike(email)).first()
if not user:
print('Cannot add permission manually; user %r does not exist' % email)
continue

collection = Collection.query.filter_by(code=code).first()
if not collection:
print('Cannot add permission manually, collection %r does not exist' % code)
continue

permission = Permission.query.filter_by(user_id=user.id,
collection_id=collection.id).first()
if permission:
current_permissions.append(permission)
if verbose:
print('Manual permission for %r on %r already exists.' % (email, code))
else:
permission = Permission.create(user=user, collection=collection, registrant=True,
cataloger=True, cataloging_admin=True)
permission.save()
new_permissions.append(permission)
if verbose:
print('Manually added permissions for %r on %r.' % (email, code))

# Apply manual deletions.
for email, code in _get_manually_deleted_permissions():
user = User.query.filter(User.email.ilike(email)).first()
if not user:
print('Cannot delete permission manually; user %r does not exist' % email)
continue

collection = Collection.query.filter_by(code=code).first()
if not collection:
print('Cannot delete permission manually, collection %r does not exist' % code)
continue

permission = Permission.query.filter_by(user_id=user.id,
collection_id=collection.id).first()
if permission:
permission.delete()
removed_permissions.append(permission)
if verbose:
print('Manually deleted permissions for %r on %r.' % (email, code))
else:
current_permissions.append(permission)
if verbose:
print('Cannot manually deleted permissions for %r on %r; does not exist.'
% (email, code))

# Optionally wipe stray permissions.
for permission in old_permissions:
if permission in current_permissions and permission not in removed_permissions:
continue
else:
print('Permission for %r on %r not found during import (deleting=%s).'
% (permission.user.email, permission.collection.code, wipe_permissions))
if wipe_permissions:
permission.delete()
20 changes: 12 additions & 8 deletions xl_auth/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ <h3>{{ _('Permissions (Active Collections Only)') }}</h3>
<tr>
<th>{{ _('Code') }}</th>
<th>{{ _('Friendly Name') }}</th>
<th>{{ _('Registrant') }}</th>
<th>{{ _('Cataloger') }}</th>
{% if user.is_admin %}
<th>{{ _('Registrant') }}</th>
<th>{{ _('Cataloger') }}</th>
{% endif %}
<th>{{ _('Cataloguing Administrator') }}</th>
</tr>
</thead>
Expand All @@ -51,12 +53,14 @@ <h3>{{ _('Permissions (Active Collections Only)') }}</h3>
<tr>
<td>{{ permission.collection.code }}</td>
<td>{{ permission.collection.friendly_name }}</td>
<td class="{{ "bool-value-{}".format(permission.registrant).lower() }}">
{{ _('Yes') if permission.registrant else _('No') }}
</td>
<td class="{{ "bool-value-{}".format(permission.cataloger).lower() }}">
{{ _('Yes') if permission.cataloger else _('No') }}
</td>
{% if user.is_admin %}
<td class="{{ "bool-value-{}".format(permission.registrant).lower() }}">
{{ _('Yes') if permission.registrant else _('No') }}
</td>
<td class="{{ "bool-value-{}".format(permission.cataloger).lower() }}">
{{ _('Yes') if permission.cataloger else _('No') }}
</td>
{% endif %}
<td class="{{ "bool-value-{}".format(permission.cataloging_admin).lower() }}">
{{ _('Yes') if permission.cataloging_admin else _('No') }}
</td>
Expand Down
20 changes: 10 additions & 10 deletions xl_auth/translations/sv/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.2.1\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2017-10-24 08:23+0200\n"
"POT-Creation-Date: 2017-10-25 13:18+0200\n"
"PO-Revision-Date: 2017-09-19 12:23+0200\n"
"Last-Translator: Mats Blomdahl <[email protected]>\n"
"Language: sv\n"
Expand Down Expand Up @@ -57,7 +57,7 @@ msgstr "Kategori saknas"
#: xl_auth/collection/forms.py:17 xl_auth/templates/collections/home.html:21
#: xl_auth/templates/collections/home.html:65 xl_auth/templates/users/profile.html:42
msgid "Code"
msgstr "Kod"
msgstr "Sigel"

#: tests/end2end/test_editing_collection.py:80 tests/forms/test_collection.py:77
#: xl_auth/collection/forms.py:63
Expand Down Expand Up @@ -116,16 +116,16 @@ msgstr "Användare"
#: tests/end2end/test_editing_user.py:45 xl_auth/templates/permissions/home.html:30
#: xl_auth/templates/permissions/home.html:31 xl_auth/templates/permissions/home.html:32
#: xl_auth/templates/users/home.html:33 xl_auth/templates/users/home.html:76
#: xl_auth/templates/users/profile.html:55 xl_auth/templates/users/profile.html:58
#: xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:58 xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:65
msgid "Yes"
msgstr "Ja"

#: tests/end2end/test_editing_user.py:45 xl_auth/templates/permissions/home.html:30
#: xl_auth/templates/permissions/home.html:31 xl_auth/templates/permissions/home.html:32
#: xl_auth/templates/users/home.html:33 xl_auth/templates/users/home.html:76
#: xl_auth/templates/users/profile.html:55 xl_auth/templates/users/profile.html:58
#: xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:58 xl_auth/templates/users/profile.html:61
#: xl_auth/templates/users/profile.html:65
msgid "No"
msgstr "Nej"

Expand Down Expand Up @@ -296,17 +296,17 @@ msgid "Collection"
msgstr "Samling"

#: xl_auth/permission/forms.py:22 xl_auth/templates/permissions/home.html:18
#: xl_auth/templates/users/profile.html:44
#: xl_auth/templates/users/profile.html:45
msgid "Registrant"
msgstr "Beståndsregistrerare"

#: xl_auth/permission/forms.py:23 xl_auth/templates/permissions/home.html:19
#: xl_auth/templates/users/profile.html:45
#: xl_auth/templates/users/profile.html:46
msgid "Cataloger"
msgstr "Katalogisatör"

#: xl_auth/permission/forms.py:24 xl_auth/templates/permissions/home.html:20
#: xl_auth/templates/users/profile.html:46
#: xl_auth/templates/users/profile.html:48
msgid "Cataloguing Administrator"
msgstr "Katalogiseringsadmin"

Expand Down Expand Up @@ -538,7 +538,7 @@ msgstr ""

#: xl_auth/templates/users/profile.html:34
msgid "Permissions (Active Collections Only)"
msgstr "Behörigheter på aktiva samlingar/sigler"
msgstr "Behörigheter på aktiva sigel"

#: xl_auth/templates/users/profile.html:35
msgid ""
Expand Down

0 comments on commit 86b824f

Please sign in to comment.