mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Integrate CorpusFollowerRoles
This commit is contained in:
parent
1be8a449fe
commit
38d09a3490
17
app/cli.py
17
app/cli.py
@ -3,10 +3,11 @@ from flask_migrate import upgrade
|
|||||||
import click
|
import click
|
||||||
import os
|
import os
|
||||||
from app.models import (
|
from app.models import (
|
||||||
|
CorpusFollowerRole,
|
||||||
Role,
|
Role,
|
||||||
User,
|
SpaCyNLPPipelineModel,
|
||||||
TesseractOCRPipelineModel,
|
TesseractOCRPipelineModel,
|
||||||
SpaCyNLPPipelineModel
|
User
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -30,19 +31,23 @@ def register(app):
|
|||||||
def deploy():
|
def deploy():
|
||||||
''' Run deployment tasks. '''
|
''' Run deployment tasks. '''
|
||||||
# Make default directories
|
# Make default directories
|
||||||
|
print('Make default directories')
|
||||||
_make_default_dirs()
|
_make_default_dirs()
|
||||||
|
|
||||||
# migrate database to latest revision
|
# migrate database to latest revision
|
||||||
|
print('Migrate database to latest revision')
|
||||||
upgrade()
|
upgrade()
|
||||||
|
|
||||||
# Insert/Update default database values
|
# Insert/Update default database values
|
||||||
current_app.logger.info('Insert/Update default roles')
|
print('Insert/Update default Roles')
|
||||||
Role.insert_defaults()
|
Role.insert_defaults()
|
||||||
current_app.logger.info('Insert/Update default users')
|
print('Insert/Update default Users')
|
||||||
User.insert_defaults()
|
User.insert_defaults()
|
||||||
current_app.logger.info('Insert/Update default SpaCyNLPPipelineModels')
|
print('Insert/Update default CorpusFollowerRoles')
|
||||||
|
CorpusFollowerRole.insert_defaults()
|
||||||
|
print('Insert/Update default SpaCyNLPPipelineModels')
|
||||||
SpaCyNLPPipelineModel.insert_defaults()
|
SpaCyNLPPipelineModel.insert_defaults()
|
||||||
current_app.logger.info('Insert/Update default TesseractOCRPipelineModels')
|
print('Insert/Update default TesseractOCRPipelineModels')
|
||||||
TesseractOCRPipelineModel.insert_defaults()
|
TesseractOCRPipelineModel.insert_defaults()
|
||||||
|
|
||||||
@app.cli.group()
|
@app.cli.group()
|
||||||
|
@ -21,6 +21,7 @@ from app.models import (
|
|||||||
CorpusFile,
|
CorpusFile,
|
||||||
CorpusFollowerAssociation,
|
CorpusFollowerAssociation,
|
||||||
CorpusFollowerPermission,
|
CorpusFollowerPermission,
|
||||||
|
CorpusFollowerRole,
|
||||||
CorpusStatus,
|
CorpusStatus,
|
||||||
User
|
User
|
||||||
)
|
)
|
||||||
@ -107,30 +108,16 @@ def current_user_unfollow_corpus(corpus_id):
|
|||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/permissions/<permission_name>/add', methods=['POST'])
|
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['POST'])
|
||||||
def add_permission(corpus_id, follower_id, permission_name):
|
def add_permission(corpus_id, follower_id):
|
||||||
try:
|
|
||||||
permission = CorpusFollowerPermission[permission_name]
|
|
||||||
except KeyError:
|
|
||||||
abort(409) # f'Permission "{permission_name}" does not exist'
|
|
||||||
corpus_follower_association = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
corpus_follower_association = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
||||||
if not (corpus_follower_association.corpus.user == current_user or current_user.is_administrator()):
|
if not (corpus_follower_association.corpus.user == current_user or current_user.is_administrator()):
|
||||||
abort(403)
|
abort(403)
|
||||||
corpus_follower_association.add_permission(permission)
|
role_name = request.json.get('role')
|
||||||
db.session.commit()
|
if role_name is None:
|
||||||
return '', 204
|
abort(400)
|
||||||
|
corpus_follower_role = CorpusFollowerRole.query.filter_by(name=role_name).first_or_404()
|
||||||
|
corpus_follower_association.role = corpus_follower_role
|
||||||
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/permissions/<permission_name>/remove', methods=['POST'])
|
|
||||||
def remove_permission(corpus_id, follower_id, permission_name):
|
|
||||||
try:
|
|
||||||
permission = CorpusFollowerPermission[permission_name]
|
|
||||||
except KeyError:
|
|
||||||
return make_response(f'Permission "{permission_name}" does not exist', 409)
|
|
||||||
corpus_follower_association = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
|
||||||
if not (corpus_follower_association.corpus.user == current_user or current_user.is_administrator()):
|
|
||||||
abort(403)
|
|
||||||
corpus_follower_association.remove_permission(permission)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
191
app/models.py
191
app/models.py
@ -6,6 +6,7 @@ from flask_login import UserMixin
|
|||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
from typing import Union
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
import json
|
import json
|
||||||
@ -57,6 +58,15 @@ class Permission(IntEnum):
|
|||||||
CONTRIBUTE = 2
|
CONTRIBUTE = 2
|
||||||
USE_API = 4
|
USE_API = 4
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(permission: Union['Permission', int, str]) -> 'Permission':
|
||||||
|
if isinstance(permission, Permission):
|
||||||
|
return permission
|
||||||
|
if isinstance(permission, int):
|
||||||
|
return Permission(permission)
|
||||||
|
if isinstance(permission, str):
|
||||||
|
return Permission[permission]
|
||||||
|
raise TypeError('permission must be Permission, int, or str')
|
||||||
|
|
||||||
class UserSettingJobStatusMailNotificationLevel(IntEnum):
|
class UserSettingJobStatusMailNotificationLevel(IntEnum):
|
||||||
NONE = 1
|
NONE = 1
|
||||||
@ -72,8 +82,22 @@ class ProfilePrivacySettings(IntEnum):
|
|||||||
|
|
||||||
class CorpusFollowerPermission(IntEnum):
|
class CorpusFollowerPermission(IntEnum):
|
||||||
VIEW = 1
|
VIEW = 1
|
||||||
CONTRIBUTE = 2
|
ADD_CORPUS_FILE = 2
|
||||||
ADMINISTRATE = 4
|
UPDATE_CORPUS_FILE = 4
|
||||||
|
REMOVE_CORPUS_FILE = 8
|
||||||
|
GENERATE_SHARE_LINK = 16
|
||||||
|
REMOVE_FOLLOWER = 32
|
||||||
|
UPDATE_FOLLOWER = 64
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(permission: Union['CorpusFollowerPermission', int, str]) -> 'CorpusFollowerPermission':
|
||||||
|
if isinstance(permission, CorpusFollowerPermission):
|
||||||
|
return permission
|
||||||
|
if isinstance(permission, int):
|
||||||
|
return CorpusFollowerPermission(permission)
|
||||||
|
if isinstance(permission, str):
|
||||||
|
return CorpusFollowerPermission[permission]
|
||||||
|
raise TypeError('permission must be CorpusFollowerPermission, int, or str')
|
||||||
# endregion enums
|
# endregion enums
|
||||||
|
|
||||||
|
|
||||||
@ -181,16 +205,19 @@ class Role(HashidMixin, db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<Role {self.name}>'
|
return f'<Role {self.name}>'
|
||||||
|
|
||||||
def add_permission(self, permission):
|
def has_permission(self, permission: Union[Permission, int, str]):
|
||||||
if not self.has_permission(permission):
|
perm = Permission.get(permission)
|
||||||
self.permissions += permission
|
return self.permissions & perm.value == perm.value
|
||||||
|
|
||||||
def has_permission(self, permission):
|
def add_permission(self, permission: Union[Permission, int, str]):
|
||||||
return self.permissions & permission == permission
|
perm = Permission.get(permission)
|
||||||
|
if not self.has_permission(perm):
|
||||||
def remove_permission(self, permission):
|
self.permissions += perm.value
|
||||||
if self.has_permission(permission):
|
|
||||||
self.permissions -= permission
|
def remove_permission(self, permission: Union[Permission, int, str]):
|
||||||
|
perm = Permission.get(permission)
|
||||||
|
if self.has_permission(perm):
|
||||||
|
self.permissions -= perm.value
|
||||||
|
|
||||||
def reset_permissions(self):
|
def reset_permissions(self):
|
||||||
self.permissions = 0
|
self.permissions = 0
|
||||||
@ -319,6 +346,96 @@ class Avatar(HashidMixin, FileMixin, db.Model):
|
|||||||
return json_serializeable
|
return json_serializeable
|
||||||
|
|
||||||
|
|
||||||
|
class CorpusFollowerRole(HashidMixin, db.Model):
|
||||||
|
__tablename__ = 'corpus_follower_roles'
|
||||||
|
# Primary key
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
# Fields
|
||||||
|
name = db.Column(db.String(64), unique=True)
|
||||||
|
default = db.Column(db.Boolean, default=False, index=True)
|
||||||
|
permissions = db.Column(db.Integer, default=0)
|
||||||
|
# Relationships
|
||||||
|
corpus_follower_associations = db.relationship(
|
||||||
|
'CorpusFollowerAssociation',
|
||||||
|
back_populates='role',
|
||||||
|
lazy='dynamic'
|
||||||
|
)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<CorpusFollowerRole {self.name}>'
|
||||||
|
|
||||||
|
def has_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
||||||
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
|
return self.permissions & perm.value == perm.value
|
||||||
|
|
||||||
|
def add_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
||||||
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
|
if not self.has_permission(perm):
|
||||||
|
self.permissions += perm.value
|
||||||
|
|
||||||
|
def remove_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
||||||
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
|
if self.has_permission(perm):
|
||||||
|
self.permissions -= perm.value
|
||||||
|
|
||||||
|
def reset_permissions(self):
|
||||||
|
self.permissions = 0
|
||||||
|
|
||||||
|
def to_json_serializeable(self, backrefs=False, relationships=False):
|
||||||
|
json_serializeable = {
|
||||||
|
'id': self.hashid,
|
||||||
|
'default': self.default,
|
||||||
|
'name': self.name,
|
||||||
|
'permissions': [
|
||||||
|
x.name
|
||||||
|
for x in CorpusFollowerPermission
|
||||||
|
if self.has_permission(x)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
if backrefs:
|
||||||
|
pass
|
||||||
|
if relationships:
|
||||||
|
json_serializeable['corpus_follower_association'] = {
|
||||||
|
x.hashid: x.to_json_serializeable(relationships=True)
|
||||||
|
for x in self.corpus_follower_association
|
||||||
|
}
|
||||||
|
return json_serializeable
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def insert_defaults():
|
||||||
|
roles = {
|
||||||
|
'Viewer': [
|
||||||
|
CorpusFollowerPermission.VIEW
|
||||||
|
],
|
||||||
|
'Contributor': [
|
||||||
|
CorpusFollowerPermission.VIEW,
|
||||||
|
CorpusFollowerPermission.ADD_CORPUS_FILE,
|
||||||
|
CorpusFollowerPermission.UPDATE_CORPUS_FILE,
|
||||||
|
CorpusFollowerPermission.REMOVE_CORPUS_FILE
|
||||||
|
],
|
||||||
|
'Administrator': [
|
||||||
|
CorpusFollowerPermission.VIEW,
|
||||||
|
CorpusFollowerPermission.ADD_CORPUS_FILE,
|
||||||
|
CorpusFollowerPermission.UPDATE_CORPUS_FILE,
|
||||||
|
CorpusFollowerPermission.REMOVE_CORPUS_FILE,
|
||||||
|
CorpusFollowerPermission.GENERATE_SHARE_LINK,
|
||||||
|
CorpusFollowerPermission.REMOVE_FOLLOWER,
|
||||||
|
CorpusFollowerPermission.UPDATE_FOLLOWER
|
||||||
|
]
|
||||||
|
}
|
||||||
|
default_role_name = 'Viewer'
|
||||||
|
for role_name, permissions in roles.items():
|
||||||
|
role = CorpusFollowerRole.query.filter_by(name=role_name).first()
|
||||||
|
if role is None:
|
||||||
|
role = CorpusFollowerRole(name=role_name)
|
||||||
|
role.reset_permissions()
|
||||||
|
for permission in permissions:
|
||||||
|
role.add_permission(permission)
|
||||||
|
role.default = role.name == default_role_name
|
||||||
|
db.session.add(role)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
class CorpusFollowerAssociation(HashidMixin, db.Model):
|
class CorpusFollowerAssociation(HashidMixin, db.Model):
|
||||||
__tablename__ = 'corpus_follower_associations'
|
__tablename__ = 'corpus_follower_associations'
|
||||||
# Primary key
|
# Primary key
|
||||||
@ -326,41 +443,38 @@ class CorpusFollowerAssociation(HashidMixin, db.Model):
|
|||||||
# Foreign keys
|
# Foreign keys
|
||||||
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
||||||
follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
follower_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||||
# Fields
|
role_id = db.Column(db.Integer, db.ForeignKey('corpus_follower_roles.id'))
|
||||||
permissions = db.Column(db.Integer, default=0, nullable=False)
|
|
||||||
# Relationships
|
# Relationships
|
||||||
corpus = db.relationship('Corpus', back_populates='corpus_follower_associations')
|
corpus = db.relationship(
|
||||||
follower = db.relationship('User', back_populates='corpus_follower_associations')
|
'Corpus',
|
||||||
|
back_populates='corpus_follower_associations'
|
||||||
|
)
|
||||||
|
follower = db.relationship(
|
||||||
|
'User',
|
||||||
|
back_populates='corpus_follower_associations'
|
||||||
|
)
|
||||||
|
role = db.relationship(
|
||||||
|
'CorpusFollowerRole',
|
||||||
|
back_populates='corpus_follower_associations'
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
if self.role is None:
|
||||||
|
self.role = CorpusFollowerRole.query.filter_by(default=True).first()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<CorpusFollowerAssociation {self.follower.__repr__()} ~ {self.corpus.__repr__()}>'
|
return f'<CorpusFollowerAssociation {self.follower.__repr__()} ~ {self.corpus.__repr__()}>'
|
||||||
|
|
||||||
def has_permission(self, permission: CorpusFollowerPermission):
|
|
||||||
return self.permissions & permission.value == permission.value
|
|
||||||
|
|
||||||
def add_permission(self, permission: CorpusFollowerPermission):
|
|
||||||
if not self.has_permission(permission):
|
|
||||||
self.permissions += permission.value
|
|
||||||
|
|
||||||
def remove_permission(self, permission: CorpusFollowerPermission):
|
|
||||||
if self.has_permission(permission):
|
|
||||||
self.permissions -= permission.value
|
|
||||||
|
|
||||||
def to_json_serializeable(self, backrefs=False, relationships=False):
|
def to_json_serializeable(self, backrefs=False, relationships=False):
|
||||||
json_serializeable = {
|
json_serializeable = {
|
||||||
'id': self.hashid,
|
'id': self.hashid,
|
||||||
'permissions': [
|
|
||||||
x.name for x in CorpusFollowerPermission
|
|
||||||
if self.has_permission(x)
|
|
||||||
],
|
|
||||||
'corpus': self.corpus.to_json_serializeable(),
|
'corpus': self.corpus.to_json_serializeable(),
|
||||||
'follower': self.follower.to_json_serializeable()
|
'follower': self.follower.to_json_serializeable(),
|
||||||
|
'role': self.role.to_json_serializeable()
|
||||||
}
|
}
|
||||||
if backrefs:
|
if backrefs:
|
||||||
json_serializeable['corpus'] = \
|
pass
|
||||||
self.corpus.to_json_serializeable(backrefs=True)
|
|
||||||
json_serializeable['follower'] = \
|
|
||||||
self.follower.to_json_serializeable(backrefs=True)
|
|
||||||
if relationships:
|
if relationships:
|
||||||
pass
|
pass
|
||||||
return json_serializeable
|
return json_serializeable
|
||||||
@ -559,7 +673,6 @@ class User(HashidMixin, UserMixin, db.Model):
|
|||||||
issuer=current_app.config['SERVER_NAME'],
|
issuer=current_app.config['SERVER_NAME'],
|
||||||
options={'require': ['exp', 'iat', 'iss', 'purpose', 'sub']}
|
options={'require': ['exp', 'iat', 'iss', 'purpose', 'sub']}
|
||||||
)
|
)
|
||||||
current_app.logger.warning(payload)
|
|
||||||
except jwt.PyJWTError:
|
except jwt.PyJWTError:
|
||||||
return False
|
return False
|
||||||
if payload.get('purpose') != 'user.confirm':
|
if payload.get('purpose') != 'user.confirm':
|
||||||
@ -687,7 +800,7 @@ class User(HashidMixin, UserMixin, db.Model):
|
|||||||
self.role.to_json_serializeable(backrefs=True)
|
self.role.to_json_serializeable(backrefs=True)
|
||||||
if relationships:
|
if relationships:
|
||||||
json_serializeable['corpus_follower_associations'] = {
|
json_serializeable['corpus_follower_associations'] = {
|
||||||
x.hashid: x.to_json_serializeable(relationships=True)
|
x.hashid: x.to_json_serializeable()
|
||||||
for x in self.corpus_follower_associations
|
for x in self.corpus_follower_associations
|
||||||
}
|
}
|
||||||
json_serializeable['corpora'] = {
|
json_serializeable['corpora'] = {
|
||||||
@ -1469,7 +1582,7 @@ class Corpus(HashidMixin, db.Model):
|
|||||||
self.user.to_json_serializeable(backrefs=True)
|
self.user.to_json_serializeable(backrefs=True)
|
||||||
if relationships:
|
if relationships:
|
||||||
json_serializeable['corpus_follower_associations'] = {
|
json_serializeable['corpus_follower_associations'] = {
|
||||||
x.hashid: x.to_json_serializeable(relationships=True)
|
x.hashid: x.to_json_serializeable()
|
||||||
for x in self.corpus_follower_associations
|
for x in self.corpus_follower_associations
|
||||||
}
|
}
|
||||||
json_serializeable['files'] = {
|
json_serializeable['files'] = {
|
||||||
|
@ -7,6 +7,9 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
|
|
||||||
constructor(listContainerElement, options = {}) {
|
constructor(listContainerElement, options = {}) {
|
||||||
super(listContainerElement, options);
|
super(listContainerElement, options);
|
||||||
|
this.listjs.on('updated', () => {
|
||||||
|
M.FormSelect.init(this.listjs.list.querySelectorAll('.list-item select'));
|
||||||
|
});
|
||||||
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
||||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||||
this.isInitialized = false;
|
this.isInitialized = false;
|
||||||
@ -28,30 +31,21 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
return (values) => {
|
return (values) => {
|
||||||
return `
|
return `
|
||||||
<tr class="list-item clickable hoverable">
|
<tr class="list-item clickable hoverable">
|
||||||
<td><img alt="user-image" class="circle responsive-img avatar" style="width:50%"></td>
|
<td><img alt="follower-avatar" class="circle responsive-img follower-avatar" style="width:50%"></td>
|
||||||
<td><b class="username"><b></td>
|
<td><b class="follower-username"><b></td>
|
||||||
<td><span class="full-name"></span><br><i class="about-me"></i></td>
|
|
||||||
<td>
|
<td>
|
||||||
<span class="disable-on-click">
|
<span class="follower-full-name"></span>
|
||||||
<label>
|
|
||||||
<input ${values['permission-can-VIEW'] ? 'checked' : ''} class="permission-can-VIEW list-action-trigger" data-list-action="toggle-permission" data-permission="VIEW" type="checkbox">
|
|
||||||
<span>View</span>
|
|
||||||
</label>
|
|
||||||
</span>
|
|
||||||
<br>
|
<br>
|
||||||
<span class="disable-on-click">
|
<i class="follower-about-me"></i>
|
||||||
<label>
|
</td>
|
||||||
<input ${values['permission-can-CONTRIBUTE'] ? 'checked' : ''} class="permission-can-CONTRIBUTE list-action-trigger" data-list-action="toggle-permission" data-permission="CONTRIBUTE" type="checkbox">
|
<td>
|
||||||
<span>Contribute</span>
|
<div class="input-field disable-on-click list-action-trigger" data-list-action="update-role">
|
||||||
</label>
|
<select>
|
||||||
</span>
|
<option value="Viewer" ${values['role.name'] === 'Viewer' ? 'selected' : ''}>Viewer</option>
|
||||||
<br>
|
<option value="Contributor" ${values['role.name'] === 'Contributor' ? 'selected' : ''}>Contributor</option>
|
||||||
<span class="disable-on-click">
|
<option value="Administrator" ${values['role.name'] === 'Administrator' ? 'selected' : ''}>Administrator</option>
|
||||||
<label>
|
</select>
|
||||||
<input ${values['permission-can-ADMINISTRATE'] ? 'checked' : ''} class="permission-can-ADMINISTRATE list-action-trigger" data-list-action="toggle-permission" data-permission="ADMINISTRATE" type="checkbox">
|
</div>
|
||||||
<span>Administrate</span>
|
|
||||||
</label>
|
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="right-align">
|
<td class="right-align">
|
||||||
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="unfollow-request"><i class="material-icons">delete</i></a>
|
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="unfollow-request"><i class="material-icons">delete</i></a>
|
||||||
@ -66,10 +60,10 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
return [
|
return [
|
||||||
{data: ['id']},
|
{data: ['id']},
|
||||||
{data: ['follower-id']},
|
{data: ['follower-id']},
|
||||||
{name: 'avatar', attr: 'src'},
|
{name: 'follower-avatar', attr: 'src'},
|
||||||
'username',
|
'follower-username',
|
||||||
'about-me',
|
'follower-about-me',
|
||||||
'full-name'
|
'follower-full-name'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +84,7 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
<th style="width:15%;"></th>
|
<th style="width:15%;"></th>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
<th>User details</th>
|
<th>User details</th>
|
||||||
<th>Permissions</th>
|
<th>Role</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -104,13 +98,11 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
return {
|
return {
|
||||||
'id': corpusFollowerAssociation.id,
|
'id': corpusFollowerAssociation.id,
|
||||||
'follower-id': corpusFollowerAssociation.follower.id,
|
'follower-id': corpusFollowerAssociation.follower.id,
|
||||||
'avatar': corpusFollowerAssociation.follower.avatar ? `/users/${corpusFollowerAssociation.follower.id}/avatar` : '/static/images/user_avatar.png',
|
'follower-avatar': corpusFollowerAssociation.follower.avatar ? `/users/${corpusFollowerAssociation.follower.id}/avatar` : '/static/images/user_avatar.png',
|
||||||
'username': corpusFollowerAssociation.follower.username,
|
'follower-username': corpusFollowerAssociation.follower.username,
|
||||||
'full-name': corpusFollowerAssociation.follower.full_name ? corpusFollowerAssociation.follower.full_name : '',
|
'follower-full-name': corpusFollowerAssociation.follower.full_name ? corpusFollowerAssociation.follower.full_name : '',
|
||||||
'about-me': corpusFollowerAssociation.follower.about_me ? corpusFollowerAssociation.follower.about_me : '',
|
'follower-about-me': corpusFollowerAssociation.follower.about_me ? corpusFollowerAssociation.follower.about_me : '',
|
||||||
'permission-can-VIEW': corpusFollowerAssociation.permissions.includes('VIEW'),
|
'role-name': corpusFollowerAssociation.role.name
|
||||||
'permission-can-CONTRIBUTE': corpusFollowerAssociation.permissions.includes('CONTRIBUTE'),
|
|
||||||
'permission-can-ADMINISTRATE': corpusFollowerAssociation.permissions.includes('ADMINISTRATE')
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +111,7 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChange(event) {
|
onChange(event) {
|
||||||
if (event.target.tagName !== 'INPUT') {return;}
|
console.log(event.target.tagName);
|
||||||
let listItemElement = event.target.closest('.list-item[data-id]');
|
let listItemElement = event.target.closest('.list-item[data-id]');
|
||||||
if (listItemElement === null) {return;}
|
if (listItemElement === null) {return;}
|
||||||
let itemId = listItemElement.dataset.id;
|
let itemId = listItemElement.dataset.id;
|
||||||
@ -127,16 +119,10 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
if (listActionElement === null) {return;}
|
if (listActionElement === null) {return;}
|
||||||
let listAction = listActionElement.dataset.listAction;
|
let listAction = listActionElement.dataset.listAction;
|
||||||
switch (listAction) {
|
switch (listAction) {
|
||||||
case 'toggle-permission': {
|
case 'update-role': {
|
||||||
let followerId = listItemElement.dataset.followerId;
|
let followerId = listItemElement.dataset.followerId;
|
||||||
let permission = listActionElement.dataset.permission;
|
let roleName = event.target.value;
|
||||||
if (event.target.checked) {
|
Utils.updateCorpusFollowerRole(this.corpusId, followerId, roleName);
|
||||||
Utils.addCorpusFollowerPermissionRequest(this.corpusId, followerId, permission)
|
|
||||||
.catch((error) => {event.target.checked = !event.target.checked;});
|
|
||||||
} else {
|
|
||||||
Utils.removeCorpusFollowerPermissionRequest(this.corpusId, followerId, permission)
|
|
||||||
.catch((error) => {event.target.checked = !event.target.checked;});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -188,11 +174,11 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'replace': {
|
case 'replace': {
|
||||||
// let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)/(service|status|description|title)$`);
|
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)/role$`);
|
||||||
// if (re.test(operation.path)) {
|
if (re.test(operation.path)) {
|
||||||
// let [match, jobId, valueName] = operation.path.match(re);
|
let [match, jobId, valueName] = operation.path.match(re);
|
||||||
// this.replace(jobId, valueName, operation.value);
|
this.replace(jobId, valueName, operation.value);
|
||||||
// }
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -36,13 +36,13 @@
|
|||||||
<li><a href="{{ url_for('settings.settings') }}"><i class="material-icons">settings</i>General Settings</a></li>
|
<li><a href="{{ url_for('settings.settings') }}"><i class="material-icons">settings</i>General Settings</a></li>
|
||||||
<li><a href="{{ url_for('users.edit_profile', user_id=current_user.id) }}"><i class="material-icons left">contact_page</i>Profile settings</a></li>
|
<li><a href="{{ url_for('users.edit_profile', user_id=current_user.id) }}"><i class="material-icons left">contact_page</i>Profile settings</a></li>
|
||||||
<li><a href="{{ url_for('auth.logout') }}">Log out</a></li>
|
<li><a href="{{ url_for('auth.logout') }}">Log out</a></li>
|
||||||
{% if current_user.can(Permission.ADMINISTRATE) or current_user.can(Permission.USE_API) %}
|
{% if current_user.can('ADMINISTRATE') or current_user.can('USE_API') %}
|
||||||
<li><div class="divider"></div></li>
|
<li><div class="divider"></div></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_user.can(Permission.ADMINISTRATE) %}
|
{% if current_user.can('ADMINISTRATE') %}
|
||||||
<li><a href="{{ url_for('admin.index') }}"><i class="material-icons">admin_panel_settings</i>Administration</a></li>
|
<li><a href="{{ url_for('admin.index') }}"><i class="material-icons">admin_panel_settings</i>Administration</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_user.can(Permission.USE_API) %}
|
{% if current_user.can('USE_API') %}
|
||||||
<li><a href="{{ url_for('apifairy.docs') }}"><i class="material-icons">api</i>API</a></li>
|
<li><a href="{{ url_for('apifairy.docs') }}"><i class="material-icons">api</i>API</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
72
migrations/versions/1f77ce4346c6_.py
Normal file
72
migrations/versions/1f77ce4346c6_.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 1f77ce4346c6
|
||||||
|
Revises: 03c7211f089d
|
||||||
|
Create Date: 2023-02-22 12:56:30.176665
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '1f77ce4346c6'
|
||||||
|
down_revision = '03c7211f089d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
'corpus_follower_roles',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=64), nullable=True),
|
||||||
|
sa.Column('default', sa.Boolean(), nullable=True),
|
||||||
|
sa.Column('permissions', sa.Integer(), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('name')
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f('ix_corpus_follower_roles_default'),
|
||||||
|
'corpus_follower_roles',
|
||||||
|
['default'],
|
||||||
|
unique=False
|
||||||
|
)
|
||||||
|
|
||||||
|
op.add_column(
|
||||||
|
'corpus_follower_associations',
|
||||||
|
sa.Column('role_id', sa.Integer(), nullable=True)
|
||||||
|
)
|
||||||
|
op.create_foreign_key(
|
||||||
|
'fk_corpus_follower_associations_role_id_corpus_follower_roles',
|
||||||
|
'corpus_follower_associations',
|
||||||
|
'corpus_follower_roles',
|
||||||
|
['role_id'],
|
||||||
|
['id']
|
||||||
|
)
|
||||||
|
op.drop_column('corpus_follower_associations', 'permissions')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.add_column(
|
||||||
|
'corpus_follower_associations',
|
||||||
|
sa.Column('permissions', sa.Integer(), nullable=True)
|
||||||
|
)
|
||||||
|
op.execute('UPDATE corpus_follower_associations SET permissions = 0;')
|
||||||
|
op.alter_column(
|
||||||
|
'corpus_follower_associations',
|
||||||
|
'permissions',
|
||||||
|
nullable=False
|
||||||
|
)
|
||||||
|
op.drop_constraint(
|
||||||
|
'fk_corpus_follower_associations_role_id_corpus_follower_roles',
|
||||||
|
'corpus_follower_associations',
|
||||||
|
type_='foreignkey'
|
||||||
|
)
|
||||||
|
op.drop_column('corpus_follower_associations', 'role_id')
|
||||||
|
|
||||||
|
op.drop_index(
|
||||||
|
op.f('ix_corpus_follower_roles_default'),
|
||||||
|
table_name='corpus_follower_roles'
|
||||||
|
)
|
||||||
|
op.drop_table('corpus_follower_roles')
|
11
nopaque.py
11
nopaque.py
@ -9,6 +9,7 @@ from app.models import (
|
|||||||
Corpus,
|
Corpus,
|
||||||
CorpusFile,
|
CorpusFile,
|
||||||
CorpusFollowerAssociation,
|
CorpusFollowerAssociation,
|
||||||
|
CorpusFollowerRole,
|
||||||
Job,
|
Job,
|
||||||
JobInput,
|
JobInput,
|
||||||
JobResult,
|
JobResult,
|
||||||
@ -26,25 +27,19 @@ app: Flask = create_app()
|
|||||||
cli.register(app)
|
cli.register(app)
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
|
||||||
def make_context() -> Dict[str, Any]:
|
|
||||||
''' Adds variables to the template context. '''
|
|
||||||
return {'Permission': Permission}
|
|
||||||
|
|
||||||
|
|
||||||
@app.shell_context_processor
|
@app.shell_context_processor
|
||||||
def make_shell_context() -> Dict[str, Any]:
|
def make_shell_context() -> Dict[str, Any]:
|
||||||
''' Adds variables to the shell context. '''
|
''' Adds variables to the shell context. '''
|
||||||
return {
|
return {
|
||||||
|
'db': db,
|
||||||
'Avatar': Avatar,
|
'Avatar': Avatar,
|
||||||
'Corpus': Corpus,
|
'Corpus': Corpus,
|
||||||
'CorpusFile': CorpusFile,
|
'CorpusFile': CorpusFile,
|
||||||
'CorpusFollowerAssociation': CorpusFollowerAssociation,
|
'CorpusFollowerAssociation': CorpusFollowerAssociation,
|
||||||
'db': db,
|
'CorpusFollowerRole': CorpusFollowerRole,
|
||||||
'Job': Job,
|
'Job': Job,
|
||||||
'JobInput': JobInput,
|
'JobInput': JobInput,
|
||||||
'JobResult': JobResult,
|
'JobResult': JobResult,
|
||||||
'Permission': Permission,
|
|
||||||
'Role': Role,
|
'Role': Role,
|
||||||
'TesseractOCRPipelineModel': TesseractOCRPipelineModel,
|
'TesseractOCRPipelineModel': TesseractOCRPipelineModel,
|
||||||
'SpaCyNLPPipelineModel': SpaCyNLPPipelineModel,
|
'SpaCyNLPPipelineModel': SpaCyNLPPipelineModel,
|
||||||
|
Loading…
Reference in New Issue
Block a user