Multi-Site Considerations

Site Properties and Multi-Site Permissions

The Site class provides methods to set a site’s properties, site owner of an object, and access to an object from other sites. However, as a best practice, administrators should perform these functions in Brightspot. See Creating Sites and Assigning Permissions to Content on Multiple Sites for more information.

Querying with Site Restrictions

In a multi-site environment, you may have cases in which queries need to reflect the site context. For example, the Recent Activity widget and search panel query for objects associated with the site that the editor is current working in.

By default, a query searches for objects across all sites unless otherwise restricted. For example, a visitor requested an article, and you want to display 10 associated articles. You can use a Query field in the Model, run the query in the ViewModel, and display the results in the View. The ViewModel must retrieve only articles owned by the site the visitor is at, or articles to which non-owning sites have been granted access. To accomplish this filtering, the ViewModel class can use the Site#itemsPredicate method in the query that gets related articles.

1
2
3
4
Query query = model.getQuery();
Site site = model.as(Site.ObjectModification.class).getOwner();
if (site != null) query.where(site.itemsPredicate());
List<Article> relatedArticles = query.select(0,10).getItems();

In the previous snippet—

  • Line 1 gets the query from the Model, the Article object retrieved by the visitor.
  • Line 2 gets the owner site of the article.
  • Line 3 uses the site.itemsPredicate method in the query if the article is owned by a user-created site. This method returns a predicate that filters out any articles that are not owned by the site, or articles to which non-owning sites have not been granted access. If the site is null, the article is owned by the Global site, which has access to all objects in Brightspot.
  • Line 5 executes the query, returning the first 10 articles retrieved.