mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into development
This commit is contained in:
commit
30739f9111
@ -127,6 +127,8 @@ class IntEnumColumn(db.TypeDecorator):
|
|||||||
return value.value
|
return value.value
|
||||||
elif isinstance(value, int):
|
elif isinstance(value, int):
|
||||||
return self.enum_type(value).value
|
return self.enum_type(value).value
|
||||||
|
elif isinstance(value, str):
|
||||||
|
return self.enum_type[value].value
|
||||||
else:
|
else:
|
||||||
return TypeError()
|
return TypeError()
|
||||||
|
|
||||||
@ -144,8 +146,7 @@ class ContainerColumn(db.TypeDecorator):
|
|||||||
def process_bind_param(self, value, dialect):
|
def process_bind_param(self, value, dialect):
|
||||||
if isinstance(value, self.container_type):
|
if isinstance(value, self.container_type):
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
elif (isinstance(value, str)
|
elif isinstance(value, str) and isinstance(json.loads(value), self.container_type):
|
||||||
and isinstance(json.loads(value), self.container_type)):
|
|
||||||
return value
|
return value
|
||||||
else:
|
else:
|
||||||
return TypeError()
|
return TypeError()
|
||||||
|
@ -125,6 +125,8 @@ def transkribus_htr_pipeline():
|
|||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
abort(500)
|
abort(500)
|
||||||
transkribus_htr_pipeline_models = r.json()['trpModelMetadata']
|
transkribus_htr_pipeline_models = r.json()['trpModelMetadata']
|
||||||
|
transkribus_htr_pipeline_models.append({'modelId': 48513, 'name': 'Caroline Minuscle', 'language': 'lat', 'isoLanguages': ['lat']})
|
||||||
|
print(transkribus_htr_pipeline_models[len(transkribus_htr_pipeline_models)-1])
|
||||||
form = CreateTranskribusHTRPipelineJobForm(
|
form = CreateTranskribusHTRPipelineJobForm(
|
||||||
transkribus_htr_pipeline_models=transkribus_htr_pipeline_models,
|
transkribus_htr_pipeline_models=transkribus_htr_pipeline_models,
|
||||||
prefix='create-job-form',
|
prefix='create-job-form',
|
||||||
|
@ -1,24 +1,7 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import (
|
from wtforms import PasswordField, SelectField, SubmitField, ValidationError
|
||||||
BooleanField,
|
from wtforms.validators import DataRequired, EqualTo
|
||||||
FileField,
|
from app.models import UserSettingJobStatusMailNotificationLevel
|
||||||
PasswordField,
|
|
||||||
SelectField,
|
|
||||||
StringField,
|
|
||||||
SubmitField,
|
|
||||||
TextAreaField,
|
|
||||||
ValidationError
|
|
||||||
)
|
|
||||||
from wtforms.validators import (
|
|
||||||
DataRequired,
|
|
||||||
InputRequired,
|
|
||||||
Email,
|
|
||||||
EqualTo,
|
|
||||||
Length,
|
|
||||||
Regexp
|
|
||||||
)
|
|
||||||
from app.models import User, UserSettingJobStatusMailNotificationLevel
|
|
||||||
from app.auth import USERNAME_REGEX
|
|
||||||
|
|
||||||
|
|
||||||
class ChangePasswordForm(FlaskForm):
|
class ChangePasswordForm(FlaskForm):
|
||||||
@ -47,18 +30,14 @@ class ChangePasswordForm(FlaskForm):
|
|||||||
if not self.user.verify_password(field.data):
|
if not self.user.verify_password(field.data):
|
||||||
raise ValidationError('Invalid password')
|
raise ValidationError('Invalid password')
|
||||||
|
|
||||||
|
|
||||||
class EditNotificationSettingsForm(FlaskForm):
|
class EditNotificationSettingsForm(FlaskForm):
|
||||||
job_status_mail_notification_level = SelectField(
|
job_status_mail_notification_level = SelectField(
|
||||||
'Job status mail notification level',
|
'Job status mail notification level',
|
||||||
choices=[('', 'Choose your option')],
|
choices=[
|
||||||
|
(x.name, x.name.capitalize())
|
||||||
|
for x in UserSettingJobStatusMailNotificationLevel
|
||||||
|
],
|
||||||
validators=[DataRequired()]
|
validators=[DataRequired()]
|
||||||
)
|
)
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.job_status_mail_notification_level.choices += [
|
|
||||||
(x.name, x.name.capitalize())
|
|
||||||
for x in UserSettingJobStatusMailNotificationLevel
|
|
||||||
]
|
|
||||||
|
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
from flask import abort, flash, redirect, render_template, url_for
|
from flask import flash, redirect, render_template, url_for
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import ProfilePrivacySettings, UserSettingJobStatusMailNotificationLevel
|
from app.models import UserSettingJobStatusMailNotificationLevel
|
||||||
from . import bp
|
from . import bp
|
||||||
from .forms import (
|
from .forms import ChangePasswordForm, EditNotificationSettingsForm
|
||||||
ChangePasswordForm,
|
|
||||||
EditNotificationSettingsForm
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('', methods=['GET', 'POST'])
|
@bp.route('', methods=['GET', 'POST'])
|
||||||
@ -20,22 +17,20 @@ def settings():
|
|||||||
data=current_user.to_json_serializeable(),
|
data=current_user.to_json_serializeable(),
|
||||||
prefix='edit-notification-settings-form'
|
prefix='edit-notification-settings-form'
|
||||||
)
|
)
|
||||||
|
# region handle change_password_form POST
|
||||||
if change_password_form.submit.data and change_password_form.validate():
|
if change_password_form.submit.data and change_password_form.validate():
|
||||||
current_user.password = change_password_form.new_password.data
|
current_user.password = change_password_form.new_password.data
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your changes have been saved')
|
flash('Your changes have been saved')
|
||||||
return redirect(url_for('.index'))
|
return redirect(url_for('.settings'))
|
||||||
|
# endregion handle change_password_form POST
|
||||||
if (edit_notification_settings_form.submit
|
# region handle edit_notification_settings_form POST
|
||||||
and edit_notification_settings_form.validate()):
|
if edit_notification_settings_form.submit and edit_notification_settings_form.validate():
|
||||||
current_user.setting_job_status_mail_notification_level = (
|
current_user.setting_job_status_mail_notification_level = edit_notification_settings_form.job_status_mail_notification_level.data
|
||||||
UserSettingJobStatusMailNotificationLevel[
|
|
||||||
edit_notification_settings_form.job_status_mail_notification_level.data # noqa
|
|
||||||
]
|
|
||||||
)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your changes have been saved')
|
flash('Your changes have been saved')
|
||||||
return redirect(url_for('.settings'))
|
return redirect(url_for('.settings'))
|
||||||
|
# endregion handle edit_notification_settings_form POST
|
||||||
return render_template(
|
return render_template(
|
||||||
'settings/settings.html.j2',
|
'settings/settings.html.j2',
|
||||||
change_password_form=change_password_form,
|
change_password_form=change_password_form,
|
||||||
|
@ -8,33 +8,20 @@ class App {
|
|||||||
this.socket.on('PATCH', (patch) => {this.onPatch(patch);});
|
this.socket.on('PATCH', (patch) => {this.onPatch(patch);});
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser(userId) {
|
getUser(userId, backrefs=false, relationships=false) {
|
||||||
if (userId in this.data.promises.getUser) {
|
if (userId in this.data.promises.getUser) {
|
||||||
return this.data.promises.getUser[userId];
|
return this.data.promises.getUser[userId];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data.promises.getUser[userId] = new Promise((resolve, reject) => {
|
this.data.promises.getUser[userId] = new Promise((resolve, reject) => {
|
||||||
fetch(`/users/${userId}?backrefs=true&relationships=true`, {headers: {Accept: 'application/json'}})
|
this.socket.emit('GET /users/<user_id>', userId, backrefs, relationships, (response) => {
|
||||||
.then(
|
if (response.status !== 200) {
|
||||||
(response) => {
|
reject(response);
|
||||||
if (response.status === 403) {this.flash('Forbidden', 'error'); reject(response);}
|
return;
|
||||||
return response.json();
|
}
|
||||||
},
|
this.data.users[userId] = response.body;
|
||||||
(response) => {
|
resolve(this.data.users[userId]);
|
||||||
this.flash('Something went wrong', 'error');
|
});
|
||||||
reject(response);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
(user) => {
|
|
||||||
this.data.users[userId] = user;
|
|
||||||
resolve(this.data.users[userId]);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error(error, 'error');
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.data.promises.getUser[userId];
|
return this.data.promises.getUser[userId];
|
||||||
@ -47,11 +34,11 @@ class App {
|
|||||||
|
|
||||||
this.data.promises.subscribeUser[userId] = new Promise((resolve, reject) => {
|
this.data.promises.subscribeUser[userId] = new Promise((resolve, reject) => {
|
||||||
this.socket.emit('SUBSCRIBE /users/<user_id>', userId, (response) => {
|
this.socket.emit('SUBSCRIBE /users/<user_id>', userId, (response) => {
|
||||||
if (response.code === 200) {
|
if (response.status !== 200) {
|
||||||
resolve(response);
|
|
||||||
} else {
|
|
||||||
reject(response);
|
reject(response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
resolve(response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,17 +5,55 @@ from app.decorators import socketio_login_required
|
|||||||
from app.models import User
|
from app.models import User
|
||||||
|
|
||||||
|
|
||||||
|
@socketio.on('GET /users/<user_id>')
|
||||||
|
@socketio_login_required
|
||||||
|
def get_user(user_hashid, backrefs=False, relationships=False):
|
||||||
|
user_id = hashids.decode(user_hashid)
|
||||||
|
user = User.query.get(user_id)
|
||||||
|
if user is None:
|
||||||
|
return {'status': 404, 'statusText': 'Not found'}
|
||||||
|
if not (user == current_user or current_user.is_administrator):
|
||||||
|
return {'status': 403, 'statusText': 'Forbidden'}
|
||||||
|
return {
|
||||||
|
'body': user.to_json_serializeable(
|
||||||
|
backrefs=backrefs,
|
||||||
|
relationships=relationships
|
||||||
|
),
|
||||||
|
'status': 200,
|
||||||
|
'statusText': 'OK',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# @socketio.on('GET /users/<user_id>')
|
||||||
|
# @socketio_login_required
|
||||||
|
# def get_user(user_hashid):
|
||||||
|
# user_id = hashids.decode(user_hashid)
|
||||||
|
# user = User.query.get(user_id)
|
||||||
|
# if user is None:
|
||||||
|
# return {'options': {'status': 404, 'statusText': 'Not found'}}
|
||||||
|
# if not (user == current_user or current_user.is_administrator):
|
||||||
|
# return {'options': {'status': 403, 'statusText': 'Forbidden'}}
|
||||||
|
# return {
|
||||||
|
# 'body': user.to_json_serializable2(),
|
||||||
|
# 'options': {
|
||||||
|
# 'status': 200,
|
||||||
|
# 'statusText': 'OK',
|
||||||
|
# 'headers': {'Content-Type: application/json'}
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('SUBSCRIBE /users/<user_id>')
|
@socketio.on('SUBSCRIBE /users/<user_id>')
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def subscribe_user(user_hashid):
|
def subscribe_user(user_hashid):
|
||||||
user_id = hashids.decode(user_hashid)
|
user_id = hashids.decode(user_hashid)
|
||||||
user = User.query.get(user_id)
|
user = User.query.get(user_id)
|
||||||
if user is None:
|
if user is None:
|
||||||
return {'code': 404, 'msg': 'Not found'}
|
return {'status': 404, 'statusText': 'Not found'}
|
||||||
if not (user == current_user or current_user.is_administrator):
|
if not (user == current_user or current_user.is_administrator):
|
||||||
return {'code': 403, 'msg': 'Forbidden'}
|
return {'status': 403, 'statusText': 'Forbidden'}
|
||||||
join_room(f'/users/{user.hashid}')
|
join_room(f'/users/{user.hashid}')
|
||||||
return {'code': 200, 'msg': 'OK'}
|
return {'status': 200, 'statusText': 'OK'}
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('UNSUBSCRIBE /users/<user_id>')
|
@socketio.on('UNSUBSCRIBE /users/<user_id>')
|
||||||
@ -24,8 +62,8 @@ def unsubscribe_user(user_hashid):
|
|||||||
user_id = hashids.decode(user_hashid)
|
user_id = hashids.decode(user_hashid)
|
||||||
user = User.query.get(user_id)
|
user = User.query.get(user_id)
|
||||||
if user is None:
|
if user is None:
|
||||||
return {'code': 404, 'msg': 'Not found'}
|
return {'status': 404, 'statusText': 'Not found'}
|
||||||
if not (user == current_user or current_user.is_administrator):
|
if not (user == current_user or current_user.is_administrator):
|
||||||
return {'code': 403, 'msg': 'Forbidden'}
|
return {'status': 403, 'statusText': 'Forbidden'}
|
||||||
leave_room(f'/users/{user.hashid}')
|
leave_room(f'/users/{user.hashid}')
|
||||||
return {'code': 200, 'msg': 'OK'}
|
return {'status': 200, 'statusText': 'OK'}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from flask import abort, current_app, request
|
from flask import abort, current_app
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from app import db
|
from app import db
|
||||||
@ -9,13 +9,7 @@ from . import bp
|
|||||||
@bp.route('/<hashid:user_id>')
|
@bp.route('/<hashid:user_id>')
|
||||||
@login_required
|
@login_required
|
||||||
def user(user_id):
|
def user(user_id):
|
||||||
user = User.query.get_or_404(user_id)
|
abort(503)
|
||||||
if not (user == current_user or current_user.is_administrator()):
|
|
||||||
abort(403)
|
|
||||||
backrefs = request.args.get('backrefs', 'false').lower() == 'true'
|
|
||||||
relationships = (
|
|
||||||
request.args.get('relationships', 'false').lower() == 'true')
|
|
||||||
return user.to_json_serializeable(backrefs=backrefs, relationships=relationships), 200
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:user_id>', methods=['DELETE'])
|
@bp.route('/<hashid:user_id>', methods=['DELETE'])
|
||||||
|
Loading…
Reference in New Issue
Block a user