Skip to content

Commit

Permalink
refactor: add types on endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Mar 27, 2024
1 parent 5149a45 commit dda100a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
9 changes: 5 additions & 4 deletions web/b3desk/endpoints/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from b3desk.models.meetings import get_mail_meeting
from b3desk.models.meetings import get_meeting_from_meeting_id_and_user_id
from b3desk.models.roles import Role
from b3desk.models.users import User

from .. import auth
from ..session import get_authenticated_attendee_fullname
Expand Down Expand Up @@ -66,7 +67,7 @@ def signin_mail_meeting(meeting_fake_id, expiration, h):


@bp.route("/meeting/signin/<meeting_fake_id>/creator/<user:creator>/hash/<h>")
def signin_meeting(meeting_fake_id, creator, h):
def signin_meeting(meeting_fake_id, creator: User, h):
meeting = get_meeting_from_meeting_id_and_user_id(meeting_fake_id, creator.id)
wordings = current_app.config["WORDINGS"]
if meeting is None:
Expand Down Expand Up @@ -101,7 +102,7 @@ def signin_meeting(meeting_fake_id, creator, h):

@bp.route("/meeting/auth/<meeting_fake_id>/creator/<user:creator>/hash/<h>")
@auth.oidc_auth("default")
def authenticate_then_signin_meeting(meeting_fake_id, creator, h):
def authenticate_then_signin_meeting(meeting_fake_id, creator: User, h):
return redirect(
url_for(
"join.signin_meeting",
Expand All @@ -124,7 +125,7 @@ def authenticate_then_signin_meeting(meeting_fake_id, creator, h):
@bp.route(
"/meeting/wait/<meeting_fake_id>/creator/<user:creator>/hash/<h>/fullname/<path:fullname>/fullname_suffix/<path:fullname_suffix>",
)
def waiting_meeting(meeting_fake_id, creator, h, fullname="", fullname_suffix=""):
def waiting_meeting(meeting_fake_id, creator: User, h, fullname="", fullname_suffix=""):
meeting = get_meeting_from_meeting_id_and_user_id(meeting_fake_id, creator.id)
if meeting is None:
return redirect(url_for("public.index"))
Expand Down Expand Up @@ -235,5 +236,5 @@ def join_meeting_as_authenticated(meeting_id):
@bp.route("/meeting/join/<meeting:meeting>/<role:role>")
@auth.oidc_auth("default")
@meeting_owner_needed
def join_meeting_as_role(meeting, role: Role, owner):
def join_meeting_as_role(meeting: Meeting, role: Role, owner: User):
return redirect(meeting.get_join_url(role, owner.fullname, create=True))
15 changes: 8 additions & 7 deletions web/b3desk/endpoints/meeting_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from b3desk.models.meetings import Meeting
from b3desk.models.meetings import MeetingFiles
from b3desk.models.meetings import MeetingFilesExternal
from b3desk.models.users import User

from .. import auth
from ..session import get_current_user
Expand All @@ -41,7 +42,7 @@
@bp.route("/meeting/files/<meeting:meeting>")
@auth.oidc_auth("default")
@meeting_owner_needed
def edit_meeting_files(meeting, owner):
def edit_meeting_files(meeting: Meeting, owner: User):
form = MeetingFilesForm()

if not current_app.config["FILE_SHARING"]:
Expand Down Expand Up @@ -75,7 +76,7 @@ def edit_meeting_files(meeting, owner):
@bp.route("/meeting/files/<meeting:meeting>", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def add_meeting_files(meeting, owner):
def add_meeting_files(meeting: Meeting, owner: User):
data = request.get_json()
is_default = False
if len(meeting.files) == 0:
Expand All @@ -101,7 +102,7 @@ def add_meeting_files(meeting, owner):
@bp.route("/meeting/files/<meeting:meeting>/<int:file_id>")
@auth.oidc_auth("default")
@meeting_owner_needed
def download_meeting_files(meeting, owner, file_id=None):
def download_meeting_files(meeting: Meeting, owner: User, file_id=None):
TMP_DOWNLOAD_DIR = current_app.config["TMP_DOWNLOAD_DIR"]
Path(TMP_DOWNLOAD_DIR).mkdir(parents=True, exist_ok=True)
tmp_name = f'{current_app.config["TMP_DOWNLOAD_DIR"]}{secrets.token_urlsafe(32)}'
Expand Down Expand Up @@ -153,7 +154,7 @@ def download_meeting_files(meeting, owner, file_id=None):
# called by NextcloudfilePicker when documents should be added to a running room:
@bp.route("/meeting/files/<meeting:meeting>/insertDocuments", methods=["POST"])
@auth.oidc_auth("default")
def insertDocuments(meeting):
def insertDocuments(meeting: Meeting):
from flask import request

files_title = request.get_json()
Expand Down Expand Up @@ -206,7 +207,7 @@ def insertDocuments(meeting):
@bp.route("/meeting/files/<meeting:meeting>/toggledownload", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def toggledownload(meeting, owner):
def toggledownload(meeting: Meeting, owner: User):
data = request.get_json()
meeting_file = db.session.get(MeetingFiles, data["id"])
if not meeting_file:
Expand All @@ -221,7 +222,7 @@ def toggledownload(meeting, owner):
@bp.route("/meeting/files/<meeting:meeting>/default", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def set_meeting_default_file(meeting, owner):
def set_meeting_default_file(meeting: Meeting, owner: User):
data = request.get_json()

actual_default_file = meeting.default_file
Expand Down Expand Up @@ -429,7 +430,7 @@ def add_external_meeting_file_nextcloud(path, meeting_id):
@bp.route("/meeting/files/<meeting:meeting>/dropzone", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def add_dropzone_files(meeting, owner):
def add_dropzone_files(meeting: Meeting, owner: User):
file = request.files["dropzoneFiles"]
# for dropzone chunk file by file validation
# shamelessly taken from https://stackoverflow.com/questions/44727052/handling-large-file-uploads-with-flask
Expand Down
14 changes: 7 additions & 7 deletions web/b3desk/endpoints/meetings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
bp = Blueprint("meetings", __name__)


def meeting_mailto_params(meeting, role: Role):
def meeting_mailto_params(meeting: Meeting, role: Role):
if role == Role.moderator:
return render_template(
"meeting/mailto/mail_href.txt", meeting=meeting, role=role
Expand Down Expand Up @@ -90,7 +90,7 @@ def quick_meeting():
@bp.route("/meeting/show/<meeting:meeting>")
@auth.oidc_auth("default")
@meeting_owner_needed
def show_meeting(meeting, owner):
def show_meeting(meeting: Meeting, owner: User):
# TODO: appears unused

form = ShowMeetingForm(data={"meeting_id": meeting.id})
Expand All @@ -111,7 +111,7 @@ def show_meeting(meeting, owner):
@bp.route("/meeting/recordings/<meeting:meeting>")
@auth.oidc_auth("default")
@meeting_owner_needed
def show_meeting_recording(meeting, owner):
def show_meeting_recording(meeting: Meeting, owner: User):
form = RecordingForm()
return render_template(
"meeting/recordings.html",
Expand All @@ -124,7 +124,7 @@ def show_meeting_recording(meeting, owner):
@bp.route("/meeting/<meeting:meeting>/recordings/<recording_id>", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def update_recording_name(meeting, recording_id, owner):
def update_recording_name(meeting: Meeting, recording_id, owner: User):
form = RecordingForm(request.form)
if not form.validate():
abort(403)
Expand Down Expand Up @@ -164,7 +164,7 @@ def new_meeting():
@bp.route("/meeting/edit/<meeting:meeting>")
@auth.oidc_auth("default")
@meeting_owner_needed
def edit_meeting(meeting, owner):
def edit_meeting(meeting: Meeting, owner: User):
form = (
MeetingWithRecordForm(obj=meeting)
if current_app.config["RECORDING"]
Expand Down Expand Up @@ -250,7 +250,7 @@ def end_meeting():
@bp.route("/meeting/create/<meeting:meeting>")
@auth.oidc_auth("default")
@meeting_owner_needed
def create_meeting(meeting, owner):
def create_meeting(meeting: Meeting, owner: User):
meeting.create_bbb()
meeting.save()
return redirect(url_for("public.welcome"))
Expand All @@ -259,7 +259,7 @@ def create_meeting(meeting, owner):
@bp.route("/meeting/<meeting:meeting>/externalUpload")
@auth.oidc_auth("default")
@meeting_owner_needed
def externalUpload(meeting, owner):
def externalUpload(meeting: Meeting, owner: User):
if meeting.is_running():
return render_template("meeting/externalUpload.html", meeting=meeting)
return redirect(url_for("public.welcome"))
Expand Down

0 comments on commit dda100a

Please sign in to comment.