From 8e293edbd30343779bbc5ea7fa967acb49c17911 Mon Sep 17 00:00:00 2001 From: Trey <73353716+TreyWW@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:54:44 +0100 Subject: [PATCH] fix: mypy type errors Signed-off-by: Trey <73353716+TreyWW@users.noreply.github.com> --- backend/api/base/modal.py | 11 ++++++----- backend/api/invoices/schedule.py | 3 +-- backend/api/teams/edit_permissions.py | 7 +++++-- backend/api/teams/switch_team.py | 4 +--- backend/service/defaults/get.py | 4 ++-- backend/service/teams/permissions.py | 3 +-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/api/base/modal.py b/backend/api/base/modal.py index 44aeff8b..0c0e09a4 100644 --- a/backend/api/base/modal.py +++ b/backend/api/base/modal.py @@ -153,11 +153,12 @@ def open_modal(request: WebRequest, modal_name, context_type=None, context_value if modal_name == "edit_team_member_permissions": team = request.user.logged_in_as_team - for_user = team.members.filter(id=context_value).first() - for_user_perms = team.permissions.filter(user=for_user).first() - if for_user: - context["editing_user"] = for_user - context["user_current_scopes"] = for_user_perms.scopes if for_user_perms else [] + if team: + for_user = team.members.filter(id=context_value).first() + for_user_perms = team.permissions.filter(user=for_user).first() + if for_user: + context["editing_user"] = for_user + context["user_current_scopes"] = for_user_perms.scopes if for_user_perms else [] return render(request, template_name, context) except ValueError as e: diff --git a/backend/api/invoices/schedule.py b/backend/api/invoices/schedule.py index 80ff3bbb..3643348a 100644 --- a/backend/api/invoices/schedule.py +++ b/backend/api/invoices/schedule.py @@ -80,8 +80,7 @@ def create_ots(request: HtmxHttpRequest) -> HttpResponse: invoice=invoice, option=1, datetime=request.POST.get("date_time"), - email_type=request.POST.get("email_type"), - # type: ignore[arg-type] + email_type=request.POST.get("email_type"), # type: ignore[arg-type] ) ) diff --git a/backend/api/teams/edit_permissions.py b/backend/api/teams/edit_permissions.py index ed482b06..d7cf2e84 100644 --- a/backend/api/teams/edit_permissions.py +++ b/backend/api/teams/edit_permissions.py @@ -21,9 +21,12 @@ def edit_user_permissions_endpoint(request: WebRequest) -> HttpResponse: permissions: list = get_permissions_from_request(request) user_id = request.POST.get("user_id") - receiver = User.objects.filter(id=user_id).first() + receiver: User | None = User.objects.filter(id=user_id).first() - error = edit_member_permissions(request, request.user, receiver, request.user.logged_in_as_team, permissions) + if receiver: + error = edit_member_permissions(request, request.user, receiver, request.user.logged_in_as_team, permissions) + else: + error = "Something went wrong" if error: messages.error(request, error) diff --git a/backend/api/teams/switch_team.py b/backend/api/teams/switch_team.py index 446022f2..c3b94dad 100644 --- a/backend/api/teams/switch_team.py +++ b/backend/api/teams/switch_team.py @@ -1,5 +1,4 @@ from django.contrib import messages -from django.contrib.auth.models import AnonymousUser from django.http import HttpResponse from django.shortcuts import render @@ -7,8 +6,7 @@ from backend.types.htmx import HtmxHttpRequest -def switch_team(request: HtmxHttpRequest, team_id=None): - team_id: str | int | None +def switch_team(request: HtmxHttpRequest, team_id: str | int | None = None): if not team_id: team_id = request.POST.get("join_team", None) diff --git a/backend/service/defaults/get.py b/backend/service/defaults/get.py index e1d1ed58..fe51bb7a 100644 --- a/backend/service/defaults/get.py +++ b/backend/service/defaults/get.py @@ -4,8 +4,8 @@ def get_account_defaults(request: WebRequest, client: Client | None = None) -> DefaultValues: if not client: - account_defaults: DefaultValues + account_defaults: DefaultValues | None if not (account_defaults := DefaultValues.filter_by_owner(owner=request.actor).filter(client__isnull=True).first()): - account_defaults = DefaultValues.objects.create(owner=request.actor, client=None) + account_defaults = DefaultValues.objects.create(owner=request.actor, client=None) # type: ignore[misc] return account_defaults return DefaultValues.filter_by_owner(owner=request.actor).get(client=client) diff --git a/backend/service/teams/permissions.py b/backend/service/teams/permissions.py index ff0d4bd7..14e5acbd 100644 --- a/backend/service/teams/permissions.py +++ b/backend/service/teams/permissions.py @@ -10,12 +10,11 @@ def edit_member_permissions(request, actor: User | Organization, receiver: User, if not validate_scopes(permissions): return "Invalid permissions" - user_team_perms = team.permissions.filter(user=receiver).first() + user_team_perms: TeamMemberPermission | None = team.permissions.filter(user=receiver).first() if not user_team_perms: team.permissions.add(TeamMemberPermission.objects.create(user=receiver, team=team, scopes=permissions)) else: - user_team_perms: TeamMemberPermission user_team_perms.scopes = permissions user_team_perms.save()