@@ -867,6 +867,8 @@ public function filterByTeam(Event $event)
867867 $ entityClass = $ event ->getTarget ()->getEntityClass ();
868868 $ alias = 'omeka_root ' ;
869869 $ em = $ this ->getServiceLocator ()->get ('Omeka\EntityManager ' );
870+ $ isSiteRequest = $ this ->getServiceLocator ()->get ('Omeka\Status ' )->isSiteRequest ();
871+
870872
871873 //fist, catch some cases where we shouldn't filter by team
872874
@@ -875,61 +877,57 @@ public function filterByTeam(Event $event)
875877 return ;
876878 }
877879
878- // site requests can be handled by site settings
879- if ($ this ->getServiceLocator ()->get ('Omeka\Status ' )->isSiteRequest ()) {
880+ //most site calls are handled by the site-item relationships, but this is for the list-of-sites block.
881+ if ($ event ->getParam ('request ' )->getResource () === 'sites ' &&
882+ $ event ->getParam ('request ' )->getOperation () === 'search ' &&
883+ $ isSiteRequest
884+ ) {
885+ //get the id for the current site
886+ $ siteSlug = $ this ->getServiceLocator ()->get ('Omeka\Status ' )->getRouteMatch ()->getParam ('site-slug ' );
887+ $ siteId = $ em ->getRepository ('Omeka\Entity\Site ' )->findOneBy (['slug ' => $ siteSlug ])->getId ();
888+
889+ //get the teams of the current site because we only want to show sites within its teams.
890+ $ teams = $ em ->getRepository ('Teams\Entity\TeamSite ' )->findBy (['site ' => $ siteId ]);
891+ $ teamIds = [];
892+
893+ foreach ($ teams as $ team ):
894+ $ teamIds [] = $ team ->getTeam ()->getId ();
895+ endforeach ;
896+
897+ //only get sites that share a team with the current site
898+ $ qb ->join ('Teams\Entity\TeamSite ' , 'ts ' , Expr \Join::WITH , $ alias . '.id = ts.site ' )
899+ ->andWhere ('ts.team IN (:team_ids) ' )
900+ ->setParameter ('team_ids ' , $ teamIds );
901+ return ;
902+ }
903+ // other site requests can be handled by site settings
904+ if ($ isSiteRequest ) {
880905 return true ;
881906 }
882907
883908 //catch cases where bypass_team_filter is passes, and it is a valid flag for the user's access level or the context,
884909 // e.g. certain non-admin site requests
885-
886- $ site_request = $ this ->getServiceLocator ()->get ('Omeka\Status ' )->isSiteRequest ();
887910 $ globalSettings = $ this ->getServiceLocator ()->get ('Omeka\Settings ' );
888- $ bypass_teams_filter_roles = $ globalSettings ->get ('teams_filter_bypass_roles ' );
911+ $ bypassTeamsRilterRoles = $ globalSettings ->get ('teams_filter_bypass_roles ' );
889912
890- if (!is_array ($ bypass_teams_filter_roles )) {
891- $ bypass_teams_filter_roles [] = $ bypass_teams_filter_roles ;
913+ if (!is_array ($ bypassTeamsRilterRoles )) {
914+ $ bypassTeamsRilterRoles [] = $ bypassTeamsRilterRoles ;
892915 } else {
893- $ bypass_teams_filter_roles = ['global_admin ' ];
916+ $ bypassTeamsRilterRoles = ['global_admin ' ];
894917 }
895918 if (isset ($ query ['bypass_team_filter ' ])
896919 && $ query ['bypass_team_filter ' ]
897- && in_array ($ this ->getUser ()->getRole (), $ bypass_teams_filter_roles )
920+ && in_array ($ this ->getUser ()->getRole (), $ bypassTeamsRilterRoles )
898921 ) {
899922 return ;
900923 }
901- if (isset ($ query ['bypass_team_filter ' ]) && $ site_request ) {
924+ if (isset ($ query ['bypass_team_filter ' ]) && $ isSiteRequest ) {
902925 return ;
903926 }
904- if (isset ($ query ['resource_class_id ' ]) && $ site_request ) {
927+ if (isset ($ query ['resource_class_id ' ]) && $ isSiteRequest ) {
905928 return ;
906929 }
907- if (isset ($ query ['resource_template_id ' ]) && $ site_request ) {
908- return ;
909- }
910-
911- //this is for the list-of-sites block.
912- if ($ event ->getParam ('request ' )->getResource () === 'sites ' &&
913- $ event ->getParam ('request ' )->getOperation () === 'search ' &&
914- $ this ->getServiceLocator ()->get ('Omeka\Status ' )->isSiteRequest ()
915- ) {
916-
917- //get the id for the current site
918- $ site_slug = $ this ->getServiceLocator ()->get ('Omeka\Status ' )->getRouteMatch ()->getParam ('site-slug ' );
919- $ site_id = $ em ->getRepository ('Omeka\Entity\Site ' )->findOneBy (['slug ' => $ site_slug ])->getId ();
920-
921- //get the teams of the current site because we only want to show sites within its teams.
922- $ teams = $ em ->getRepository ('Teams\Entity\TeamSite ' )->findBy (['site ' => $ site_id ]);
923- $ team_ids = [];
924-
925- foreach ($ teams as $ team ):
926- $ team_ids [] = $ team ->getTeam ()->getId ();
927- endforeach ;
928-
929- //only get sites that share a team with the current site
930- $ qb ->join ('Teams\Entity\TeamSite ' , 'ts ' , Expr \Join::WITH , $ alias . '.id = ts.site ' )
931- ->andWhere ('ts.team IN (:team_ids) ' )
932- ->setParameter ('team_ids ' , $ team_ids );
930+ if (isset ($ query ['resource_template_id ' ]) && $ isSiteRequest ) {
933931 return ;
934932 }
935933
@@ -962,7 +960,6 @@ public function filterByTeam(Event $event)
962960 return ;
963961 }
964962
965-
966963 $ team_id = $ this ->getTeamContext ($ query , $ event );
967964 if ($ team_id === [0 ]) {
968965 return ;
0 commit comments