Skip to content

Commit

Permalink
Merge branch 'master' into release-2015.09
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Oct 14, 2015
2 parents da15761 + 83f3cd3 commit 544c7c8
Show file tree
Hide file tree
Showing 20 changed files with 739 additions and 27 deletions.
51 changes: 51 additions & 0 deletions bundle/Resources/config/role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
parameters:
# Form types
ezrepoforms.policy.edit.form.class: EzSystems\RepositoryForms\Form\Type\Role\PolicyType

# Validators
ezrepoforms.validator.unique_role_identifier.class: EzSystems\RepositoryForms\Validator\Constraints\UniqueRoleIdentifierValidator

# Action dispatchers
ezrepoforms.action_dispatcher.role.class: EzSystems\RepositoryForms\Form\ActionDispatcher\RoleDispatcher
ezrepoforms.action_dispatcher.policy.class: EzSystems\RepositoryForms\Form\ActionDispatcher\PolicyDispatcher

# Form processors
ezrepoforms.form_processor.role.class: EzSystems\RepositoryForms\Form\Processor\RoleFormProcessor
ezrepoforms.form_processor.policy.class: EzSystems\RepositoryForms\Form\Processor\PolicyFormProcessor

services:
# Form types
ezrepoforms.policy.edit.form:
class: %ezrepoforms.policy.edit.form.class%
arguments: [%ezpublish.api.role.policy_map%, @translator]
tags:
- { name: form.type, alias: ezrepoforms_policy_edit }

# Validators
ezrepoforms.validator.unique_role_identifier:
class: %ezrepoforms.validator.unique_role_identifier.class%
arguments: [@ezpublish.api.service.role]
tags:
- { name: validator.constraint_validator, alias: ezrepoforms.validator.unique_role_identifier }

# Action dispatchers
ezrepoforms.action_dispatcher.role:
class: %ezrepoforms.action_dispatcher.role.class%
parent: ezrepoforms.action_dispatcher.base

ezrepoforms.action_dispatcher.policy:
class: %ezrepoforms.action_dispatcher.policy.class%
parent: ezrepoforms.action_dispatcher.base

# Form processors
ezrepoforms.form_processor.role:
class: %ezrepoforms.form_processor.role.class%
arguments: [@ezpublish.api.service.role]
tags:
- { name: kernel.event_subscriber }

ezrepoforms.form_processor.policy:
class: %ezrepoforms.form_processor.policy.class%
arguments: [@ezpublish.api.service.role]
tags:
- { name: kernel.event_subscriber }
22 changes: 3 additions & 19 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- {resource: section.yml}
- {resource: role.yml}

parameters:
ezrepoforms.field_type_form_mapper.registry.class: EzSystems\RepositoryForms\FieldType\FieldTypeFormMapperRegistry
Expand Down Expand Up @@ -28,7 +29,6 @@ parameters:
ezrepoforms.validator.validator_configuration.class: EzSystems\RepositoryForms\Validator\Constraints\ValidatorConfigurationValidator
ezrepoforms.validator.field_settings.class: EzSystems\RepositoryForms\Validator\Constraints\FieldSettingsValidator
ezrepoforms.validator.default_field_value.class: EzSystems\RepositoryForms\Validator\Constraints\FieldDefinitionDefaultValueValidator
ezrepoforms.validator.unique_role_identifier.class: EzSystems\RepositoryForms\Validator\Constraints\UniqueRoleIdentifierValidator

ezrepoforms.twig.field_edit_rendering_extension.class: EzSystems\RepositoryForms\Twig\FieldEditRenderingExtension
ezrepoforms.action_dispatcher.content_type.class: EzSystems\RepositoryForms\Form\ActionDispatcher\ContentTypeDispatcher
Expand All @@ -38,8 +38,6 @@ parameters:
ezrepoforms.form_processor.content_type.options:
redirectRouteAfterPublish: %ezrepoforms.form_processor.content_type.options.redirect_route_after_publish%
ezrepoforms.form_processor.content_type_group.class: EzSystems\RepositoryForms\Form\Processor\ContentTypeGroupFormProcessor
ezrepoforms.action_dispatcher.role.class: EzSystems\RepositoryForms\Form\ActionDispatcher\RoleDispatcher
ezrepoforms.form_processor.role.class: EzSystems\RepositoryForms\Form\Processor\RoleFormProcessor

services:
ezrepoforms.field_type_form_mapper.registry:
Expand Down Expand Up @@ -176,18 +174,13 @@ services:
tags:
- { name: validator.constraint_validator, alias: ezrepoforms.validator.default_field_value }

ezrepoforms.validator.unique_role_identifier:
class: %ezrepoforms.validator.unique_role_identifier.class%
arguments: [@ezpublish.api.service.role]
tags:
- { name: validator.constraint_validator, alias: ezrepoforms.validator.unique_role_identifier }

ezrepoforms.twig.field_edit_rendering_extension:
class: %ezrepoforms.twig.field_edit_rendering_extension.class%
arguments: [@ezpublish.templating.field_block_renderer]
tags:
- { name: twig.extension }

# Action dispatchers
ezrepoforms.action_dispatcher.base:
class: EzSystems\RepositoryForms\Form\ActionDispatcher\AbstractActionDispatcher
abstract: true
Expand All @@ -202,6 +195,7 @@ services:
class: %ezrepoforms.action_dispatcher.content_type.group.class%
parent: ezrepoforms.action_dispatcher.base

# Form processors
ezrepoforms.form_processor.content_type:
class: %ezrepoforms.form_processor.content_type.class%
arguments: [@ezpublish.api.service.content_type, @router, %ezrepoforms.form_processor.content_type.options%]
Expand All @@ -213,13 +207,3 @@ services:
arguments: [@ezpublish.api.service.content_type]
tags:
- { name: kernel.event_subscriber }

ezrepoforms.action_dispatcher.role:
class: %ezrepoforms.action_dispatcher.role.class%
parent: ezrepoforms.action_dispatcher.base

ezrepoforms.form_processor.role:
class: %ezrepoforms.form_processor.role.class%
arguments: [@ezpublish.api.service.role]
tags:
- { name: kernel.event_subscriber }
28 changes: 28 additions & 0 deletions bundle/Resources/translations/ezrepoforms_role.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<source>role.save</source>
<target>Save</target>
</trans-unit>
<trans-unit id="2bcaf8ca5d0b4a50085011b522da0dfc">
<source>role.cancel</source>
<target>Cancel</target>
</trans-unit>
<trans-unit id="97ccb80e8991c2b37daf50834a8d7a18" resname="role.remove_draft">
<source>role.remove_draft</source>
<target>Cancel</target>
Expand All @@ -22,6 +26,30 @@
<source>role.create</source>
<target>Create a role</target>
</trans-unit>
<trans-unit id="f69be0366fdb75154d6781d3d1d63590">
<source>role.policy.type</source>
<target>Policy type</target>
</trans-unit>
<trans-unit id="be06833a23ccaafde1d58b4876abe401">
<source>role.policy.all_modules</source>
<target>All modules</target>
</trans-unit>
<trans-unit id="51cb855a33cf4446b6ffa51308c3ed1f">
<source>role.policy.all_functions</source>
<target>All functions</target>
</trans-unit>
<trans-unit id="7de073d0c9d3b8cd9a26a7362d2ae3de">
<source>role.policy.all_modules_all_functions</source>
<target>All modules / All functions</target>
</trans-unit>
<trans-unit id="ad15636cac36e85c7cb8abd53378feb9">
<source>role.policy.type.choose</source>
<target>Choose a combination of module/function</target>
</trans-unit>
<trans-unit id="c66259bddf003273f41e31e77b7af64d">
<source>role.policy.form.delete</source>
<target>Delete policy</target>
</trans-unit>
</body>
</file>
</xliff>
63 changes: 63 additions & 0 deletions lib/Data/Mapper/PolicyMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\RepositoryForms\Data\Mapper;

use eZ\Publish\API\Repository\Values\User\PolicyDraft;
use eZ\Publish\API\Repository\Values\ValueObject;
use EzSystems\RepositoryForms\Data\Role\PolicyCreateData;
use EzSystems\RepositoryForms\Data\Role\PolicyUpdateData;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PolicyMapper implements FormDataMapperInterface
{
/**
* Maps a ValueObject from eZ content repository to a data usable as underlying form data (e.g. create/update struct).
*
* @param ValueObject|\eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft
* @param array $params
*
* @return PolicyUpdateData|PolicyCreateData
*/
public function mapToFormData(ValueObject $policyDraft, array $params = [])
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
$params = $resolver->resolve($params);

if (!$this->isPolicyNew($policyDraft)) {
$data = new PolicyUpdateData([
'policyDraft' => $policyDraft,
'roleDraft' => $params['roleDraft'],
'initialRole' => $params['initialRole'],
'moduleFunction' => "{$policyDraft->module}|{$policyDraft->function}",
]);
} else {
$data = new PolicyCreateData([
'policyDraft' => $policyDraft,
'roleDraft' => $params['roleDraft'],
'initialRole' => $params['initialRole'],
]);
}

return $data;
}

private function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver
->setRequired(['roleDraft', 'initialRole'])
->setAllowedTypes('roleDraft', '\eZ\Publish\API\Repository\Values\User\RoleDraft')
->setAllowedTypes('initialRole', '\eZ\Publish\API\Repository\Values\User\Role');
}

private function isPolicyNew(PolicyDraft $policy)
{
return $policy->id === null;
}
}
2 changes: 1 addition & 1 deletion lib/Data/Mapper/RoleMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace EzSystems\RepositoryForms\Data\Mapper;

use eZ\Publish\API\Repository\Values\ValueObject;
use EzSystems\RepositoryForms\Data\RoleData;
use EzSystems\RepositoryForms\Data\Role\RoleData;

class RoleMapper implements FormDataMapperInterface
{
Expand Down
27 changes: 27 additions & 0 deletions lib/Data/Role/PolicyCreateData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\RepositoryForms\Data\Role;

use eZ\Publish\Core\Repository\Values\User\PolicyCreateStruct;
use EzSystems\RepositoryForms\Data\NewsnessCheckable;

/**
* @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft
* @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
* @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole
*/
class PolicyCreateData extends PolicyCreateStruct implements NewsnessCheckable
{
use PolicyDataTrait;

public function isNew()
{
return true;
}
}
49 changes: 49 additions & 0 deletions lib/Data/Role/PolicyDataTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\RepositoryForms\Data\Role;

use eZ\Publish\API\Repository\Values\User\PolicyDraft;

trait PolicyDataTrait
{
/**
* @var PolicyDraft
*/
protected $policyDraft;

/**
* @var \eZ\Publish\API\Repository\Values\User\RoleDraft
*/
protected $roleDraft;

/**
* Role the draft was created from.
*
* @var \eZ\Publish\API\Repository\Values\User\RoleDraft
*/
protected $initialRole;

/**
* Combination of module + function as a single string.
* Example: "content|read".
*
* @var string
*/
public $moduleFunction;

public function setPolicy(PolicyDraft $policyDraft)
{
$this->policy = $policyDraft;
}

public function getId()
{
return $this->policyDraft ? $this->policyDraft->id : null;
}
}
37 changes: 37 additions & 0 deletions lib/Data/Role/PolicyUpdateData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace EzSystems\RepositoryForms\Data\Role;

use eZ\Publish\Core\Repository\Values\User\PolicyUpdateStruct;
use EzSystems\RepositoryForms\Data\NewnessChecker;

/**
* @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft
* @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
* @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole
*/
class PolicyUpdateData extends PolicyUpdateStruct
{
use PolicyDataTrait, NewnessChecker;

protected function getIdentifierValue()
{
return $this->policyDraft->module;
}

public function getModule()
{
return $this->policyDraft->module;
}

public function getFunction()
{
return $this->policyDraft->function;
}
}
7 changes: 4 additions & 3 deletions lib/Data/RoleData.php → lib/Data/Role/RoleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
*
* @version //autogentag//
*/
namespace EzSystems\RepositoryForms\Data;
namespace EzSystems\RepositoryForms\Data\Role;

use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
use EzSystems\RepositoryForms\Data\NewnessChecker;
use EzSystems\RepositoryForms\Data\NewsnessCheckable;

/**
* Base data class for ContentType update form, with FieldDefinitions data and ContentTypeDraft.
*
* @property-read \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
* @property-read \EzSystems\RepositoryForms\Data\FieldDefinitionData[] $fieldDefinitionsData
* @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
*/
class RoleData extends RoleUpdateStruct implements NewsnessCheckable
{
Expand Down
15 changes: 15 additions & 0 deletions lib/Event/RepositoryFormEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ final class RepositoryFormEvents
*/
const ROLE_REMOVE_DRAFT = 'role.update.removeDraft';

/**
* Base name for Policy update processing events.
*/
const POLICY_UPDATE = 'policy.update';

/**
* Triggered when saving the policy.
*/
const POLICY_SAVE = 'policy.update.savePolicy';

/**
* Triggered when canceling policy edition.
*/
const POLICY_REMOVE_DRAFT = 'policy.update.removeDraft';

/**
* Triggered when updating a section.
*/
Expand Down
Loading

0 comments on commit 544c7c8

Please sign in to comment.