Class ContentRestrictedModelItemHelper
- java.lang.Object
-
- org.ametys.cms.model.restrictions.ContentRestrictedModelItemHelper
-
- All Implemented Interfaces:
Component
,Serviceable
public class ContentRestrictedModelItemHelper extends Object implements Component, Serviceable
Helper for definitions with restrictions on contents
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ContentRestrictedModelItemHelper.FirstRestrictionsChecksState
TODO NEWATTRIBUTEAPI_CONTENT: make this enum private when caller of_doFirstRestrictionsChecks(Content, Restrictions, boolean)
in DefaultContentType are removed
-
Field Summary
Fields Modifier and Type Field Description private CurrentUserProvider
_currentUserProvider
Current user provider.private RightManager
_rightManager
The rights manager.private WorkflowProvider
_workflowProvider
The workflow providerstatic String
ROLE
The Avalon role name
-
Constructor Summary
Constructors Constructor Description ContentRestrictedModelItemHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ContentRestrictedModelItemHelper.FirstRestrictionsChecksState
_doFirstRestrictionsChecks(Content content, Restrictions restrictions, boolean forReading)
Does the first checks on restrictions TODO NEWATTRIBUTEAPI_CONTENT: make this method private when caller in DefaultContentType are removedprivate boolean
_hasRights(Content content, Set<String> rightLimitations)
Check if current user has the given rights.private boolean
_isInWorkflowStep(WorkflowAwareContent content, Set<Integer> workflowLimitations)
Check if the workflow of the content is in a given current step.private boolean
_parseAccessType(Configuration configuration)
Parses type attribute from a configuration.Restrictions
_parseRestrictions(Configuration configuration)
Parses the attribute definition's restrictions.private void
_populateNegativeRestrictions(Configuration restrictionsConfig, Restrictions restrictions)
Populates the negative restrictions.private void
_populateRightRestrictions(Configuration restrictionsConfig, Restrictions restrictions)
Populates the rights restrictions.private void
_populateWorkflowRestrictions(Configuration restrictionsConfig, Restrictions restrictions)
Populates the workflows restrictions.boolean
canRead(Content content, ModelItem item, Restrictions restrictions)
Determine whether a model item can be read at this time.boolean
canWrite(Content content, ModelItem item, Restrictions restrictions)
Determine whether a model item can be written at this time.void
populateRestrictions(Configuration attributeConfiguration, Restrictions restrictions)
Parses the attribute definition's restrictions.void
service(ServiceManager manager)
-
-
-
Field Detail
-
_rightManager
private RightManager _rightManager
The rights manager.
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
Current user provider.
-
_workflowProvider
private WorkflowProvider _workflowProvider
The workflow provider
-
-
Constructor Detail
-
ContentRestrictedModelItemHelper
public ContentRestrictedModelItemHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
canRead
public boolean canRead(Content content, ModelItem item, Restrictions restrictions) throws AmetysRepositoryException
Determine whether a model item can be read at this time.- Parameters:
item
- the model item on which check the restrictionscontent
- The content where item is to be written on. Can be null, on content creation.restrictions
- the restrictions to check- Returns:
true
if the current user is allowed to write the model item of this content.- Throws:
AmetysRepositoryException
- if an error occurs while accessing the content workflow.
-
canWrite
public boolean canWrite(Content content, ModelItem item, Restrictions restrictions) throws AmetysRepositoryException
Determine whether a model item can be written at this time.- Parameters:
item
- the model item on which check the restrictionscontent
- The content where item is to be written on. Can be null, on content creation.restrictions
- the restrictions to check- Returns:
true
if the current user is allowed to write the model item of this content.- Throws:
AmetysRepositoryException
- if an error occurs while accessing the content workflow.
-
_doFirstRestrictionsChecks
public ContentRestrictedModelItemHelper.FirstRestrictionsChecksState _doFirstRestrictionsChecks(Content content, Restrictions restrictions, boolean forReading) throws AmetysRepositoryException
Does the first checks on restrictions TODO NEWATTRIBUTEAPI_CONTENT: make this method private when caller in DefaultContentType are removed- Parameters:
content
- The content where item is to be read / written on. Can be null, on content creation.restrictions
- The restrictions to applyforReading
-true
for reading checks,false
for writing checks.- Returns:
- the state of the first checks
- Throws:
AmetysRepositoryException
- if an error occurs while accessing the content workflow.
-
_hasRights
private boolean _hasRights(Content content, Set<String> rightLimitations)
Check if current user has the given rights.- Parameters:
rightLimitations
- the right limitations.content
- the content.- Returns:
true
if it is on at least one step,false
otherwise.
-
_isInWorkflowStep
private boolean _isInWorkflowStep(WorkflowAwareContent content, Set<Integer> workflowLimitations) throws AmetysRepositoryException
Check if the workflow of the content is in a given current step.- Parameters:
workflowLimitations
- the workflow limitations.content
- the content.- Returns:
true
if it is on at least one step,false
otherwise.- Throws:
AmetysRepositoryException
- if an error occurs.
-
_parseRestrictions
public Restrictions _parseRestrictions(Configuration configuration) throws ConfigurationException
Parses the attribute definition's restrictions.- Parameters:
configuration
- the configuration of the element that have content restrictions- Returns:
- the parsed restrictions.
- Throws:
ConfigurationException
- if the configuration is not valid.
-
populateRestrictions
public void populateRestrictions(Configuration attributeConfiguration, Restrictions restrictions) throws ConfigurationException
Parses the attribute definition's restrictions. TODO NEWATTRIBUTEAPI_CONTENT: This method is public to be used in MetadataAndRepeaterDefinitionParser fromDefaultContentType
. Make this method private when it is deleted- Parameters:
attributeConfiguration
- the attribute configuration to use.restrictions
- the restrictions.- Throws:
ConfigurationException
- if the configuration is not valid.
-
_populateNegativeRestrictions
private void _populateNegativeRestrictions(Configuration restrictionsConfig, Restrictions restrictions) throws ConfigurationException
Populates the negative restrictions.- Parameters:
restrictionsConfig
- the restrictions configuration to use.restrictions
- the restrictions.- Throws:
ConfigurationException
- if the configuration is not valid.
-
_populateRightRestrictions
private void _populateRightRestrictions(Configuration restrictionsConfig, Restrictions restrictions) throws ConfigurationException
Populates the rights restrictions.- Parameters:
restrictionsConfig
- the restrictions configuration to use.restrictions
- the restrictions.- Throws:
ConfigurationException
- if the configuration is not valid.
-
_populateWorkflowRestrictions
private void _populateWorkflowRestrictions(Configuration restrictionsConfig, Restrictions restrictions) throws ConfigurationException
Populates the workflows restrictions.- Parameters:
restrictionsConfig
- the restrictions configuration to use.restrictions
- the restrictions.- Throws:
ConfigurationException
- if the configuration is not valid.
-
_parseAccessType
private boolean _parseAccessType(Configuration configuration) throws ConfigurationException
Parses type attribute from a configuration.- Parameters:
configuration
- the configuration.- Returns:
true
forread
type,false
forwrite
type.- Throws:
ConfigurationException
- if the configuration is not valid.
-
-