Controlling revision access
Revisions are a helpful method of branching off from the published version of an asset, making changes, and then preserving those changes without publishing them live until a specified time in the future; however, by default, there is no restriction on who can create revisions, and the only way to access revisions is from the Version History widget on the content edit page (formerly referred to as the Revisions widget in Brightspot versions prior to 4.8). Because this may not always be desirable, Brightspot lets you control revision access.
Reasons you may want to limit revision access or to present only the latest revision:
- A new editor might only be required to perform simple functions in Brightspot, like proofreading the asset, but is not allowed to take editorial actions like creating a revision. Giving this individual the ability to create a revision can complicate operations or be superfluous to their needs.
- An editor working too quickly may not refer to the Version History widget and instead publish a change to the live asset. The revision author must then reconcile the published changes with those in the revision, which is time-consuming and prone to errors.
- An asset has multiple reviewers, all of whom must navigate to the asset, then select the appropriate revision. The extra clicks add up over time and unnecessarily increase the asset's workflow life cycle.
Draft.java
. This should not be confused with the drafts feature in Brightspot, which refers to content that is saved but not yet published.
The DraftAccess.java
and DraftSelector.java
ClassFinder
-based APIs allow administrators to set and enforce these controls so that an editor has a more curated experience in Brightspot.
DraftAccess API
DraftAccess.java
determines whether or not a revision can be created.
interface DraftAccess<T extends Recordable> {
boolean isCreationAllowed(T content);
}
DraftSelector API
DraftSelector.java
determines whether or not, when visiting an asset's content edit form, the latest revision of an asset is presented instead of the published version.
interface DraftSelector<T extends Recordable> {
Draft selectDraft(T content);
}
Example
In the following code snippet, an editor navigating to an asset lands immediately on the existing revision of it and cannot create any other revisions from it.
import com.psddev.cms.db.Content;
import com.psddev.cms.db.Draft;
import com.psddev.cms.ui.content.DraftAccess;
import com.psddev.cms.ui.content.DraftSelector;
import com.psddev.dari.db.Query;
public class ExampleRevisionManager implements DraftAccess<Content>, DraftSelector<Content> {
// only allow creation of new revisions if there are no existing revisions for the given content
@Override
public boolean isCreationAllowed(Content content) {
return !Query.from(Draft.class)
.where("objectId = ?", content.getId())
.hasMoreThan(0);
}
// when the given content is accessed, direct the user to the one existing revision instead
@Override
public Draft selectDraft(Content content) {
return Query.from(Draft.class)
.where("objectId = ?", content.getId())
.first();
}
}
As a result of this code, the editor sees a Revisions widget without the option to Start New Revision.
As a result of this code, in the Revisions widget, the editor is routed directly to the latest revision of the asset, and not to the published version.