doorcontrol: Add is_door_active
to prevent forgetting "Misc Access"
This commit is contained in:
parent
71d2227854
commit
b3a7ef8232
@ -101,14 +101,8 @@ def update_user_groups(
|
|||||||
|
|
||||||
expected_group_members = (
|
expected_group_members = (
|
||||||
rule.get_matching_members()
|
rule.get_matching_members()
|
||||||
.with_is_active()
|
.with_is_door_active()
|
||||||
.filter(
|
.filter(Q(**{door.access_field: True}) & Q(is_door_active=True))
|
||||||
Q(**{door.access_field: True})
|
|
||||||
& (
|
|
||||||
Q(is_active=True)
|
|
||||||
| Member.objects.has_flag("folder", "Misc. Access")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# all members should exist in Access by this point
|
# all members should exist in Access by this point
|
||||||
expected_group_member_ids = [
|
expected_group_member_ids = [
|
||||||
@ -137,7 +131,7 @@ def sync_members(access_client: AccessClient):
|
|||||||
if user.employee_number
|
if user.employee_number
|
||||||
}
|
}
|
||||||
|
|
||||||
for member in Member.objects.with_is_active().all():
|
for member in Member.objects.with_is_door_active().all():
|
||||||
logger.info("Syncing member %s", member)
|
logger.info("Syncing member %s", member)
|
||||||
expected_user = {
|
expected_user = {
|
||||||
"first_name": member.first_name,
|
"first_name": member.first_name,
|
||||||
@ -149,12 +143,7 @@ def sync_members(access_client: AccessClient):
|
|||||||
|
|
||||||
if access_user := access_users_by_employee_number.get(member.uid):
|
if access_user := access_users_by_employee_number.get(member.uid):
|
||||||
expected_user["status"] = (
|
expected_user["status"] = (
|
||||||
UserStatus.ACTIVE
|
UserStatus.ACTIVE if member.is_door_active else UserStatus.DEACTIVATED
|
||||||
if (
|
|
||||||
member.is_active
|
|
||||||
or member.flags.filter(name="Misc. Access", type="folder").exists()
|
|
||||||
)
|
|
||||||
else UserStatus.DEACTIVATED
|
|
||||||
)
|
)
|
||||||
changes = {
|
changes = {
|
||||||
k: v for k, v in expected_user.items() if getattr(access_user, k) != v
|
k: v for k, v in expected_user.items() if getattr(access_user, k) != v
|
||||||
|
@ -123,6 +123,12 @@ class MemberQuerySet(models.QuerySet):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def with_is_door_active(self):
|
||||||
|
"""Like `is_active`, but also includes "Misc. Access" members"""
|
||||||
|
return self.with_is_active().annotate(
|
||||||
|
is_door_active=Q(is_active=True) | self.has_flag("folder", "Misc. Access")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Member(BaseModel):
|
class Member(BaseModel):
|
||||||
uid = models.CharField(max_length=24, primary_key=True)
|
uid = models.CharField(max_length=24, primary_key=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user