Skip to content

Commit

Permalink
[FIX] Character Information Error Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Geuthur committed Jan 24, 2025
1 parent 6521229 commit c860ece
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 11 additions & 7 deletions ledger/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ def convert_corp_tax(ess: int) -> float:
return (ess / app_settings.LEDGER_CORP_TAX) * (100 - app_settings.LEDGER_CORP_TAX)


def get_character(request, character_id) -> tuple[bool, EveCharacter]:
def get_character(request, character_id, corp=False) -> tuple[bool, EveCharacter]:
"""Get Character and check permissions"""
perms = True
if character_id == 0:
character_id = request.user.profile.main_character.character_id

try:
main_char = EveCharacter.objects.get(character_id=character_id)
# Corporation Tempalte
if corp:
main_char = EveCharacter.objects.select_related(
"character_ownership",
"character_ownership__user__profile",
"character_ownership__user__profile__main_character",
).get(character_id=request.user.profile.main_character.character_id)
else:
main_char = EveCharacter.objects.get(character_id=character_id)
except ObjectDoesNotExist:
main_char = EveCharacter.objects.select_related(
"character_ownership",
"character_ownership__user__profile",
"character_ownership__user__profile__main_character",
).get(character_id=request.user.profile.main_character.character_id)
return False, None

# check access
visible = models.CharacterAudit.objects.visible_eve_characters(request.user)
Expand Down
15 changes: 14 additions & 1 deletion ledger/api/ledger/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def get_ledger_corp_ally_details_information(
corp: bool = False,
):
perm, entitys = ledger_api_process(request, entity_type, entity_id)
corp_template = False

if not perm:
context = {
Expand All @@ -138,7 +139,19 @@ def get_ledger_corp_ally_details_information(

current_date = timezone.now()

_, char = get_character(request, main_id)
if entity_id == main_id:
corp_template = True

_, char = get_character(request, main_id, corp=corp_template)

if char is None:
context = {
"error_title": "403 Error",
"error_message": "Character not found.",
}
return render(
request, "ledger/modals/information/error.html", context, status=403
)

# Get all Chars from the main (including the main char itself)
alts = get_alts_queryset(char, corporations=entitys)
Expand Down

0 comments on commit c860ece

Please sign in to comment.