Skip to content

Commit

Permalink
fix: mypy type errors
Browse files Browse the repository at this point in the history
Signed-off-by: Trey <[email protected]>
  • Loading branch information
TreyWW committed Jul 22, 2024
1 parent 0f434ac commit 8e293ed
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
11 changes: 6 additions & 5 deletions backend/api/base/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions backend/api/invoices/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
)

Expand Down
7 changes: 5 additions & 2 deletions backend/api/teams/edit_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions backend/api/teams/switch_team.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from django.contrib import messages
from django.contrib.auth.models import AnonymousUser
from django.http import HttpResponse
from django.shortcuts import render

from backend.models import Organization
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)
Expand Down
4 changes: 2 additions & 2 deletions backend/service/defaults/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions backend/service/teams/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 8e293ed

Please sign in to comment.