fix playlist file model
This commit is contained in:
parent
f913b6aadc
commit
db5c94615e
@ -43,7 +43,7 @@ class AuthAbl:
|
|||||||
return jsonify(message="Incorrect credentials"), 401
|
return jsonify(message="Incorrect credentials"), 401
|
||||||
|
|
||||||
login_user(user)
|
login_user(user)
|
||||||
return jsonify(success=True)
|
return jsonify(user.as_dict())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def profile():
|
def profile():
|
||||||
|
@ -28,8 +28,11 @@ class PlaylistAbl:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_playlist(playlist_id):
|
def get_playlist(playlist_id):
|
||||||
(query, files) = PlaylistDao.get_playlist(playlist_id)
|
print("get")
|
||||||
return jsonify({'id': query.id, 'name': query.name, 'files': files})
|
#(query, files) = PlaylistDao.get_playlist(playlist_id)
|
||||||
|
print(query)
|
||||||
|
#return jsonify({'id': query.id, 'name': query.name, 'files': files})
|
||||||
|
return jsonify(success=True)
|
||||||
|
|
||||||
# EDIT PLAYLIST CONTENT
|
# EDIT PLAYLIST CONTENT
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -22,4 +22,3 @@ def logout():
|
|||||||
@login_required
|
@login_required
|
||||||
def profile():
|
def profile():
|
||||||
return AuthAbl.profile()
|
return AuthAbl.profile()
|
||||||
|
|
||||||
|
@ -3,9 +3,13 @@ from ..models import Playlist, PlaylistFile, File
|
|||||||
|
|
||||||
class PlaylistDao:
|
class PlaylistDao:
|
||||||
def get_playlist(playlist_id):
|
def get_playlist(playlist_id):
|
||||||
|
print(playlist_id)
|
||||||
|
print("ok")
|
||||||
query = db.session.query(Playlist).filter(Playlist.id == playlist_id).first()
|
query = db.session.query(Playlist).filter(Playlist.id == playlist_id).first()
|
||||||
|
print("ok")
|
||||||
|
print(query.files)
|
||||||
files = []
|
files = []
|
||||||
for playlist_file in query.playlist_files:
|
for playlist_file in query.files:
|
||||||
file = playlist_file.file.as_dict()
|
file = playlist_file.file.as_dict()
|
||||||
file['position'] = playlist_file.position
|
file['position'] = playlist_file.position
|
||||||
file['seconds'] = playlist_file.seconds
|
file['seconds'] = playlist_file.seconds
|
||||||
|
@ -8,14 +8,12 @@ class PlaylistFile(db.Model):
|
|||||||
file_id = db.Column(db.Integer, db.ForeignKey('file.id'), primary_key=True)
|
file_id = db.Column(db.Integer, db.ForeignKey('file.id'), primary_key=True)
|
||||||
position = db.Column(db.Integer)
|
position = db.Column(db.Integer)
|
||||||
seconds = db.Column(db.Integer, default=10)
|
seconds = db.Column(db.Integer, default=10)
|
||||||
playlist = db.relationship('Playlist', back_populates='playlist_files')
|
|
||||||
file = db.relationship('File', back_populates='playlist_files')
|
|
||||||
|
|
||||||
class File(db.Model):
|
class File(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key = True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key = True, autoincrement=True)
|
||||||
name = db.Column(db.String(150))
|
name = db.Column(db.String(150))
|
||||||
type = db.Column(db.String(255)) # maximum length of mimetype
|
type = db.Column(db.String(255)) # maximum length of mimetype
|
||||||
playlist_files = db.relationship('PlaylistFile', back_populates='file')
|
playlists = db.relationship('Playlist', secondary='PlaylistFile', back_populates='files')
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||||
@ -28,8 +26,7 @@ class Playlist(db.Model):
|
|||||||
read_permissions = db.Column(db.Integer, default=0)
|
read_permissions = db.Column(db.Integer, default=0)
|
||||||
write_permissions = db.Column(db.Integer, default=0)
|
write_permissions = db.Column(db.Integer, default=0)
|
||||||
execute_permissions = db.Column(db.Integer, default=0)
|
execute_permissions = db.Column(db.Integer, default=0)
|
||||||
files = db.relationship('File', secondary='PlaylistFile')
|
files = db.relationship('File', secondary='PlaylistFile', back_populates='playlists')
|
||||||
playlist_files = db.relationship('PlaylistFile', order_by='PlaylistFile.position', back_populates='playlist')
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||||
|
@ -14,9 +14,11 @@ class permissions:
|
|||||||
def decorator_require_permissions(func):
|
def decorator_require_permissions(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper_require_permissions(*args, **kwargs):
|
def wrapper_require_permissions(*args, **kwargs):
|
||||||
|
print("wrapper permissions")
|
||||||
for perm in permissions:
|
for perm in permissions:
|
||||||
check_perm = CheckPermissionFactory(perm)
|
check_perm = CheckPermissionFactory(perm)
|
||||||
if not check_perm.is_valid():
|
print(args, kwargs)
|
||||||
|
if not check_perm.is_valid(kwargs):
|
||||||
return jsonify( \
|
return jsonify( \
|
||||||
message=check_perm.message), \
|
message=check_perm.message), \
|
||||||
check_perm.status_code
|
check_perm.status_code
|
||||||
@ -33,7 +35,6 @@ def CheckPermissionFactory(perm):
|
|||||||
case Perm.CREATE_ROLE:
|
case Perm.CREATE_ROLE:
|
||||||
return CheckCreateRole()
|
return CheckCreateRole()
|
||||||
case Perm.CREATE_PLAYLIST:
|
case Perm.CREATE_PLAYLIST:
|
||||||
print("creat plays")
|
|
||||||
return CheckCreatePlaylist()
|
return CheckCreatePlaylist()
|
||||||
case Perm.VIEW_PLAYLIST:
|
case Perm.VIEW_PLAYLIST:
|
||||||
return CheckViewPlaylist()
|
return CheckViewPlaylist()
|
||||||
@ -44,28 +45,49 @@ def CheckPermissionFactory(perm):
|
|||||||
case _:
|
case _:
|
||||||
return CheckNone()
|
return CheckNone()
|
||||||
|
|
||||||
|
def get_playlist_id(args):
|
||||||
|
if 'playlist_id' in args:
|
||||||
|
return args['playlist_id']
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class CheckNone:
|
class CheckNone:
|
||||||
def is_valid(self):
|
def is_valid(self, args):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class CheckOwnPlaylist:
|
class CheckOwnPlaylist:
|
||||||
def is_valid(self, playlist_id):
|
def __init__(self):
|
||||||
query = db.session.query(Playlist).filter(Playlist.id == playlist_id).first()
|
|
||||||
self.message = "You don't own this playlist"
|
self.message = "You don't own this playlist"
|
||||||
self.status_code = 403
|
self.status_code = 403
|
||||||
|
|
||||||
|
def is_valid(self, args):
|
||||||
|
playlist_id = get_playlist_id(args)
|
||||||
|
query = db.session.query(Playlist).filter(Playlist.id == playlist_id).first()
|
||||||
|
if query is None:
|
||||||
|
self.message = "This playlist doesn't exist"
|
||||||
|
self.status_code = 404
|
||||||
|
return False
|
||||||
return query['owner_id'] == current_user.as_dict()['id']
|
return query['owner_id'] == current_user.as_dict()['id']
|
||||||
|
|
||||||
class CheckViewPlaylist:
|
class CheckViewPlaylist:
|
||||||
def is_valid(self, playlist_id):
|
def __init__(self):
|
||||||
if CheckOwnPlaylist().is_valid(playlist_id):
|
|
||||||
return True
|
|
||||||
self.message = "You don't have the permission to view this playlist"
|
self.message = "You don't have the permission to view this playlist"
|
||||||
self.status_code = 403
|
self.status_code = 403
|
||||||
|
|
||||||
|
def is_valid(self, args):
|
||||||
|
check_own = CheckOwnPlaylist()
|
||||||
|
if check_own.is_valid(args):
|
||||||
|
return True
|
||||||
|
elif check_own.status_code == 404:
|
||||||
|
self.message = "This playlist doesn't exist"
|
||||||
|
self.status_code = 404
|
||||||
|
return False
|
||||||
|
|
||||||
|
# todo check view
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class CheckEditPlaylist:
|
class CheckEditPlaylist:
|
||||||
def is_valid(self, playlist_id):
|
def is_valid(self, args):
|
||||||
if CheckOwnPlaylist().is_valid(playlist_id):
|
if CheckOwnPlaylist().is_valid(playlist_id):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user