-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
global: admin views for invenio-oauth
Signed-off-by: Bruno Cuc <bruno.cuc@cern.ch>
- Loading branch information
Bruno Cuc
committed
Jan 15, 2016
1 parent
de1682a
commit 82b09a7
Showing
13 changed files
with
227 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016 CERN. | ||
# | ||
# Invenio 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 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc., | ||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
"""Views for OAuth.""" | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
from flask.ext.admin.contrib.sqla import ModelView | ||
from flask_babelex import gettext as _ | ||
from wtforms.fields import TextAreaField | ||
|
||
from .models import RemoteAccount, RemoteToken, UserIdentity | ||
|
||
|
||
class RemoteAccountView(ModelView): | ||
"""Flask-Admin view to manage remote accounts from invenio-oauthclient.""" | ||
|
||
can_view_details = True | ||
|
||
column_list = ( | ||
'id', | ||
'user_id', | ||
'client_id', | ||
'extra_data', | ||
'tokens', | ||
) | ||
|
||
remote_account_columns = ( | ||
'id', | ||
'user_id', | ||
'client_id', | ||
'extra_data', | ||
) | ||
|
||
column_searchable_list = column_sortable_list = remote_account_columns | ||
|
||
column_filters = ('id', 'user_id', 'client_id',) | ||
|
||
column_default_sort = ('id', True) | ||
|
||
column_display_all_relations = True | ||
inline_models = (RemoteToken,) | ||
|
||
column_labels = { | ||
'id': _('ID'), | ||
'user_id': _('User ID'), | ||
'client_id': _('Client ID'), | ||
} | ||
|
||
|
||
class RemoteTokenView(ModelView): | ||
"""Flask-Admin view to manage remote tokens from invenio-oauthclient.""" | ||
|
||
can_view_details = True | ||
|
||
column_list = ( | ||
'id_remote_account', | ||
'token_type', | ||
'access_token', | ||
) | ||
|
||
column_searchable_list = \ | ||
column_sortable_list = \ | ||
column_list | ||
|
||
column_filters = ( | ||
'id_remote_account', | ||
'token_type', | ||
'secret', | ||
) | ||
|
||
form_columns = ( | ||
'remote_account', | ||
'token_type', | ||
'access_token', | ||
'secret', | ||
) | ||
|
||
column_labels = { | ||
'id_remote_account': _('ID Remote Account'), | ||
} | ||
|
||
form_overrides = { | ||
'access_token': TextAreaField | ||
} | ||
|
||
|
||
remote_account_adminview = { | ||
'model': RemoteAccount, | ||
'modelview': RemoteAccountView, | ||
'category': _('User Management') | ||
} | ||
|
||
remote_token_adminview = { | ||
'model': RemoteToken, | ||
'modelview': RemoteTokenView, | ||
'category': _('User Management') | ||
} | ||
|
||
__all__ = ('remote_account_adminview', 'remote_token_adminview') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016 CERN. | ||
# | ||
# Invenio 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 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc., | ||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
|
||
"""Views for OAuth.""" | ||
from flask import Flask, url_for | ||
from flask.ext.admin import Admin | ||
from invenio_admin import InvenioAdmin | ||
from invenio_db import db | ||
from werkzeug.local import LocalProxy | ||
|
||
from invenio_oauthclient import InvenioOAuthClient | ||
from invenio_oauthclient.admin import RemoteAccountView, RemoteTokenView, \ | ||
remote_account_adminview, remote_token_adminview | ||
|
||
|
||
def test_admin(app): | ||
"""Test flask-admin interace.""" | ||
InvenioOAuthClient(app) | ||
|
||
assert isinstance(remote_account_adminview, dict) | ||
assert isinstance(remote_token_adminview, dict) | ||
|
||
assert 'model' in remote_account_adminview | ||
assert 'modelview' in remote_account_adminview | ||
assert 'model' in remote_token_adminview | ||
assert 'modelview' in remote_token_adminview | ||
|
||
admin = Admin(app, name="Test") | ||
|
||
user_model = remote_account_adminview.pop('model') | ||
user_view = remote_account_adminview.pop('modelview') | ||
admin.add_view(user_view(user_model, db.session, | ||
**remote_account_adminview)) | ||
|
||
with app.app_context(): | ||
# create user and save url for testing | ||
request_url = url_for("remoteaccount.index_view") | ||
|
||
with app.app_context(): | ||
with app.test_client() as client: | ||
res = client.get( | ||
request_url, | ||
follow_redirects=True | ||
) | ||
assert res.status_code == 200 | ||
# import ipdb; ipdb.set_trace() | ||
assert 'Extra Data' in str(res.get_data()) | ||
assert 'Tokens' in str(res.get_data()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters