mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
Use HashidMixin from flask_hashids
This commit is contained in:
parent
37c244b30c
commit
82543d883f
@ -1,21 +1,26 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
|
from flask_hashids import HashidMixin
|
||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
|
from itsdangerous import BadSignature, TimedJSONWebSignatureSerializer
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from . import db, hashids, login
|
from . import db, login
|
||||||
import base64
|
import base64
|
||||||
import enum
|
import enum
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
class HashidMixin:
|
class Permission(enum.IntEnum):
|
||||||
@property
|
'''
|
||||||
def hashid(self):
|
Defines User permissions as integers by the power of 2. User permission
|
||||||
return hashids.encode(self.id)
|
can be evaluated using the bitwise operator &.
|
||||||
|
'''
|
||||||
|
ADMINISTRATE = 4
|
||||||
|
CONTRIBUTE = 2
|
||||||
|
USE_API = 1
|
||||||
|
|
||||||
|
|
||||||
class FileMixin:
|
class FileMixin:
|
||||||
@ -33,16 +38,6 @@ class FileMixin:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Permission(enum.IntEnum):
|
|
||||||
'''
|
|
||||||
Defines User permissions as integers by the power of 2. User permission
|
|
||||||
can be evaluated using the bitwise operator &.
|
|
||||||
'''
|
|
||||||
ADMINISTRATE = 4
|
|
||||||
CONTRIBUTE = 2
|
|
||||||
USE_API = 1
|
|
||||||
|
|
||||||
|
|
||||||
class Role(HashidMixin, db.Model):
|
class Role(HashidMixin, db.Model):
|
||||||
__tablename__ = 'roles'
|
__tablename__ = 'roles'
|
||||||
# Primary key
|
# Primary key
|
||||||
@ -578,7 +573,7 @@ class CorpusFile(FileMixin, HashidMixin, db.Model):
|
|||||||
os.remove(self.path)
|
os.remove(self.path)
|
||||||
except OSError:
|
except OSError:
|
||||||
current_app.logger.error(
|
current_app.logger.error(
|
||||||
'Removing {} led to an OSError!'.format(self.path)
|
f'Removing {self.path} led to an OSError!'
|
||||||
)
|
)
|
||||||
pass
|
pass
|
||||||
db.session.delete(self)
|
db.session.delete(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user