@@ -204,6 +204,60 @@ def test_list_booking_filtered_by_organization_without_permissions(self):
204204 )
205205 self .assertEqual (response .status_code , 403 )
206206
207+ def test_list_booking_filtered_by_multiple_organizations (self ):
208+ """Bookings from either requested organization are included."""
209+ role = self .create_role_with_permissions (
210+ [SchedulePermissions .can_write_schedule .name ]
211+ )
212+ self .attach_role_facility_organization_user (self .organization , self .user , role )
213+ first_booking = self .create_booking ()
214+
215+ other_organization = self .create_facility_organization (facility = self .facility )
216+ self .attach_role_facility_organization_user (other_organization , self .user , role )
217+ other_user = self .create_user ()
218+ self .attach_role_facility_organization_user (
219+ other_organization , other_user , role
220+ )
221+ other_resource = self .create_resource (user = other_user )
222+ other_slot = self .create_slot (resource = other_resource )
223+ second_booking = self .create_booking (token_slot = other_slot )
224+
225+ response = self .client .get (
226+ self .base_url ,
227+ {
228+ "resource_type" : SchedulableResourceTypeOptions .practitioner .value ,
229+ "organization_ids" : (
230+ f"{ self .organization .external_id } ,{ other_organization .external_id } "
231+ ),
232+ },
233+ )
234+ self .assertEqual (response .status_code , 200 )
235+ self .assertCountEqual (
236+ [result ["id" ] for result in response .data ["results" ]],
237+ [str (first_booking .external_id ), str (second_booking .external_id )],
238+ )
239+
240+ def test_list_booking_filtered_by_multiple_organizations_checks_each_permission (
241+ self ,
242+ ):
243+ """A permitted organization cannot grant access to another one."""
244+ role = self .create_role_with_permissions (
245+ [SchedulePermissions .can_write_schedule .name ]
246+ )
247+ self .attach_role_facility_organization_user (self .organization , self .user , role )
248+ other_organization = self .create_facility_organization (facility = self .facility )
249+
250+ response = self .client .get (
251+ self .base_url ,
252+ {
253+ "resource_type" : SchedulableResourceTypeOptions .practitioner .value ,
254+ "organization_ids" : (
255+ f"{ self .organization .external_id } ,{ other_organization .external_id } "
256+ ),
257+ },
258+ )
259+ self .assertEqual (response .status_code , 403 )
260+
207261 def test_retrieve_booking_with_permissions (self ):
208262 """Users with can_list_user_booking permission can retrieve bookings."""
209263 permissions = [SchedulePermissions .can_list_booking .name ]
0 commit comments