mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
Implement /admin using flask-admin. Overall cleanup
This commit is contained in:
parent
c405061574
commit
d4cd313940
@ -3,6 +3,7 @@ from config import Config
|
|||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask.logging import default_handler
|
from flask.logging import default_handler
|
||||||
|
from flask_admin import Admin
|
||||||
from flask_apscheduler import APScheduler
|
from flask_apscheduler import APScheduler
|
||||||
from flask_assets import Environment
|
from flask_assets import Environment
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
@ -15,10 +16,12 @@ from flask_sqlalchemy import SQLAlchemy
|
|||||||
from flask_hashids import Hashids
|
from flask_hashids import Hashids
|
||||||
from logging import Formatter, StreamHandler
|
from logging import Formatter, StreamHandler
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
from .extensions.nopaque_flask_admin_views import AdminIndexView, ModelView
|
||||||
|
|
||||||
|
|
||||||
docker_client = DockerClient.from_env()
|
docker_client = DockerClient.from_env()
|
||||||
|
|
||||||
|
admin = Admin()
|
||||||
apifairy = APIFairy()
|
apifairy = APIFairy()
|
||||||
assets = Environment()
|
assets = Environment()
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
@ -74,6 +77,7 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
|
|
||||||
from .models import AnonymousUser, User
|
from .models import AnonymousUser, User
|
||||||
|
|
||||||
|
admin.init_app(app, index_view=AdminIndexView())
|
||||||
apifairy.init_app(app)
|
apifairy.init_app(app)
|
||||||
assets.init_app(app)
|
assets.init_app(app)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
@ -92,9 +96,6 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
# endregion Extensions
|
# endregion Extensions
|
||||||
|
|
||||||
# region Blueprints
|
# region Blueprints
|
||||||
from .blueprints.admin import bp as admin_blueprint
|
|
||||||
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
|
||||||
|
|
||||||
from .blueprints.api import bp as api_blueprint
|
from .blueprints.api import bp as api_blueprint
|
||||||
app.register_blueprint(api_blueprint, url_prefix='/api')
|
app.register_blueprint(api_blueprint, url_prefix='/api')
|
||||||
|
|
||||||
@ -127,6 +128,10 @@ def create_app(config: Config = Config) -> Flask:
|
|||||||
|
|
||||||
from .blueprints.workshops import bp as workshops_blueprint
|
from .blueprints.workshops import bp as workshops_blueprint
|
||||||
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
||||||
|
|
||||||
|
from .models import _models
|
||||||
|
for model in _models:
|
||||||
|
admin.add_view(ModelView(model, db.session, category='Database'))
|
||||||
# endregion Blueprints
|
# endregion Blueprints
|
||||||
|
|
||||||
# region SocketIO Namespaces
|
# region SocketIO Namespaces
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
from flask import Blueprint
|
|
||||||
from flask_login import login_required
|
|
||||||
from app.decorators import admin_required
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('admin', __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
|
||||||
@login_required
|
|
||||||
@admin_required
|
|
||||||
def before_request():
|
|
||||||
'''
|
|
||||||
Ensures that the routes in this package can be visited only by users with
|
|
||||||
administrator privileges (login_required and admin_required).
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
from . import json_routes, routes
|
|
@ -1,16 +0,0 @@
|
|||||||
from flask_wtf import FlaskForm
|
|
||||||
from wtforms import SelectField, SubmitField
|
|
||||||
from app.models import Role
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateUserForm(FlaskForm):
|
|
||||||
role = SelectField('Role')
|
|
||||||
submit = SubmitField()
|
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
|
||||||
if 'data' not in kwargs:
|
|
||||||
kwargs['data'] = {'role': user.role.hashid}
|
|
||||||
if 'prefix' not in kwargs:
|
|
||||||
kwargs['prefix'] = 'update-user-form'
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.role.choices = [(x.hashid, x.name) for x in Role.query.all()]
|
|
@ -1,23 +0,0 @@
|
|||||||
from flask import abort, request
|
|
||||||
from app.decorators import content_negotiation
|
|
||||||
from app import db
|
|
||||||
from app.models import User
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/confirmed', methods=['PUT'])
|
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
|
||||||
def update_user_role(user_id):
|
|
||||||
confirmed = request.json
|
|
||||||
if not isinstance(confirmed, bool):
|
|
||||||
abort(400)
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
user.confirmed = confirmed
|
|
||||||
db.session.commit()
|
|
||||||
response_data = {
|
|
||||||
'message': (
|
|
||||||
f'User "{user.username}" is now '
|
|
||||||
f'{"confirmed" if confirmed else "unconfirmed"}'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
@ -1,136 +0,0 @@
|
|||||||
from flask import abort, flash, redirect, render_template, url_for
|
|
||||||
from app import db, hashids
|
|
||||||
from app.models import Avatar, Corpus, Role, User
|
|
||||||
from app.blueprints.users.settings.forms import (
|
|
||||||
UpdateAvatarForm,
|
|
||||||
UpdatePasswordForm,
|
|
||||||
UpdateNotificationsForm,
|
|
||||||
UpdateAccountInformationForm,
|
|
||||||
UpdateProfileInformationForm
|
|
||||||
)
|
|
||||||
from . import bp
|
|
||||||
from .forms import UpdateUserForm
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
|
||||||
def admin():
|
|
||||||
return render_template(
|
|
||||||
'admin/admin.html.j2',
|
|
||||||
title='Administration'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/corpora')
|
|
||||||
def corpora():
|
|
||||||
corpora = Corpus.query.all()
|
|
||||||
return render_template(
|
|
||||||
'admin/corpora.html.j2',
|
|
||||||
title='Corpora',
|
|
||||||
corpora=corpora
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users')
|
|
||||||
def users():
|
|
||||||
users = User.query.all()
|
|
||||||
return render_template(
|
|
||||||
'admin/users.html.j2',
|
|
||||||
title='Users',
|
|
||||||
users=users
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>')
|
|
||||||
def user(user_id):
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
corpora = Corpus.query.filter(Corpus.user == user).all()
|
|
||||||
return render_template(
|
|
||||||
'admin/user.html.j2',
|
|
||||||
title=user.username,
|
|
||||||
user=user,
|
|
||||||
corpora=corpora
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/settings', methods=['GET', 'POST'])
|
|
||||||
def user_settings(user_id):
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
update_account_information_form = UpdateAccountInformationForm(user)
|
|
||||||
update_profile_information_form = UpdateProfileInformationForm(user)
|
|
||||||
update_avatar_form = UpdateAvatarForm()
|
|
||||||
update_password_form = UpdatePasswordForm(user)
|
|
||||||
update_notifications_form = UpdateNotificationsForm(user)
|
|
||||||
update_user_form = UpdateUserForm(user)
|
|
||||||
|
|
||||||
# region handle update profile information form
|
|
||||||
if update_profile_information_form.submit.data and update_profile_information_form.validate():
|
|
||||||
user.about_me = update_profile_information_form.about_me.data
|
|
||||||
user.location = update_profile_information_form.location.data
|
|
||||||
user.organization = update_profile_information_form.organization.data
|
|
||||||
user.website = update_profile_information_form.website.data
|
|
||||||
user.full_name = update_profile_information_form.full_name.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update profile information form
|
|
||||||
|
|
||||||
# region handle update avatar form
|
|
||||||
if update_avatar_form.submit.data and update_avatar_form.validate():
|
|
||||||
try:
|
|
||||||
Avatar.create(
|
|
||||||
update_avatar_form.avatar.data,
|
|
||||||
user=user
|
|
||||||
)
|
|
||||||
except (AttributeError, OSError):
|
|
||||||
abort(500)
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update avatar form
|
|
||||||
|
|
||||||
# region handle update account information form
|
|
||||||
if update_account_information_form.submit.data and update_account_information_form.validate():
|
|
||||||
user.email = update_account_information_form.email.data
|
|
||||||
user.username = update_account_information_form.username.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Profile settings updated')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update account information form
|
|
||||||
|
|
||||||
# region handle update password form
|
|
||||||
if update_password_form.submit.data and update_password_form.validate():
|
|
||||||
user.password = update_password_form.new_password.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update password form
|
|
||||||
|
|
||||||
# region handle update notifications form
|
|
||||||
if update_notifications_form.submit.data and update_notifications_form.validate():
|
|
||||||
user.setting_job_status_mail_notification_level = \
|
|
||||||
update_notifications_form.job_status_mail_notification_level.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update notifications form
|
|
||||||
|
|
||||||
# region handle update user form
|
|
||||||
if update_user_form.submit.data and update_user_form.validate():
|
|
||||||
role_id = hashids.decode(update_user_form.role.data)
|
|
||||||
user.role = Role.query.get(role_id)
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update user form
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'admin/user_settings.html.j2',
|
|
||||||
title='Settings',
|
|
||||||
update_account_information_form=update_account_information_form,
|
|
||||||
update_avatar_form=update_avatar_form,
|
|
||||||
update_notifications_form=update_notifications_form,
|
|
||||||
update_password_form=update_password_form,
|
|
||||||
update_profile_information_form=update_profile_information_form,
|
|
||||||
update_user_form=update_user_form,
|
|
||||||
user=user
|
|
||||||
)
|
|
20
app/extensions/nopaque_flask_admin_views.py
Normal file
20
app/extensions/nopaque_flask_admin_views.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from flask import abort
|
||||||
|
from flask_admin import (
|
||||||
|
AdminIndexView as _AdminIndexView,
|
||||||
|
expose
|
||||||
|
)
|
||||||
|
from flask_admin.contrib.sqla import ModelView as _ModelView
|
||||||
|
from flask_login import current_user
|
||||||
|
|
||||||
|
|
||||||
|
class AdminIndexView(_AdminIndexView):
|
||||||
|
@expose('/')
|
||||||
|
def index(self):
|
||||||
|
if not current_user.is_administrator:
|
||||||
|
abort(403)
|
||||||
|
return super().index()
|
||||||
|
|
||||||
|
|
||||||
|
class ModelView(_ModelView):
|
||||||
|
def is_accessible(self):
|
||||||
|
return current_user.is_administrator
|
@ -1,2 +0,0 @@
|
|||||||
from .types import ContainerColumn
|
|
||||||
from .types import IntEnumColumn
|
|
@ -1,14 +1,45 @@
|
|||||||
from .anonymous_user import *
|
from .anonymous_user import AnonymousUser
|
||||||
from .avatar import *
|
from .avatar import Avatar
|
||||||
from .corpus_file import *
|
from .corpus_file import CorpusFile
|
||||||
from .corpus_follower_association import *
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
from .corpus_follower_role import *
|
from .corpus_follower_role import CorpusFollowerPermission, CorpusFollowerRole
|
||||||
from .corpus import *
|
from .corpus import CorpusStatus, Corpus
|
||||||
from .job_input import *
|
from .job_input import JobInput
|
||||||
from .job_result import *
|
from .job_result import JobResult
|
||||||
from .job import *
|
from .job import JobStatus, Job
|
||||||
from .role import *
|
from .role import Permission, Role
|
||||||
from .spacy_nlp_pipeline_model import *
|
from .spacy_nlp_pipeline_model import SpaCyNLPPipelineModel
|
||||||
from .tesseract_ocr_pipeline_model import *
|
from .tesseract_ocr_pipeline_model import TesseractOCRPipelineModel
|
||||||
from .token import *
|
from .token import Token
|
||||||
from .user import *
|
from .user import (
|
||||||
|
ProfilePrivacySettings,
|
||||||
|
UserSettingJobStatusMailNotificationLevel,
|
||||||
|
User
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_models = [
|
||||||
|
Avatar,
|
||||||
|
CorpusFile,
|
||||||
|
CorpusFollowerAssociation,
|
||||||
|
CorpusFollowerRole,
|
||||||
|
Corpus,
|
||||||
|
JobInput,
|
||||||
|
JobResult,
|
||||||
|
Job,
|
||||||
|
Role,
|
||||||
|
SpaCyNLPPipelineModel,
|
||||||
|
TesseractOCRPipelineModel,
|
||||||
|
Token,
|
||||||
|
User
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
_enums = [
|
||||||
|
CorpusFollowerPermission,
|
||||||
|
CorpusStatus,
|
||||||
|
JobStatus,
|
||||||
|
Permission,
|
||||||
|
ProfilePrivacySettings,
|
||||||
|
UserSettingJobStatusMailNotificationLevel
|
||||||
|
]
|
||||||
|
@ -8,7 +8,7 @@ import shutil
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from app import db
|
from app import db
|
||||||
from app.converters.vrt import normalize_vrt_file
|
from app.converters.vrt import normalize_vrt_file
|
||||||
from app.extensions.nopaque_sqlalchemy_extras import IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import IntEnumColumn
|
||||||
from .corpus_follower_association import CorpusFollowerAssociation
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from time import sleep
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.nopaque_sqlalchemy_extras import ContainerColumn, IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn, IntEnumColumn
|
||||||
|
|
||||||
|
|
||||||
class JobStatus(IntEnum):
|
class JobStatus(IntEnum):
|
||||||
|
@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.nopaque_sqlalchemy_extras import ContainerColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn
|
||||||
from .file_mixin import FileMixin
|
from .file_mixin import FileMixin
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.nopaque_sqlalchemy_extras import ContainerColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn
|
||||||
from .file_mixin import FileMixin
|
from .file_mixin import FileMixin
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import re
|
|||||||
import secrets
|
import secrets
|
||||||
import shutil
|
import shutil
|
||||||
from app import db, hashids
|
from app import db, hashids
|
||||||
from app.extensions.nopaque_sqlalchemy_extras import IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import IntEnumColumn
|
||||||
from .corpus import Corpus
|
from .corpus import Corpus
|
||||||
from .corpus_follower_association import CorpusFollowerAssociation
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
from .corpus_follower_role import CorpusFollowerRole
|
from .corpus_follower_role import CorpusFollowerRole
|
||||||
|
@ -68,8 +68,8 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_user.is_administrator %}
|
{% if current_user.is_administrator %}
|
||||||
<li {% if request.path == url_for('admin.admin') %}class="active"{% endif %}>
|
<li>
|
||||||
<a href="{{ url_for('admin.admin') }}">
|
<a href="{{ url_for('admin.index') }}">
|
||||||
<i class="material-icons left">admin_panel_settings</i>
|
<i class="material-icons left">admin_panel_settings</i>
|
||||||
Administration
|
Administration
|
||||||
</a>
|
</a>
|
||||||
|
@ -118,8 +118,8 @@
|
|||||||
|
|
||||||
{% if current_user.is_administrator %}
|
{% if current_user.is_administrator %}
|
||||||
{# Administration #}
|
{# Administration #}
|
||||||
<li {% if request.path == url_for('admin.admin') %}class="active"{% endif %}>
|
<li>
|
||||||
<a class="waves-effect" href="{{ url_for('admin.admin') }}"><i class="material-icons">admin_panel_settings</i>Administration</a>
|
<a class="waves-effect" href="{{ url_for('admin.index') }}"><i class="material-icons">admin_panel_settings</i>Administration</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
{% extends "base.html.j2" %}
|
|
||||||
|
|
||||||
{% block page_content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col s12">
|
|
||||||
<h1 id="title">{{ title }}</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12 l4">
|
|
||||||
<div class="card hoverable">
|
|
||||||
<a href="{{ url_for('.users') }}" style="position: absolute; width: 100%; height: 100%;"></a>
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title"><i class="material-icons left">group</i>Users</span>
|
|
||||||
<p>Edit the individual user accounts. You have the following options:</p>
|
|
||||||
<ul>
|
|
||||||
<li>- View, edit and delete user accounts</li>
|
|
||||||
<li>- View, edit and delete user corpora</li>
|
|
||||||
<li>- View, edit and delete user jobs</li>
|
|
||||||
<li>- View, edit and delete user added Tesseract models</li>
|
|
||||||
<li>- View, edit and delete user added SpaCy models</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12 l4">
|
|
||||||
<div class="card hoverable">
|
|
||||||
<a href="{{ url_for('.corpora') }}" style="position: absolute; width: 100%; height: 100%;"></a>
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title"><i class="nopaque-icons left">I</i>Corpora</span>
|
|
||||||
<p>Edit all Corpora. You have the following options:</p>
|
|
||||||
<ul>
|
|
||||||
<li>- View, edit and delete corpora</li>
|
|
||||||
<li>- View, edit and delete corpus jobs</li>
|
|
||||||
<li>- Edit corpus follower roles and the public status of the corpus</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock page_content %}
|
|
@ -1,29 +0,0 @@
|
|||||||
{% extends "base.html.j2" %}
|
|
||||||
|
|
||||||
{% block page_content %}
|
|
||||||
<div class="container">
|
|
||||||
<h1 id="title">{{ title }}</h1>
|
|
||||||
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="corpus-list no-autoinit" id="corpus-list"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock page_content %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
{{ super() }}
|
|
||||||
<script>
|
|
||||||
let corpusListElement = document.querySelector('#corpus-list');
|
|
||||||
let corpusList = new nopaque.resource_lists.CorpusList(corpusListElement);
|
|
||||||
corpusList.add(
|
|
||||||
[
|
|
||||||
{% for corpus in corpora %}
|
|
||||||
{{ corpus.to_json_serializeable(backrefs=True,relationships=True)|tojson }},
|
|
||||||
{% endfor %}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
{% endblock scripts %}
|
|
@ -1,104 +0,0 @@
|
|||||||
{% extends "base.html.j2" %}
|
|
||||||
{% import "wtf.html.j2" as wtf %}
|
|
||||||
|
|
||||||
{% block page_content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col s12">
|
|
||||||
<h1 id="title">{{ title }}</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12">
|
|
||||||
<form method="POST">
|
|
||||||
{{ edit_profile_settings_form.hidden_tag() }}
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title">General settings</span>
|
|
||||||
{{ wtf.render_field(edit_profile_settings_form.username, material_icon='person') }}
|
|
||||||
{{ wtf.render_field(edit_profile_settings_form.email, material_icon='email') }}
|
|
||||||
</div>
|
|
||||||
<div class="card-action">
|
|
||||||
<div class="right-align">
|
|
||||||
{{ wtf.render_field(edit_profile_settings_form.submit, material_icon='send') }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form method="POST">
|
|
||||||
{{ edit_notification_settings_form.hidden_tag() }}
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title">Notification settings</span>
|
|
||||||
{{ wtf.render_field(edit_notification_settings_form.job_status_mail_notification_level, material_icon='notifications') }}
|
|
||||||
</div>
|
|
||||||
<div class="card-action">
|
|
||||||
<div class="right-align">
|
|
||||||
{{ wtf.render_field(edit_notification_settings_form.submit, material_icon='send') }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form method="POST">
|
|
||||||
{{ admin_edit_user_form.hidden_tag() }}
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title">Administrator settings</span>
|
|
||||||
{{ wtf.render_field(admin_edit_user_form.role, material_icon='swap_vert') }}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col s12"><p> </p></div>
|
|
||||||
<div class="col s1">
|
|
||||||
<p><i class="material-icons">check</i></p>
|
|
||||||
</div>
|
|
||||||
<div class="col s8">
|
|
||||||
<p>{{ admin_edit_user_form.confirmed.label.text }}</p>
|
|
||||||
<p class="light">Change confirmation status manually.</p>
|
|
||||||
</div>
|
|
||||||
<div class="col s3 right-align">
|
|
||||||
<div class="switch">
|
|
||||||
<label>
|
|
||||||
{{ admin_edit_user_form.confirmed() }}
|
|
||||||
<span class="lever"></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-action right-align">
|
|
||||||
{{ wtf.render_field(admin_edit_user_form.submit, material_icon='send') }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<span class="card-title">Delete account</span>
|
|
||||||
<p>Deleting an account has the following effects:</p>
|
|
||||||
<ul>
|
|
||||||
<li>All data associated with your corpora and jobs will be permanently deleted.</li>
|
|
||||||
<li>All settings will be permanently deleted.</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="card-action right-align">
|
|
||||||
<a href="#delete-account-modal" class="btn modal-trigger red waves-effect waves-light"><i class="material-icons left">delete</i>Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock page_content %}
|
|
||||||
|
|
||||||
{% block modals %}
|
|
||||||
{{ super() }}
|
|
||||||
<div class="modal" id="delete-account-modal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<h4>Confirm deletion</h4>
|
|
||||||
<p>Do you really want to delete your account and all associated data? All associated corpora, jobs and files will be permanently deleted!</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
||||||
<a href="{{ url_for('.delete_user', user_id=user.id) }}" class="btn red waves-effect waves-light"><i class="material-icons left">delete</i>Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock modals %}
|
|
@ -1,131 +0,0 @@
|
|||||||
{% extends "base.html.j2" %}
|
|
||||||
|
|
||||||
{% block page_content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col s12 l2">
|
|
||||||
<p> </p>
|
|
||||||
{# <img src="{{ url_for('users.user_avatar', user_id=user.id) }}" alt="user-image" class="circle responsive-img"> #}
|
|
||||||
</div>
|
|
||||||
<div class="col s12 l10">
|
|
||||||
<h1 id="title">{{ title }}</h1>
|
|
||||||
<p>
|
|
||||||
<span class="chip hoverable tooltipped no-autoinit" id="user-role-chip">{{ user.role.name }}</span>
|
|
||||||
{% if user.confirmed %}
|
|
||||||
<span class="chip white-text" id="user-confirmed-chip" style="background-color: #4caf50;">confirmed</span>
|
|
||||||
{% else %}
|
|
||||||
<span class="chip white-text" id="user-confirmed-chip" style="background-color: #f44336;">unconfirmed</span>
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
{% if user.about_me %}
|
|
||||||
<p>{{ user.about_me }}</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12 hide-on-med-and-down"> </div>
|
|
||||||
|
|
||||||
<div class="col s12">
|
|
||||||
<ul class="tabs tabs-fixed-width z-depth-1">
|
|
||||||
<li class="tab"><a href="#user-info">User info</a></li>
|
|
||||||
<li class="tab"><a href="#user-corpora">Corpora</a></li>
|
|
||||||
<li class="tab"><a href="#user-jobs">Jobs</a></li>
|
|
||||||
<li class="tab"><a href="#user-tesseract-ocr-pipeline-models">Tesseract OCR Pipeline Models</a></li>
|
|
||||||
<li class="tab"><a href="#user-spacy-nlp-pipeline-models">SpaCy NLP Pipeline Models</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12" id="user-info">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<ul>
|
|
||||||
<li>Username: {{ user.username }}</li>
|
|
||||||
<li>Email: {{ user.email }}</li>
|
|
||||||
<li>Id: {{ user.id }}</li>
|
|
||||||
<li>Hashid: {{ user.hashid }}</li>
|
|
||||||
<li>Member since: {{ user.member_since.strftime('%Y-%m-%d') }}</li>
|
|
||||||
<li>Last seen: {% if user.last_seen %}{{ user.last_seen.strftime('%Y-%m-%d') }}</li>{% endif %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="card-action right-align">
|
|
||||||
<a class="btn waves-effect waves-light" href="{{ url_for('.user_settings', user_id=user.id) }}"><i class="material-icons left">edit</i>Edit</a>
|
|
||||||
<a class="btn red modal-trigger waves-effect waves-light" data-target="delete-user-modal"><i class="material-icons left">delete</i>Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12" id="user-corpora">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="corpus-list" data-user-id="{{ user.hashid }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12" id="user-jobs">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="job-list" data-user-id="{{ user.hashid }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12" id="user-spacy-nlp-pipeline-models">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="spacy-nlp-pipeline-model-list" data-user-id="{{ user.hashid }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12" id="user-tesseract-ocr-pipeline-models">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="tesseract-ocr-pipeline-model-list" data-user-id="{{ user.hashid }}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock page_content %}
|
|
||||||
|
|
||||||
|
|
||||||
{% block modals %}
|
|
||||||
{{ super() }}
|
|
||||||
<div id="delete-user-modal" class="modal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<h3>Delete user</h3>
|
|
||||||
<p>Do you really want to delete the user {{ user.username }}? All associated data will be permanently deleted!</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
||||||
<a class="btn red modal-close waves-effect waves-light"><i class="material-icons left">delete</i>Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock modals %}
|
|
||||||
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
{{ super() }}
|
|
||||||
<script>
|
|
||||||
let userRoleChip = document.querySelector('#user-role-chip');
|
|
||||||
let userRoleChipTooltip = M.Tooltip.init(
|
|
||||||
userRoleChip,
|
|
||||||
{
|
|
||||||
html: `
|
|
||||||
<p>Permissions</p>
|
|
||||||
<p class="left-align">
|
|
||||||
{% for permission in ['ADMINISTRATE', 'CONTRIBUTE', 'USE_API'] %}
|
|
||||||
<label>
|
|
||||||
<input class="filled-in" type="checkbox" {{ 'checked' if user.can(permission) }}>
|
|
||||||
<span>{{ permission|capitalize }}</span>
|
|
||||||
</label>
|
|
||||||
{% if not loop.last %}
|
|
||||||
<br>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</p>
|
|
||||||
`.trim()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
{% endblock scripts %}
|
|
@ -1,66 +0,0 @@
|
|||||||
{% extends "users/settings/settings.html.j2" %}
|
|
||||||
|
|
||||||
{% block admin_settings %}
|
|
||||||
<div class="col s12"></div>
|
|
||||||
|
|
||||||
<div class="col s12 l4">
|
|
||||||
<h4>Administrator Settings</h4>
|
|
||||||
<p>Here the Confirmation Status of the user can be set manually and a special role can be assigned.</p>
|
|
||||||
</div>
|
|
||||||
<div class="col s12 l8">
|
|
||||||
<br>
|
|
||||||
<ul class="collapsible no-autoinit settings-collapsible">
|
|
||||||
<li>
|
|
||||||
<div class="collapsible-header" style="justify-content: space-between;">
|
|
||||||
<span>Confirmation status</span>
|
|
||||||
<i class="caret material-icons">keyboard_arrow_right</i>
|
|
||||||
</div>
|
|
||||||
<div class="collapsible-body">
|
|
||||||
<div style="overflow: auto;">
|
|
||||||
<p class="left"><i class="material-icons">check</i></p>
|
|
||||||
<p class="left" style="margin-left: 10px;">
|
|
||||||
Confirmed<br>
|
|
||||||
<span class="light">Change confirmation status manually.</span>
|
|
||||||
</p>
|
|
||||||
<br class="hide-on-med-and-down">
|
|
||||||
<div class="switch right">
|
|
||||||
<label>
|
|
||||||
<input {% if user.confirmed %}checked{% endif %} id="user-confirmed-switch" type="checkbox">
|
|
||||||
<span class="lever"></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<div class="collapsible-header" style="justify-content: space-between;">
|
|
||||||
<span>Role</span>
|
|
||||||
<i class="caret material-icons">keyboard_arrow_right</i>
|
|
||||||
</div>
|
|
||||||
<div class="collapsible-body">
|
|
||||||
<form method="POST">
|
|
||||||
{{ update_user_form.hidden_tag() }}
|
|
||||||
{{ wtf.render_field(update_user_form.role, material_icon='manage_accounts') }}
|
|
||||||
<div class="right-align">
|
|
||||||
{{ wtf.render_field(update_user_form.submit, material_icon='send') }}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{% endblock admin_settings %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
{{ super() }}
|
|
||||||
<script>
|
|
||||||
let userConfirmedSwitchElement = document.querySelector('#user-confirmed-switch');
|
|
||||||
userConfirmedSwitchElement.addEventListener('change', (event) => {
|
|
||||||
let newConfirmed = userConfirmedSwitchElement.checked;
|
|
||||||
nopaque.requests.admin.users.entity.confirmed.update({{ user.hashid|tojson }}, newConfirmed)
|
|
||||||
.catch((response) => {
|
|
||||||
userConfirmedSwitchElement.checked = !userConfirmedSwitchElement;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock scripts %}
|
|
@ -1,34 +0,0 @@
|
|||||||
{% extends "base.html.j2" %}
|
|
||||||
|
|
||||||
{% block page_content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col s12">
|
|
||||||
<h1 id="title">{{ title }}</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col s12">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="admin-user-list no-autoinit" id="admin-user-list"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock page_content %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
{{ super() }}
|
|
||||||
<script>
|
|
||||||
let adminUserListElement = document.querySelector('#admin-user-list');
|
|
||||||
let adminUserList = new nopaque.resource_lists.AdminUserList(adminUserListElement);
|
|
||||||
adminUserList.add(
|
|
||||||
[
|
|
||||||
{% for user in users %}
|
|
||||||
{{ user.to_json_serializeable(backrefs=True)|tojson }},
|
|
||||||
{% endfor %}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
{% endblock scripts %}
|
|
@ -172,8 +172,6 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% block admin_settings %}{% endblock admin_settings %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock page_content %}
|
{% endblock page_content %}
|
||||||
|
@ -14,6 +14,7 @@ docker==7.0.0
|
|||||||
email_validator==2.1.1
|
email_validator==2.1.1
|
||||||
eventlet==0.34.2
|
eventlet==0.34.2
|
||||||
Flask==2.3.3
|
Flask==2.3.3
|
||||||
|
Flask-Admin==1.6.1
|
||||||
Flask-APScheduler==1.13.1
|
Flask-APScheduler==1.13.1
|
||||||
Flask-Assets==2.1.0
|
Flask-Assets==2.1.0
|
||||||
Flask-Hashids==1.0.3
|
Flask-Hashids==1.0.3
|
||||||
|
@ -4,6 +4,7 @@ dnspython==2.5.0
|
|||||||
docker
|
docker
|
||||||
eventlet==0.34.2
|
eventlet==0.34.2
|
||||||
Flask==2.3.3
|
Flask==2.3.3
|
||||||
|
Flask-Admin==1.6.1
|
||||||
Flask-APScheduler
|
Flask-APScheduler
|
||||||
Flask-Assets
|
Flask-Assets
|
||||||
Flask-Hashids
|
Flask-Hashids
|
||||||
|
Loading…
Reference in New Issue
Block a user