From 1c1bcee7fd8bfce564109932ae4c79dbc0cb75e0 Mon Sep 17 00:00:00 2001 From: Jaimyn Mayer Date: Sat, 20 Apr 2024 19:13:25 +1000 Subject: [PATCH 1/2] added GHA comment about PR on wrong branch --- .github/workflows/comment_wrong_branch.yml | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/comment_wrong_branch.yml diff --git a/.github/workflows/comment_wrong_branch.yml b/.github/workflows/comment_wrong_branch.yml new file mode 100644 index 00000000..502d5707 --- /dev/null +++ b/.github/workflows/comment_wrong_branch.yml @@ -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.' + }) From b3941ade97b5ed53dde272b7fb523d05e60acdcb Mon Sep 17 00:00:00 2001 From: Jaimyn Mayer Date: Sat, 20 Apr 2024 19:17:34 +1000 Subject: [PATCH 2/2] fix unhandled exception when logging access for non existent user --- memberportal/api_access/consumers.py | 62 +++++++++++++++++++++------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/memberportal/api_access/consumers.py b/memberportal/api_access/consumers.py index 39cd54aa..daa2657e 100644 --- a/memberportal/api_access/consumers.py +++ b/memberportal/api_access/consumers.py @@ -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 @@ -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": @@ -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: