Skip to content
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
11 changes: 10 additions & 1 deletion memberportal/access/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from django.contrib import admin
from rest_framework_api_key.admin import APIKeyModelAdmin
from .models import *
from .models import (
AccessControlledDevice,
AccessControlledDeviceAPIKey,
ExternalAccessControlAPIKey,
Doors,
DoorLog,
Interlock,
InterlockLog,
MemberbucksDevice,
)


@admin.register(AccessControlledDeviceAPIKey)
Expand Down
6 changes: 3 additions & 3 deletions memberportal/api_access/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def receive_json(self, content=None, **kwargs):
)

except Exception as e:
logger.error("Error receiving message from device: %s", e)
logger.exception("Error receiving message from device")
self.send_json({"command": "error"})
raise e

Expand Down Expand Up @@ -544,7 +544,7 @@ def handle_other_packet(self, content):
)
message = f"We just tried to debit ${amount} from your {config.MEMBERBUCKS_NAME} balance but were not "
f"successful. You currently have ${profile.memberbucks_balance}. If this wasn't you, please let us know "
f"immediately."
"immediately."

User.objects.get(profile=profile).email_notification(subject, message)

Expand Down Expand Up @@ -613,7 +613,7 @@ def handle_other_packet(self, content):
)
message = f"Description: {transaction.description}. Balance Remaining: "
f"${profile.memberbucks_balance}. If this wasn't you, or you believe there "
f"has been an error, please let us know."
"has been an error, please let us know."

User.objects.get(profile=profile).email_notification(subject, message)

Expand Down
36 changes: 19 additions & 17 deletions memberportal/api_access/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from rest_framework.views import APIView
from constance import config

API_DISABLED_MESSAGE = "This API is disabled in the config."


class AccessSystemStatus(APIView):
"""
Expand All @@ -21,7 +23,7 @@ class AccessSystemStatus(APIView):
permission_classes = (HasExternalAccessControlAPIKey | permissions.IsAdminUser,)

def get(self, request):
statusObject = {
status_object = {
"doors": [],
"interlocks": [],
"memberbucksDevices": [],
Expand Down Expand Up @@ -58,7 +60,7 @@ def report_count(device_type: str):
offline = door.get_unavailable()
update_count(offline, door.locked_out)

statusObject["doors"].append(
status_object["doors"].append(
{
"id": door.id,
"name": door.name,
Expand All @@ -78,7 +80,7 @@ def report_count(device_type: str):
offline = interlock.get_unavailable()
update_count(offline, interlock.locked_out)

statusObject["interlocks"].append(
status_object["interlocks"].append(
{
"id": interlock.id,
"name": interlock.name,
Expand All @@ -94,30 +96,30 @@ def report_count(device_type: str):
report_count("interlock")
reset_count()

for memberbucksDevice in MemberbucksDevice.objects.all():
offline = memberbucksDevice.get_unavailable()
update_count(offline, memberbucksDevice.locked_out)
for memberbucks_device in MemberbucksDevice.objects.all():
offline = memberbucks_device.get_unavailable()
update_count(offline, memberbucks_device.locked_out)

statusObject["memberbucksDevices"].append(
status_object["memberbucksDevices"].append(
{
"id": memberbucksDevice.id,
"name": memberbucksDevice.name,
"lastSeen": memberbucksDevice.last_seen,
"lockedOut": memberbucksDevice.locked_out,
"id": memberbucks_device.id,
"name": memberbucks_device.name,
"lastSeen": memberbucks_device.last_seen,
"lockedOut": memberbucks_device.locked_out,
"offline": offline,
}
)
if offline and memberbucksDevice.report_online_status:
if offline and memberbucks_device.report_online_status:
a_device_is_offline = True

# report spacebucksDevices metrics
report_count("spacebucksDevice")
reset_count()

if error_if_offline and a_device_is_offline:
return Response(statusObject, status=status.HTTP_503_SERVICE_UNAVAILABLE)
return Response(status_object, status=status.HTTP_503_SERVICE_UNAVAILABLE)

return Response(statusObject)
return Response(status_object)


class UserAccessPermissions(APIView):
Expand Down Expand Up @@ -260,7 +262,7 @@ def post(self, request, door_id):
return Response({"success": bumped})
else:
return Response(
{"success": False, "error": "This API is disabled in the config."},
{"success": False, "error": API_DISABLED_MESSAGE},
status=status.HTTP_403_FORBIDDEN,
)

Expand All @@ -286,7 +288,7 @@ def post(self, request, door_id=None, interlock_id=None):
return Response({"success": locked})
else:
return Response(
{"success": False, "error": "This API is disabled in the config."},
{"success": False, "error": API_DISABLED_MESSAGE},
status=status.HTTP_403_FORBIDDEN,
)

Expand All @@ -312,6 +314,6 @@ def post(self, request, door_id=None, interlock_id=None):
return Response({"success": unlocked})
else:
return Response(
{"success": False, "error": "This API is disabled in the config."},
{"success": False, "error": API_DISABLED_MESSAGE},
status=status.HTTP_403_FORBIDDEN,
)
2 changes: 1 addition & 1 deletion memberportal/api_admin_tools/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import *
from .models import MemberTier, PaymentPlan


@admin.register(MemberTier)
Expand Down
Loading
Loading