-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor publish workflow to use security, cleanup configuration #59
Changes from 1 commit
991a8d0
6c7aada
65ccec2
e4e1275
bdf22d7
e750115
c7a67ae
5afa058
87fd7f3
45f1fba
4587c0c
93fb382
003d8cd
89bf726
e0d41d8
b516cd7
fc927c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
Changelog | ||
========= | ||
|
||
* **2013-06-20**: [PublishWorkflow] Moved the access checks to security voter | ||
and using isGranted 'VIEW' instead. | ||
Removed twig function cmf_is_published, just use is_granted('VIEW', content) | ||
instead. | ||
Configuration was adjusted: The parameter for the role that may see unpublished | ||
content moved from `role` to `publish_workflow.view_non_published_role`. The | ||
publish_workflow_listener moved to `publish_workflow.request_listener`. | ||
|
||
* **2013-05-16**: [PublishWorkFlowChecker] Removed Request argument | ||
from check method. Class now accepts a DateTime object to | ||
optionally "set" the current time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,23 @@ public function load(array $configs, ContainerBuilder $container) | |
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.xml'); | ||
|
||
$container->setParameter($this->getAlias().'.role', $config['role']); | ||
$container->setParameter($this->getAlias() . '.document_manager_name', $config['document_manager_name']); | ||
|
||
if (!$config['publish_workflow_listener']) { | ||
$container->removeDefinition($this->getAlias() . '.publish_workflow_listener'); | ||
} elseif (!class_exists('Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter')) { | ||
throw new InvalidConfigurationException("The 'publish_workflow_listener' may not be enabled unless 'Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter' is available."); | ||
if (isset($config['publish_workflow'])) { | ||
$this->loadPublishWorkflow($config['publish_workflow'], $loader, $container); | ||
} | ||
} | ||
|
||
public function loadPublishWorkflow($config, XmlFileLoader $loader, ContainerBuilder $container) { | ||
$container->setParameter($this->getAlias().'.publish_workflow.view_non_published_role', $config['view_non_published_role']); | ||
$loader->load('publish_workflow.xml'); | ||
|
||
if ($config['request_listener']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the nested if? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is possible to load the publish workflow but disable the request listener. or do i misunderstand your question? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could handle this entire thing with a single if() and no else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't see it. if we have request_listener but no dynamic router, we need to explode. if we do not have request_listener at all, we need to remove the service definition. if you think its better, i can change this to
|
||
if (!class_exists('Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter')) { | ||
throw new InvalidConfigurationException('The "publish_workflow.request_listener" may not be enabled unless "Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter" is available.'); | ||
} | ||
} else { | ||
$container->removeDefinition($this->getAlias() . '.publish_workflow.request_listener'); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,12 @@ public function getConfigTreeBuilder() | |
$rootNode | ||
->children() | ||
->scalarNode('document_manager_name')->defaultValue('default')->end() | ||
->scalarNode('role')->defaultValue('IS_AUTHENTICATED_ANONYMOUSLY')->end() | ||
->booleanNode('publish_workflow_listener')->defaultFalse()->end() | ||
->arrayNode('publish_workflow') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wonder if we should not enable the pwf things by default. the model and admin classes do expose the information, so as a clueless user, i would expect it to just work. this is about security, so i would prefer security over performance for the default value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added addDefaultsIfNotSet and an enabled parameter |
||
->children() | ||
->scalarNode('view_non_published_role')->defaultValue('CAN_VIEW_NON_PUBLISHED')->end() | ||
->booleanNode('request_listener')->defaultTrue()->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow; | ||
|
||
/** | ||
* Interface models can implement if they want to support time based publish | ||
* checking. | ||
*/ | ||
interface PublishTimePeriodInterface | ||
{ | ||
/** | ||
* Return the date from which the content should be published. | ||
* | ||
* A NULL value is interpreted as a date in the past, meaning the content | ||
* is publishable unless publish end date is set and in the past. | ||
* | ||
* @return \DateTime|null | ||
*/ | ||
public function getPublishStartDate(); | ||
|
||
/** | ||
* Return the date at which the content should stop being published. | ||
* | ||
* A NULL value is interpreted as saying that the document will | ||
* never end being publishable. | ||
* | ||
* @return \DateTime|null | ||
*/ | ||
public function getPublishEndDate(); | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow; | ||
|
||
/** | ||
* Interface models can implement if they want to support publish checking with | ||
* a binary flag. | ||
* | ||
* Several publish interfaces can be combined. Publish voters will return DENY | ||
* if the condition is not met and ABSTAIN if it is met, to allow other voters | ||
* to influence the decision as well. | ||
*/ | ||
interface PublishableInterface | ||
{ | ||
/** | ||
* Whether this content is publishable at all. | ||
* | ||
* A false value indicates that the content is not published. True means it | ||
* is allowed to show this content. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isPublishable(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="cmf_core.twig_extension_class">Symfony\Cmf\Bundle\CoreBundle\Twig\TwigExtension</parameter> | ||
<parameter key="cmf_core.publish_workflow_listener_class">Symfony\Cmf\Bundle\CoreBundle\EventListener\PublishWorkflowListener</parameter> | ||
<parameter key="cmf_core.security.publishable_voter_class">Symfony\Cmf\Bundle\CoreBundle\Security\Authorization\Voter\PublishableVoter</parameter> | ||
<parameter key="cmf_core.security.publish_time_period_voter_class">Symfony\Cmf\Bundle\CoreBundle\Security\Authorization\Voter\PublishTimePeriodVoter</parameter> | ||
<parameter key="cmf_core.listener.request_aware_class">Symfony\Cmf\Bundle\CoreBundle\EventListener\RequestAwareListener</parameter> | ||
<parameter key="cmf_core.admin_extension.publish_workflow_class">Symfony\Cmf\Bundle\CoreBundle\Admin\Extension\PublishWorkflowExtension</parameter> | ||
</parameters> | ||
|
||
<services> | ||
|
||
<service id="cmf_core.security.publishable_voter" class="%cmf_core.security.publishable_voter_class%"> | ||
<argument type="service" id="service_container" on-invalid="ignore"/> | ||
<argument>%cmf_core.publish_workflow.view_non_published_role%</argument> | ||
<tag name="security.voter"/> | ||
</service> | ||
|
||
<service id="cmf_core.security.publish_time_period_voter" class="%cmf_core.security.publish_time_period_voter_class%"> | ||
<argument type="service" id="service_container" on-invalid="ignore"/> | ||
<argument>%cmf_core.publish_workflow.view_non_published_role%</argument> | ||
<tag name="security.voter"/> | ||
</service> | ||
|
||
<service id="cmf_core.publish_workflow.request_listener" class="%cmf_core.publish_workflow_listener_class%"> | ||
<tag name="kernel.event_subscriber"/> | ||
<argument type="service" id="security.context"/> | ||
</service> | ||
|
||
<service id="cmf_core.admin_extension.publish_workflow" class="%cmf_core.admin_extension.publish_workflow_class%"> | ||
<tag name="sonata.admin.extension"/> | ||
</service> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to remove this definition when there is no sonata available? see #60 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will just remove it for good measure |
||
|
||
</services> | ||
</container> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly brackets needs to be on the next line