Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and tweaks #261

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/comment_wrong_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Wrong Branch Warning

on:
workflow_dispatch:
pull_request:
types: [opened]
branches:
- "main"

jobs:
comment_warning:
if: ${{ github.event.pull_request.base.repo.clone_url != github.event.pull_request.head.repo.clone_url }}
runs-on: ubuntu-latest
steps:
- name: Comment warning about the wrong branch selected for PR
id: comment_docker_image
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Warning: we only accept PRs to the `dev` branch. It looks like you've created a PR to the `main` branch. Please edit this PR and select the `dev` branch as the target branch instead. If this was intentional please ignore this message.'
})
62 changes: 46 additions & 16 deletions memberportal/api_access/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,50 @@ def __init__(self, *args, **kwargs):

def handle_other_packet(self, content):
if content.get("command") == "log_access":
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success=True)
self.send_ack("log_access")
return True
# handle the case where the profile doesn't exist
try:
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success=True)
self.send_ack("log_access")
return True
except Profile.DoesNotExist:
self.send_ack("log_access")
logger.warning(
f"Tried to process log_access but profile with card ID {card_id} does not exist."
)
return True

elif content.get("command") == "log_access_denied":
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success=False)
self.send_ack("log_access_denied")
self.sync_users()
return True
# handle the case where the profile doesn't exist
try:
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success=False)
self.send_ack("log_access_denied")
self.sync_users()
return True
except Profile.DoesNotExist:
self.send_ack("log_access_denied")
logger.warning(
f"Tried to process log_access_denied but profile with card ID {card_id} does not exist."
)
return True

elif content.get("command") == "log_access_locked_out":
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success="locked_out")
self.send_ack("log_access_locked_out")
return True
# handle the case where the profile doesn't exist
try:
card_id = content.get("card_id")
profile = Profile.objects.get(rfid=card_id)
self.device.log_access(profile.user.id, success="locked_out")
self.send_ack("log_access_locked_out")
return True
except Profile.DoesNotExist:
self.send_ack("log_access_locked_out")
logger.warning(
f"Tried to process log_access_locked_out but profile with card ID {card_id} does not exist."
)
return True

else:
return False
Expand Down Expand Up @@ -448,6 +472,9 @@ def handle_other_packet(self, content):
"success": False,
}
)
logger.warning(
f"Tried to process balance but profile with card ID {card_id} does not exist."
)
return True

if content.get("command") == "debit":
Expand Down Expand Up @@ -487,6 +514,9 @@ def handle_other_packet(self, content):
"success": False,
}
)
logger.warning(
f"Tried to process debit but profile with card ID {card_id} does not exist."
)
return True

if profile.memberbucks_balance >= amount:
Expand Down
Loading