Skip to content

Commit

Permalink
Merge pull request #261 from membermatters/fixes-and-tweaks
Browse files Browse the repository at this point in the history
Fixes and tweaks
  • Loading branch information
jabelone authored May 23, 2024
2 parents 49befa2 + b3941ad commit db331e8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
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

0 comments on commit db331e8

Please sign in to comment.