Multi-Site Considerations

Working with one more sites requires consideration of site domain names and site access to resources. Using Site-related APIs, you can set the domain name of a site, the site owner of an object, and other sites that can also access the object. However, it is recommended that the administrator perform these actions with the Brightspot editorial UI. See Creating Sites and Multi-Site and URLs for more information.

Querying with Site Restrictions

In a multi-site environment, you may have use cases where queries need to reflect the site context. For example, the Brightspot Recent Activity widget and search panel query for objects that are owned by the site that the user selects in the Dashboard.

By default, a query searches for objects across all sites unless otherwise restricted. Consider the use case of generating and displaying a list of articles that are related to an article selected by a user. 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 logged-in site, 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 selected by the user.

  • 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 ten articles retrieved.