Skip to content

Commit

Permalink
XWIKI-20907: Introduce the notion of required rights
Browse files Browse the repository at this point in the history
* Add a method to api.Document to get the required rights
* Add a method to convert to RequiredRight to a DocumentRequiredRight.
  • Loading branch information
michitux committed Nov 13, 2024
1 parent d5a7285 commit 74e1f1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3399,19 +3399,29 @@ public void setHidden(boolean hidden)
* @return {@code true} if required rights defined in a {@code XWiki.RequiredRightClass} object shall be
* enforced, meaning that editing will be limited to users with these rights and content of this document can't
* use more rights than defined in the object, {@code false} otherwise
* @since 16.6.0RC1
* @since 16.10.0RC1
*/
@Unstable
public boolean isEnforceRequiredRights()
{
return this.doc.isEnforceRequiredRights();
}

/**
* @return the required rights that have been set on this document
* @since 16.10.0RC1
*/
@Unstable
public DocumentRequiredRights getRequiredRights()
{
return Utils.getComponent(DocumentRequiredRightsReader.class).readRequiredRights(this.doc);
}

/**
* @param enforceRequiredRights if required rights defined in a {@code XWiki.RequiredRightClass} object shall be
* enforced, meaning that editing will be limited to users with these rights and content of this document can't use
* more rights than defined in the object
* @since 16.6.0RC1
* @since 16.10.0RC1
*/
@Unstable
public void setEnforceRequiredRights(boolean enforceRequiredRights)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.xwiki.model.EntityType;
import org.xwiki.security.authorization.Right;
import org.xwiki.security.authorization.requiredrights.DocumentRequiredRight;
import org.xwiki.stability.Unstable;
import org.xwiki.text.XWikiToStringBuilder;

Expand Down Expand Up @@ -123,6 +124,16 @@ public boolean isManualReviewNeeded()
return this.manualReviewNeeded;
}

/**
* @return the document required right equivalent of this required right
* @since 16.10.0RC1
*/
@Unstable
public DocumentRequiredRight toDocumentRequiredRight()
{
return new DocumentRequiredRight(this.right, this.entityType);
}

@Override
public String toString()
{
Expand Down

0 comments on commit 74e1f1d

Please sign in to comment.