@@ -21,6 +21,7 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
2121 end
2222
2323 schedule.every(30 .minutes) { ensure_booking_access }
24+ on_update
2425 end
2526
2627 @mutex = Mutex .new
@@ -129,6 +130,11 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
129130 security
130131 end
131132
133+ protected def has_access? (security , zone_id , user_id ) : Bool
134+ has_access = (String | Int64 | Nil ).from_json(security.zone_access_member?(zone_id, user_id).get.to_json)
135+ !! has_access
136+ end
137+
132138 @check_mutex : Mutex = Mutex .new
133139 @performing_check : Bool = false
134140 @check_queued : Bool = false
@@ -172,7 +178,7 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
172178
173179 # apply access this access to the system, need to find the differences
174180 allocations = @allocations
175- logger.debug { " found #{ allocations .size} users that need access" }
181+ logger.debug { " found #{ access_required .size} users that need access" }
176182
177183 if allocations == access_required
178184 logger.debug { " no access changes are required" }
@@ -213,7 +219,7 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
213219 begin
214220 zone_id = lookup_zone_id(security, zone)
215221 raise " unable to find zone_id for: #{ zone } " unless zone_id
216- security.zone_access_remove_member(zone_id, user_id).get
222+ security.zone_access_remove_member(zone_id, user_id).get if has_access?(security, zone_id, user_id)
217223 rescue error
218224 # add the user back to the zone so it can be removed in a later sync
219225 access_required[user_email] << zone
@@ -240,7 +246,7 @@ class Place::Bookings::GrantAreaAccess < PlaceOS::Driver
240246 begin
241247 zone_id = lookup_zone_id(security, zone)
242248 raise " unable to find zone_id for: #{ zone } " unless zone_id
243- security.zone_access_add_member(zone_id, user_id).get
249+ security.zone_access_add_member(zone_id, user_id).get unless has_access?(security, zone_id, user_id)
244250 rescue error
245251 # remove the user from the recorded zone so it can be added in a later sync
246252 access_required[user_email].delete zone
0 commit comments