Skip to content

Commit

Permalink
Merge pull request #74 from mome-borogove/fix-reject
Browse files Browse the repository at this point in the history
Fix crash on rejecting orphans
  • Loading branch information
Deadevilgrounds authored Oct 10, 2024
2 parents 4a96558 + 0a84a3a commit 68a5b44
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 63 deletions.
4 changes: 2 additions & 2 deletions whctools/templates/whctools/list_acl_members.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ <h3 class="panel-title">Members of the "{{ acl_name }}" ACL</h3>
<td>{{character.corp}}</td>
<td>{{character.alliance}}</td>
{% if character.is_main %}
<td><a href="/whctools/staff/action/{{character.id}}/reject/removed/{{reject_timers.large_reject}}/acl" class="whcbutton btn btn-danger" role="button" id="kick-all">Kick All</a></td>
<td><a href="/whctools/staff/action/{{character.char_id}}/reject/removed/{{reject_timers.large_reject}}/acl" class="whcbutton btn btn-danger" role="button" id="kick-all">Kick All</a></td>
{% else %}
<td><a href="/whctools/staff/action/{{character.id}}/reject/other/{{reject_timers.medium_reject}}/acl" class="whcbutton btn btn-warning" role="button" id="remove-alt">Remove Alt</a></td>
<td><a href="/whctools/staff/action/{{character.char_id}}/reject/other/{{reject_timers.medium_reject}}/acl" class="whcbutton btn btn-warning" role="button" id="remove-alt">Remove Alt</a></td>
{% endif %}
</tr>
{% endfor %}
Expand Down
8 changes: 4 additions & 4 deletions whctools/templates/whctools/staff/staff_apps_in_progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
{% if char.is_main_char and not char.ma_is_valid %}
<div class="whctools-error"><i class="fa fas fa-exclamation-triangle"></i> Failed to fetch skills from Member Audit.<br>Refresh page or ask player to re-register if it persists.</div>
{% else %}
<button class="whcbutton btn btn-primary openSkillcheckPopup" data-character-id="{{ char.application.eve_character_id }}">Check Skills</button>
<button class="whcbutton btn btn-primary openSkillcheckPopup" data-character-id="{{ char.application.eve_character.character_id }}">Check Skills</button>
{% endif %}
</td>
<td>
<select class="acl-dropdown" data-character-id="{{ char.application.eve_character.id }}">
<select class="acl-dropdown" data-character-id="{{ char.application.eve_character.character_id }}">
{% for acl in existing_acls %}
<option value="{{ acl.name }}">{{ acl.name }}</option>
{% endfor %}
</select>
<button class="whcbutton btn btn-primary accept-button" role="button">Accept</button>
<a href="/whctools/staff/action/{{ char.application.eve_character.id }}/reject/skills/{{ reject_timers.short_reject }}" class="whcbutton btn btn-warning" role="button">Reject: Skills</a>
<a href="/whctools/staff/action/{{ char.application.eve_character.id }}/reject/other/{{ reject_timers.medium_reject }}" class="whcbutton btn btn-danger" role="button">Reject: Other</a>
<a href="/whctools/staff/action/{{ char.application.eve_character.character_id }}/reject/skills/{{ reject_timers.short_reject }}" class="whcbutton btn btn-warning" role="button">Reject: Skills</a>
<a href="/whctools/staff/action/{{ char.application.eve_character.character_id }}/reject/other/{{ reject_timers.medium_reject }}" class="whcbutton btn btn-danger" role="button">Reject: Other</a>
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion whctools/templates/whctools/staff/staff_rejected_apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div>{{char.get_reject_reason_display}}</div>
</td>
<td>
<a href="/whctools/staff/action/{{char.eve_character.id}}/reset" class="whcbutton btn btn-danger" role="button">Reset</a>
<a href="/whctools/staff/action/{{char.eve_character.character_id}}/reset" class="whcbutton btn btn-danger" role="button">Reset</a>
</td>
</tr>
{% endfor %}
Expand Down
111 changes: 56 additions & 55 deletions whctools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def withdraw(request, char_id, acl_name="WHC"):
def accept(request, char_id, acl_name="WHC"):

whcapplication = Applications.objects.filter(
eve_character_id=char_id
eve_character__character_id=char_id
).select_related("eve_character")

if whcapplication:
Expand Down Expand Up @@ -257,79 +257,80 @@ def reject(request, char_id, reason, days, source="staff", acl_name="WHC"):
redirect_target = redirect("/whctools/staff/open")

whcapplication = Applications.objects.filter(eve_character__character_id=char_id)

if whcapplication.exists():
logger.debug(whcapplication)
else:
if not whcapplication.exists():
logger.error(f"Cannot find character {char_id} to delete.")
return redirect_target

if whcapplication: # @@@ move this into template
member_application = whcapplication[0]
old_state = member_application.member_state
notify_subject = "Application Denied"

# Removed should only be triggered by the removal by staff directly after a membership is allready accepted
if reason == "removed":
# If a WHC character is forcefully removed, remove all alts as well.
logger.debug(
f"Removing {member_application.eve_character.character_name} and all their alts from {acl_name}"
)
rejection_reason = Applications.RejectionStates.REMOVED
notify_subject = "Membership Revoked"
notification_names = remove_all_alts(
acl_name,
member_application,
Applications.MembershipStates.REJECTED,
rejection_reason,
days,
)
# @@@ move this into template?
member_application = whcapplication[0]
old_state = member_application.member_state
notify_subject = "Application Denied"

else:
# Other can be used for individual removal of alts that need cleaning up.
# note: currently only used on the reject an open application - additional @@@ TODO to hook up to the remove membership page
logger.debug(
f"Singleton removal of {member_application.eve_character.character_name}"
)
# Removed should only be triggered by the removal by staff directly after a membership is allready accepted
if reason == "removed":
# If a WHC character is forcefully removed, remove all alts as well.
logger.debug(
f"Removing {member_application.eve_character.character_name} and all their alts from {acl_name}"
)
rejection_reason = Applications.RejectionStates.REMOVED
notify_subject = "Membership Revoked"
notification_names = remove_all_alts(
acl_name,
member_application,
Applications.MembershipStates.REJECTED,
rejection_reason,
days,
)

rejection_reason = (
Applications.RejectionStates.SKILLS
if reason == "skills"
else Applications.RejectionStates.OTHER
)
notification_names = member_application.eve_character.character_name
remove_character_from_community(
member_application,
Applications.MembershipStates.REJECTED,
rejection_reason,
days,
)
remove_character_from_acl(
member_application.eve_character.character_id,
acl_name,
old_state,
member_application.member_state,
rejection_reason,
)
else:
# Other can be used for individual removal of alts that need cleaning up.
# note: currently only used on the reject an open application - additional @@@ TODO to hook up to the remove membership page
logger.debug(
f"Singleton removal of {member_application.eve_character.character_name}"
)

log_application_change(
application=member_application, old_state=old_state, reason=rejection_reason
rejection_reason = (
Applications.RejectionStates.SKILLS
if reason == "skills"
else Applications.RejectionStates.OTHER
)
notification_names = member_application.eve_character.character_name
remove_character_from_community(
member_application,
Applications.MembershipStates.REJECTED,
rejection_reason,
days,
)
remove_character_from_acl(
member_application.eve_character.character_id,
acl_name,
old_state,
member_application.member_state,
rejection_reason,
)

log_application_change(
application=member_application, old_state=old_state, reason=rejection_reason
)

try:
# If this is an orphan, we won't know who to notify since there's no associated user.
notify.danger(
member_application.eve_character.character_ownership.user,
f"{acl_name} Community: {notify_subject}",
f"Your application to the {acl_name} Community on {notification_names} has been rejected.\n\n\t* Reason: {member_application.get_reject_reason_display()}"
+ "\n\nIf you have any questions about this action, please contact WHC Community Coordinators on discord.",
)
)
except:
pass

return redirect_target

@login_required
@permission_required("whctools.whc_officer")
def reset(request, char_id, acl_name="WHC"):

whcapplication = Applications.objects.filter(eve_character_id=char_id)
whcapplication = Applications.objects.filter(eve_character__character_id=char_id)

if whcapplication:
member_application = whcapplication[0]
Expand Down Expand Up @@ -442,7 +443,7 @@ def list_acl_members(request, acl_pk=""):

char_list.append({
"name": name,
"id": char_id,
"char_id": char_id,
"main": main,
"corp": corp,
"alliance": alliance,
Expand Down
2 changes: 1 addition & 1 deletion whctools/views_staff/open_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def all_characters_currently_with_open_apps():
def getSkills(eve_char_id):

application = Applications.objects.filter(
eve_character_id=eve_char_id
eve_character__character_id=eve_char_id
).select_related("eve_character")[0]

existing_acls = Acl.objects.all()
Expand Down

0 comments on commit 68a5b44

Please sign in to comment.