Fixed members of Session for frontend usage

This commit is contained in:
Ferdinand Thiessen 2020-11-05 03:57:55 +01:00
parent 03aefbb35a
commit 7aba295e45
5 changed files with 31 additions and 21 deletions

View File

@ -22,11 +22,16 @@ class Session(db.Model, ModelSerializeMixin):
lifetime: int = db.Column(db.Integer) lifetime: int = db.Column(db.Integer)
browser: str = db.Column(db.String(30)) browser: str = db.Column(db.String(30))
platform: str = db.Column(db.String(30)) platform: str = db.Column(db.String(30))
userid: str = ""
_id = db.Column("id", db.Integer, primary_key=True) _id = db.Column("id", db.Integer, primary_key=True)
_user: User = db.relationship("User", back_populates="_sessions") _user: User = db.relationship("User", back_populates="_sessions")
_user_id = db.Column("user_id", db.Integer, db.ForeignKey("user.id")) _user_id = db.Column("user_id", db.Integer, db.ForeignKey("user.id"))
@property
def userid(self):
return self._user.userid
def refresh(self): def refresh(self):
"""Update the Timestamp """Update the Timestamp

View File

@ -367,16 +367,16 @@ def update_event_slot(event_id, slot_id, current_session):
def delete_event_slot(event_id, slot_id, current_session): def delete_event_slot(event_id, slot_id, current_session):
"""Delete an EventSlot """Delete an EventSlot
Route: ``/schedule/events/<event_id>/slots/<slot_id>`` | Method: ``DELETE`` Route: ``/schedule/events/<event_id>/slots/<slot_id>`` | Method: ``DELETE``
Args: Args:
event_id: Identifier of the event event_id: Identifier of the event
slot_id: Identifier of the slot slot_id: Identifier of the slot
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
Returns: Returns:
JSON encoded Event object or HTTP-error JSON encoded Event object or HTTP-error
""" """
event = event_controller.get_event(event_id) event = event_controller.get_event(event_id)
event_controller.remove_event_slot(event, slot_id) event_controller.remove_event_slot(event, slot_id)
return jsonify(event) return jsonify(event)
@ -420,17 +420,17 @@ def add_job_slot(event_id, slot_id, current_session):
def delete_job_slot(event_id, slot_id, job_type, current_session): def delete_job_slot(event_id, slot_id, job_type, current_session):
"""Delete a JobSlot """Delete a JobSlot
Route: ``/schedule/events/<event_id>/slots/<slot_id>/jobs/<job_type>`` | Method: ``DELETE`` Route: ``/schedule/events/<event_id>/slots/<slot_id>/jobs/<job_type>`` | Method: ``DELETE``
Args: Args:
event_id: Identifier of the event event_id: Identifier of the event
slot_id: Identifier of the EventSlot slot_id: Identifier of the EventSlot
job_type: Identifier of the JobSlot job_type: Identifier of the JobSlot
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
Returns: Returns:
JSON encoded Event object or HTTP-error JSON encoded Event object or HTTP-error
""" """
event = event_controller.get_event(event_id) event = event_controller.get_event(event_id)
job_slot = event_controller.get_job_slot(slot_id, job_type) job_slot = event_controller.get_job_slot(slot_id, job_type)
event_controller.delete_job_slot(job_slot) event_controller.delete_job_slot(job_slot)
@ -469,7 +469,9 @@ def update_job_slot(event_id, slot_id, job_type, current_session: Session):
try: try:
user = userController.get_user(data["user"]["userid"]) user = userController.get_user(data["user"]["userid"])
value = data["user"]["value"] value = data["user"]["value"]
if (user == current_session._user and not user.has_permission(permissions.ASSIGN)) or (user != current_session._user and not current_session._user.has_permission(permissions.ASSIGN_OTHER)): if (user == current_session._user and not user.has_permission(permissions.ASSIGN)) or (
user != current_session._user and not current_session._user.has_permission(permissions.ASSIGN_OTHER)
):
raise Forbidden raise Forbidden
event_controller.assign_job(slot, user, value) event_controller.assign_job(slot, user, value)
except (KeyError, ValueError): except (KeyError, ValueError):

View File

@ -157,7 +157,9 @@ def remove_event_slot(event, slot_id):
def get_job_slot(event_slot_id, job_type): def get_job_slot(event_slot_id, job_type):
jt = JobSlot.query.filter(JobSlot._type_id == job_type).filter(JobSlot._event_slot_id == event_slot_id).one_or_none() jt = (
JobSlot.query.filter(JobSlot._type_id == job_type).filter(JobSlot._event_slot_id == event_slot_id).one_or_none()
)
if jt is None: if jt is None:
raise NotFound raise NotFound
return jt return jt

View File

@ -57,7 +57,7 @@ class JobSlot(db.Model, ModelSerializeMixin):
event_slot_ = db.relationship("EventSlot", back_populates="jobs") event_slot_ = db.relationship("EventSlot", back_populates="jobs")
__table_args__ = (UniqueConstraint('type_id', 'event_slot_id', name='_type_event_slot_uc'),) __table_args__ = (UniqueConstraint("type_id", "event_slot_id", name="_type_event_slot_uc"),)
########## ##########

View File

@ -1,11 +1,12 @@
import datetime import datetime
from backports.datetime_fromisoformat import MonkeyPatch from backports.datetime_fromisoformat import MonkeyPatch
MonkeyPatch.patch_fromisoformat() MonkeyPatch.patch_fromisoformat()
def from_iso_format(date_str): def from_iso_format(date_str):
"""Z-suffix aware version of `datetime.datetime.fromisoformat`""" """Z-suffix aware version of `datetime.datetime.fromisoformat`"""
time = datetime.datetime.fromisoformat(date_str.replace('Z', '+00:00')) time = datetime.datetime.fromisoformat(date_str.replace("Z", "+00:00"))
if time.tzinfo: if time.tzinfo:
return time.astimezone(datetime.timezone.utc) return time.astimezone(datetime.timezone.utc)
return time.replace(tzinfo=datetime.timezone.utc) return time.replace(tzinfo=datetime.timezone.utc)