Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
global: admin interface improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Lars Holm Nielsen <[email protected]>
  • Loading branch information
lnielsen committed Aug 31, 2015
1 parent 65f37e5 commit ead61c8
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 9 deletions.
33 changes: 30 additions & 3 deletions invenio/modules/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,38 @@ class AccMixin(object):
acc_delete_action = 'cfgwebaccess'


class UserEXTInlineModelForm(InlineFormAdmin):
class UserEXTAdmin(ModelView, AccMixin):

"""Inline admin for UserEXT."""
form_columns = ('method', 'id')

_can_create = False
_can_edit = False
_can_delete = True
can_view_details = True

column_list = (
'method', 'id', 'user'
)

column_details_list = ('method', 'id', 'user')

column_searchable_list = (
'method', 'id', 'user.nickname', 'user.email',
)

column_filters = (
'method', 'user.nickname', 'user.email',
)

form_columns = ('method', 'id', )


class UserAdmin(ModelView, AccMixin):

"""Flask-Admin view to manage users."""

can_view_details = True

column_list = (
'id', 'nickname', 'email', 'family_name', 'given_names',
'note', 'last_login', 'password_scheme',
Expand All @@ -79,7 +101,9 @@ class UserAdmin(ModelView, AccMixin):
'last_login': DateTimeField
}

inline_models = [UserEXTInlineModelForm(UserEXT)]
column_details_list = column_list

details_template = 'accounts/admin/details.html'

@action('inactivate', 'Inactivate',
'Are you sure you want to inactivate selected users?')
Expand Down Expand Up @@ -147,3 +171,6 @@ def register_admin(app, admin):
admin.add_view(
UserAdmin(User, db.session, name="Users", category=category)
)
admin.add_view(
UserEXTAdmin(UserEXT, db.session, name="Identities", category=category)
)
15 changes: 15 additions & 0 deletions invenio/modules/accounts/templates/accounts/admin/details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'admin/model/details.html' %}
{% import 'admin/lib.html' as lib with context %}

{% block navlinks %}
{{super()}}
{%- set user_id = get_value(model, 'id') %}
{%- set user_email = get_value(model, 'email') %}
<ul class="nav nav-pills nav-justified">
<li><a href="{{url_for('userext.index_view', flt3_16=user_email )}}">View identities</a></li>
<li><a href="{{url_for('search.search', p='8560_w:%s' % user_id)}}">View records</a></li>
<li><a href="{{url_for('bibworkflowobject.index_view', flt3_2=user_email)}}">View deposits</a></li>
<li><a href="{{url_for('resourceusage.index_view', flt0_2='User', flt3_9=user_id)}}">View metrics</a></li>
<li><a href="{{url_for('Communities.index_view', flt2_9=user_email)}}">View communities</a></li>
</ul>
{% endblock %}
10 changes: 5 additions & 5 deletions invenio/modules/communities/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class CommunitiesAdmin(ModelView):

"""Administrative view for communities."""

#acc_edit_action = 'cfgmymodel'

_can_create = True
_can_edit = True
_can_delete = True

column_list = ('id', 'title', 'description', 'page', 'last_modified',
'ranking', 'fixed_points')
column_list = (
'id', 'title', 'owner', 'last_modified', 'last_record_accepted',
'ranking', 'fixed_points',
)
column_searchable_list = ('title',)

page_size = 100
column_filters = ('owner.nickname', 'owner.email', 'last_modified')

def __init__(self, model, session, **kwargs):
"""Initialize administrative view for communities."""
Expand Down
129 changes: 129 additions & 0 deletions invenio/modules/deposit/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015 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.

"""Flask-Admin page to configure users and accounts."""

from __future__ import absolute_import
from markupsafe import Markup

from flask import flash, render_template
from flask_admin.actions import action
from flask_admin.form.fields import DateTimeField
from flask_admin.model.form import InlineFormAdmin

from invenio.ext.admin.views import ModelView
from invenio.ext.sqlalchemy import db

from invenio.ext.login import login_user, logout_user

from invenio.modules.workflows.models import BibWorkflowObject, Workflow, ObjectVersion
from invenio.modules.workflows.engine import WorkflowStatus


from .models import Deposition

class AccMixin(object):

"""Configure access rights."""

_can_create = False
_can_edit = False
_can_delete = False

acc_view_action = 'cfgwebaccess'
acc_edit_action = 'cfgwebaccess'
acc_delete_action = 'cfgwebaccess'


def name_from_workflowstatus(s):
if s == WorkflowStatus.NEW:
return "NEW"
elif s == WorkflowStatus.RUNNING:
return "RUNNING"
elif s == WorkflowStatus.HALTED:
return "HALTED"
elif s == WorkflowStatus.ERROR:
return "ERROR"
elif s == WorkflowStatus.COMPLETED:
return "COMPLETED"


def format_deposition(v, c, m, n):
"""Format data for a deposition."""
return Markup(render_template(
"deposit/admin/deposition_data.html", obj=Deposition(m)))


class DepositAdmin(ModelView, AccMixin):

"""Flask-Admin view to manage users."""

can_view_details = True

column_list = (
'id', 'user', 'id_workflow', 'version', 'workflow.status', 'created',
'modified',
)

column_details_list = (
'id',
'user',
'version',
'workflow.status',
'created',
'modified',
'_data',
'child_logs',
)

column_names = {
'_data': 'Data',
}

column_filters = (
'user.email',
'user.nickname',
'created',
'modified',
)

column_formatters = {
'version': lambda v, c, m, n: ObjectVersion.name_from_version(
getattr(m, n)),
'workflow.status': lambda v, c, m, n: name_from_workflowstatus(
m.workflow.status),
'_data': format_deposition
}

def get_query(self):
params = [
Workflow.module_name == 'webdeposit',
BibWorkflowObject.id_user != 0
]

return BibWorkflowObject.query.join("workflow").options(
db.contains_eager('workflow')).filter(*params)


def register_admin(app, admin):
"""Call on app initialization to register administration interface."""
category = "Deposits"
admin.add_view(DepositAdmin(
BibWorkflowObject, db.session, name="Deposits", category=category
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<p>
<strong>{{obj.title}}</strong>
{% if obj.get_latest_sip() %}
{% set sip = obj.get_latest_sip() %}
<a href="{{ url_for('record.metadata', recid=sip.metadata['recid'])}}">View record</a>{% endif %}
</p>
<p>
<strong>Draft:</strong><br/>
{% for v in obj.drafts.values() %}
<pre>{{v.values}}</pre>
{% endfor %}
</p>
<p>
<strong>Submission Information Packages:</strong><br/>
{% for s in obj.sips %}

<i>{{s.uuid}} ({{s.timestamp}}):</i><br>
<small class="text-muted">Agents: {% for a in s.agents %}{{a.user_id}} &lt;{{a.email_address}}&gt; ({{a.ip_address}}),{% endfor%}</small>
<pre>{% for k in s.metadata.keys()|sort if not k.startswith('_') %}{{k}}: {{s.metadata[k]}}
{% endfor %}
</pre>
<pre>{{s.package}}</pre>

{% endfor %}
</p>
<p>
<strong>Files:</strong><br/>
{% for f in obj.files %}
{{f.name}} ({{f.size|filesizeformat}}) <small class="text-muted">Checksum: {{f.checksum}}, Path: {{f.path}}</small><br/>
{% endfor %}

<p>
8 changes: 7 additions & 1 deletion invenio/modules/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from invenio.ext.logging import deprecated
from invenio.ext.sqlalchemy import db
from invenio.ext.sqlalchemy.utils import session_manager
from invenio.modules.accounts.models import User

from six import callable, iteritems
from six.moves import cPickle
Expand Down Expand Up @@ -327,7 +328,8 @@ class BibWorkflowObject(db.Model):
data_type = db.Column(db.String(150), default="",
nullable=True)
uri = db.Column(db.String(500), default="")
id_user = db.Column(db.Integer, default=0, nullable=False)
id_user = db.Column(
db.Integer, db.ForeignKey(User.id), default=0, nullable=False)

child_logs = db.relationship("BibWorkflowObjectLog",
backref='bibworkflowobject',
Expand All @@ -337,6 +339,10 @@ class BibWorkflowObject(db.Model):
Workflow, foreign_keys=[id_workflow], remote_side=Workflow.uuid,
)

user = db.relationship(
User, foreign_keys=[id_user], remote_side=User.id,
)

_log = None

@property
Expand Down

0 comments on commit ead61c8

Please sign in to comment.