From 7aba295e459b622f82aa769df54c47162dd42629 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 5 Nov 2020 03:57:55 +0100 Subject: [PATCH] Fixed members of Session for frontend usage --- flaschengeist/models/session.py | 5 +++ flaschengeist/plugins/schedule/__init__.py | 38 ++++++++++--------- .../plugins/schedule/event_controller.py | 4 +- flaschengeist/plugins/schedule/models.py | 2 +- flaschengeist/utils/datetime.py | 3 +- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/flaschengeist/models/session.py b/flaschengeist/models/session.py index 05da44c..df95b85 100644 --- a/flaschengeist/models/session.py +++ b/flaschengeist/models/session.py @@ -22,11 +22,16 @@ class Session(db.Model, ModelSerializeMixin): lifetime: int = db.Column(db.Integer) browser: str = db.Column(db.String(30)) platform: str = db.Column(db.String(30)) + userid: str = "" _id = db.Column("id", db.Integer, primary_key=True) _user: User = db.relationship("User", back_populates="_sessions") _user_id = db.Column("user_id", db.Integer, db.ForeignKey("user.id")) + @property + def userid(self): + return self._user.userid + def refresh(self): """Update the Timestamp diff --git a/flaschengeist/plugins/schedule/__init__.py b/flaschengeist/plugins/schedule/__init__.py index 4b2a4de..f0d27df 100644 --- a/flaschengeist/plugins/schedule/__init__.py +++ b/flaschengeist/plugins/schedule/__init__.py @@ -367,16 +367,16 @@ def update_event_slot(event_id, slot_id, current_session): def delete_event_slot(event_id, slot_id, current_session): """Delete an EventSlot - Route: ``/schedule/events//slots/`` | Method: ``DELETE`` + Route: ``/schedule/events//slots/`` | Method: ``DELETE`` - Args: - event_id: Identifier of the event - slot_id: Identifier of the slot - current_session: Session sent with Authorization Header + Args: + event_id: Identifier of the event + slot_id: Identifier of the slot + current_session: Session sent with Authorization Header - Returns: - JSON encoded Event object or HTTP-error - """ + Returns: + JSON encoded Event object or HTTP-error + """ event = event_controller.get_event(event_id) event_controller.remove_event_slot(event, slot_id) 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): """Delete a JobSlot - Route: ``/schedule/events//slots//jobs/`` | Method: ``DELETE`` + Route: ``/schedule/events//slots//jobs/`` | Method: ``DELETE`` - Args: - event_id: Identifier of the event - slot_id: Identifier of the EventSlot - job_type: Identifier of the JobSlot - current_session: Session sent with Authorization Header + Args: + event_id: Identifier of the event + slot_id: Identifier of the EventSlot + job_type: Identifier of the JobSlot + current_session: Session sent with Authorization Header - Returns: - JSON encoded Event object or HTTP-error - """ + Returns: + JSON encoded Event object or HTTP-error + """ event = event_controller.get_event(event_id) job_slot = event_controller.get_job_slot(slot_id, job_type) 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: user = userController.get_user(data["user"]["userid"]) 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 event_controller.assign_job(slot, user, value) except (KeyError, ValueError): diff --git a/flaschengeist/plugins/schedule/event_controller.py b/flaschengeist/plugins/schedule/event_controller.py index 8968049..b9f0775 100644 --- a/flaschengeist/plugins/schedule/event_controller.py +++ b/flaschengeist/plugins/schedule/event_controller.py @@ -157,7 +157,9 @@ def remove_event_slot(event, slot_id): 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: raise NotFound return jt diff --git a/flaschengeist/plugins/schedule/models.py b/flaschengeist/plugins/schedule/models.py index e015243..62cbaac 100644 --- a/flaschengeist/plugins/schedule/models.py +++ b/flaschengeist/plugins/schedule/models.py @@ -57,7 +57,7 @@ class JobSlot(db.Model, ModelSerializeMixin): 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"),) ########## diff --git a/flaschengeist/utils/datetime.py b/flaschengeist/utils/datetime.py index 7c50c41..dc62371 100644 --- a/flaschengeist/utils/datetime.py +++ b/flaschengeist/utils/datetime.py @@ -1,11 +1,12 @@ import datetime from backports.datetime_fromisoformat import MonkeyPatch + MonkeyPatch.patch_fromisoformat() def from_iso_format(date_str): """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: return time.astimezone(datetime.timezone.utc) return time.replace(tzinfo=datetime.timezone.utc)