Verified Commit e58ff10c authored by Huste, Tobias (FWCC) - 111645's avatar Huste, Tobias (FWCC) - 111645
Browse files

admin: add admin interface for background upload

- remote server can be added and created
- ssh keys can be viewed
parent f7e10807
Pipeline #2838 passed with stage
in 48 minutes and 37 seconds
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2018 HZDR
#
# This file is part of Rodare.
#
# Rodare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rodare 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rodare. If not, see <http://www.gnu.org/licenses/>.
"""Administration interface for invenio-uploadbyurl."""
from flask_admin.contrib.sqla import ModelView
from flask_babelex import gettext as _
from invenio_accounts.models import User
from .models import RemoteServer, SSHKey
class RemoteServerAdmin(ModelView):
"""Remote Server admin view."""
can_create = True
can_edit = True
can_delete = True
can_view_details = True
column_list = ('name', 'server_address', 'port', 'description')
column_details_list = ('name', 'server_address', 'port', 'description')
class SSHKeyAdmin(ModelView):
"""SSH Key admin view."""
can_create = False
can_edit = False
can_delete = False
can_view_details = True
column_list = ('username', 'keytype', 'user', 'remote_server',
'valid_until')
column_details_list = ('username', 'keytype', 'user', 'remote_server',
'valid_until')
column_searchable_list = ('username', User.email, )
page_size = 25
remoteserver_adminview = dict(
modelview=RemoteServerAdmin,
model=RemoteServer,
category=_('Background upload')
)
sshkey_adminview = dict(
modelview=SSHKeyAdmin,
model=SSHKey,
category=_('Background upload')
)
......@@ -31,7 +31,6 @@ tests_require = [
'check-manifest>=0.25',
'coverage>=4.0',
'invenio-access>=1.0.0a12',
'invenio-accounts>=1.0.0b10',
'invenio-celery>=1.0.0b2',
'invenio-i18n>=1.0.0b4',
'invenio-theme>=1.0.0b4',
......@@ -77,6 +76,7 @@ install_requires = [
'celery>=4.0.2',
'humanize>=0.5.1',
'invenio-accounts>=1.0.0b12',
'invenio-admin>=1.0.0b3',
'invenio-assets>=1.0.0b6',
'invenio-files-rest>=1.0.0a19',
'invenio-records-files>=1.0.0a9',
......@@ -113,6 +113,12 @@ setup(
include_package_data=True,
platforms='any',
entry_points={
'invenio_admin.views': [
'remoteserver_adminview = '
'invenio_uploadbyurl.admin:remoteserver_adminview',
'sshkey_adminview = '
'invenio_uploadbyurl.admin:sshkey_adminview',
],
'invenio_base.apps': [
'invenio_uploadbyurl = invenio_uploadbyurl:InvenioUploadByURL',
],
......
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2018 HZDR
#
# This file is part of Rodare.
#
# Rodare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rodare 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rodare. If not, see <http://www.gnu.org/licenses/>.
"""Test uploadbyurl admin views."""
from flask import url_for
from flask_admin import Admin
from invenio_db import db
from invenio_uploadbyurl.admin import remoteserver_adminview, sshkey_adminview
def test_admin(app, remote):
"""Test uploadbyurl admin interface."""
assert isinstance(remoteserver_adminview, dict)
assert isinstance(sshkey_adminview, dict)
assert 'model' in remoteserver_adminview
assert 'modelview' in remoteserver_adminview
assert 'model' in sshkey_adminview
assert 'modelview' in sshkey_adminview
admin = Admin(app, name="Test")
remoteserver_model = remoteserver_adminview.pop('model')
remoteserver_view = remoteserver_adminview.pop('modelview')
admin.add_view(remoteserver_view(
remoteserver_model, db.session,
**remoteserver_adminview
))
sshkey_model = sshkey_adminview.pop('model')
sshkey_view = sshkey_adminview.pop('modelview')
admin.add_view(sshkey_view(
sshkey_model, db.session,
**sshkey_adminview
))
with app.app_context():
rs_index_view_url = url_for('remoteserver.index_view')
rs_delete_view_url = url_for('remoteserver.delete_view')
key_index_view_url = url_for('sshkey.index_view')
with app.test_client() as client:
resp = client.get(
rs_index_view_url,
follow_redirects=True,
)
assert resp.status_code == 200
assert 'foo' in str(resp.get_data())
assert 'Server Address' in str(resp.get_data())
resp = client.get(
key_index_view_url,
follow_redirects=True,
)
assert resp.status_code == 200
assert 'foo' in str(resp.get_data())
assert 'Keytype' in str(resp.get_data())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment