Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 13712c1

Browse files
committed
adjust to createbundle security refactoring
1 parent 64df05d commit 13712c1

File tree

9 files changed

+87
-43
lines changed

9 files changed

+87
-43
lines changed

bundles/block/cache.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ The Symfony2 CMF BlockBundle additionally provides its own adapters for:
99

1010
* `ESI`_
1111
* `SSI`_
12-
* Asynchronous javascript
13-
* Synchronous javascript
12+
* Asynchronous JavaScript
13+
* Synchronous JavaScript
1414

1515
.. note::
1616

@@ -145,14 +145,14 @@ is triggered:
145145

146146
* The ESI and SSI adapter add a specific tag and a url to retrieve the
147147
block content;
148-
* The javascript adapter adds javascript and a url to retrieve the block
148+
* The JavaScript adapter adds JavaScript and a url to retrieve the block
149149
content.
150150

151151
* If the cache element is not expired and has data it is returned.
152152
* The template is rendered:
153153

154154
* For ESI and SSI the url is called to retrieve the block content
155-
* For Javascript the browser calls a url and replaces a placeholder with the
155+
* For JavaScript the browser calls a url and replaces a placeholder with the
156156
* returned block content
157157

158158
.. note::
@@ -308,10 +308,10 @@ This extends the default SsiCache adapter of the SonataCacheBundle.
308308
See :ref:`the configuration reference <reference-config-block-caches-ssi>` to
309309
learn how to configure the ssi adapter.
310310

311-
Javascript
311+
JavaScript
312312
~~~~~~~~~~
313313

314-
Renders the block using javascript, the page is loaded and not waiting for the
314+
Renders the block using JavaScript, the page is loaded and not waiting for the
315315
block to be finished rendering or retrieving data. The block is then
316316
asynchronously or synchronously loaded and added to the page.
317317

bundles/block/introduction.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ A block service contains:
207207
* Default settings;
208208
* Dorm configuration;
209209
* Cache configuration;
210-
* Javascript and stylesheet assets to be loaded;
210+
* JavaScript files and stylesheet assets to be loaded;
211211
* A load method.
212212

213213
The block services provided by the Symfony2 CMF BlockBundle are in the
@@ -292,11 +292,11 @@ Cache Configuration
292292
The method ``getCacheKeys`` contains cache keys to be used for caching the
293293
block.
294294

295-
Javascript and Stylesheets
295+
JavaScript and Stylesheets
296296
~~~~~~~~~~~~~~~~~~~~~~~~~~
297297

298-
The methods ``getJavascripts`` and ``getStylesheets`` can be used to define
299-
javascript and stylesheet assets needed by a block. Use the twig helpers
298+
The methods ``getJavaScripts`` and ``getStylesheets`` can be used to define
299+
JavaScript and stylesheet assets needed by a block. Use the twig helpers
300300
``sonata_block_include_javascripts`` and ``sonata_block_include_stylesheets``
301301
to render them:
302302

@@ -314,7 +314,7 @@ to render them:
314314

315315
.. note::
316316

317-
This will output the javascripts and stylesheets for all blocks loaded in
317+
This will output the JavaScript files and stylesheets for all blocks loaded in
318318
the service container of your application.
319319

320320
The Load Method

bundles/block/types.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Publish Workflow Interfaces
2121
~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222

2323
The ``AbstractBlock`` implements the write interfaces for publishable and
24-
publish time period, see the
25-
:doc:`publish workflow documentation <../core/publish_workflow>` for more
24+
publish time period, see the
25+
:doc:`publish workflow documentation <../core/publish_workflow>` for more
2626
information.
2727

2828
Sonata Admin
@@ -275,15 +275,15 @@ SlideshowBlock
275275

276276
The ``SlideshowBlock`` is a special kind of ``ContainerBlock``. It can contain
277277
any kind of blocks that will be rendered with a wrapper div to help a
278-
javascript slideshow library to slide them.
278+
JavaScript slideshow library to slide them.
279279

280280
The ``ImagineBlock`` is particularly suited if you want to do an image
281281
slideshow, but the ``SlideshowBlock`` can handle any kind of blocks, also mixed
282282
types of blocks in the same slideshow.
283283

284284
.. note::
285285

286-
This bundle does not attempt to provide a javascript library for animating
286+
This bundle does not attempt to provide a JavaScript library for animating
287287
the slideshow. Chose your preferred library that plays well with the rest
288288
of your site and hook it on the slideshows. (See also below).
289289

@@ -341,7 +341,7 @@ Make the slideshow work in the frontend
341341
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342342

343343
Since the BlockBundle doesn't contain anything to make the slideshow work
344-
in the frontend, you need to do this yourself. Use your favourite javascript
344+
in the frontend, you need to do this yourself. Use your favourite JavaScript
345345
library to make the slideshow interactive. If special markup is needed for
346346
your slideshow code to work, you can override
347347
``BlockBundle:Block:block_slideshow.html.twig`` and/or the templates of the

bundles/create/developing-hallo.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To use this template, specify ``hallo-coffee`` as editor in the
3636
) ?>
3737
3838
The hallo-coffee template uses assetic to load the coffee script files from
39-
``Resources/public/vendor/hallo/src``, rather than the precompiled javascript
39+
``Resources/public/vendor/hallo/src``, rather than the precompiled JavaScript
4040
from ``Resources/public/vendor/create/deps/hallo-min.js``. This also means
4141
that you need to add a mapping for coffeescript in your assetic configuration
4242
and you need the `coffee compiler set up correctly`_.

bundles/create/introduction.rst

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CreateBundle
99
applications. It integrates create.js and the CreatePHP library into
1010
Symfony2.
1111

12-
The javascript library `create.js`_ provides a comprehensive web editing
12+
The JavaScript library `create.js`_ provides a comprehensive web editing
1313
interface for Content Management Systems. It is designed to provide a modern,
1414
fully browser-based HTML5 environment for managing content. Create.js can be
1515
adapted to work on almost any content management backend. Create.js makes your
@@ -88,7 +88,7 @@ Installation
8888
You can install this bundle `with composer`_ using the
8989
`symfony-cmf/create-bundle`_ package.
9090

91-
Additionally, you will need to provide the javascript libraries. The standard
91+
Additionally, you will need to provide the JavaScript libraries. The standard
9292
way to do this is to add a ``scripts`` section in your ``composer.json`` to
9393
have the CreateBundle download the necessary libraries:
9494

@@ -187,7 +187,7 @@ You also need to configure the FOSRestBundle to handle json:
187187
),
188188
));
189189
190-
If you want to use Assetic to combine the CSS and Javascript used for
190+
If you want to use Assetic to combine the CSS and JavaScript used for
191191
create.js, you need to enable the CreateBundle in the assetic configuration.
192192
Find the configuration for ``assetic.bundles``. If it is not present, assetic
193193
automatically scans all bundles for assets and you don't need to do anything.
@@ -274,29 +274,52 @@ additionally need to register the route for the image upload handler:
274274
275275
return $collection;
276276
277+
.. _bundle_create_introduction_access_control:
278+
277279
Access Control
278280
~~~~~~~~~~~~~~
279281

280282
In order to limit who can edit content, the provided controllers as well as the
281-
javascript loader check if the current user is granted the configured
282-
``cmf_create.role``. By default the role is ``ROLE_ADMIN``.
283+
JavaScript loader check if the current user is granted the configured
284+
``cmf_create.security.role``. By default the role is ``ROLE_ADMIN``.
283285

284286
.. tip::
285287

286288
In order to have security in place, you need to configure a
287289
"Symfony2 firewall". Read more in the `Symfony2 security chapter`_.
290+
If you do not do that, create.js will not be loaded and editing
291+
will be disabled.
292+
293+
If you do not want to edit on the production domain directly, e.g.
294+
because of caching, you can provide a second domain where you have
295+
security configured and do the editing there.
296+
297+
You can completely disable security checks by setting the role parameter to
298+
boolean ``false``. Then you need to configure access permissions on the routes
299+
defined in ``Resources/routing/rest.xml`` and, if activated, in ``image.xml``.
300+
If you set the role to false but do not configure any security,
301+
**every visitor of your site will be able to edit the content**.
302+
You also will need custom logic to decide whether to include the create.js
303+
JavaScript files.
304+
305+
You can also use a custom security check service by implementing
306+
``Symfony\Cmf\Bundle\CreateBundle\Security\AccessCheckerInterface``
307+
and setting this service in ``cmf_create.security.checker_service``.
288308

289309
If you need more fine grained access control, look into the CreatePHP
290310
``RdfMapperInterface`` ``isEditable`` method. You can extend a mapper and
291311
overwrite ``isEditable`` to answer whether the passed domain object is
292312
editable.
293313

294-
Load create.js Javascript and CSS
314+
Load create.js JavaScript and CSS
295315
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296316

297-
This bundle provides templates that load the required Javascript and CSS files
298-
based on Assetic. The Javascript loader also parametrizes the configuration
299-
for create.js and the chosen editor.
317+
This bundle provides a template that loads the required CSS files, as well as
318+
a controller action that loads the necessary JavaScript *if* the current user
319+
is allowed to edit according to
320+
:ref:`the security configuration <bundle_create_introduction_access_control>`.
321+
The JavaScript loader also parametrizes the configuration for create.js and
322+
WYSIWYG editor.
300323

301324
Alternatively, you can of course use your own templates to include the assets
302325
needed by create.js.
@@ -319,7 +342,7 @@ after those to be able to customize as needed) with:
319342
Make sure assetic is rewriting the paths in your CSS files properly or you
320343
might not see icon images.
321344

322-
In your page bottom area load the javascripts. If you are using Symfony 2.2 or
345+
In your page bottom area, load the JavaScript files. If you are using Symfony 2.2 or
323346
higher, the method reads:
324347

325348
.. configuration-block::
@@ -354,9 +377,15 @@ For Symfony 2.1, the syntax is:
354377
'_locale' => $app->getRequest()->getLocale(),
355378
) ?>
356379
380+
.. tip::
381+
382+
You can include this call unconditionally. The controller checks if the
383+
current user is allowed to edit and only in that case includes the
384+
JavaScript.
385+
357386
.. note::
358387

359-
The provided javascript file configures create.js and the editor. If you
388+
The provided JavaScript file configures create.js and the editor. If you
360389
use the hallo editor, a plugin is enabled to use the tag editor to edit
361390
``skos:related`` collections of attributes. For customization of the editor
362391
configuration further, you will need to use a

bundles/create/other-editors.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Then re-run composer:
3636
3737
$ php composer.phar run-scripts
3838
39-
In your template, load the javascript files using:
39+
In your template, load the JavaScript files using:
4040

4141
.. configuration-block::
4242

@@ -85,7 +85,7 @@ Custom Editors
8585
--------------
8686

8787
You can provide your own template to customize how to load CKEditor, hallo.js
88-
or a javascript editor not supported out of the box. The template has
88+
or a WYSIWYG editor not supported out of the box. The template has
8989
follow the naming pattern
9090
``CmfCreateBundle::includejsfiles-%editor%.html.twig`` to be loaded. You custom
9191
file thus needs to reside in ``app/Resources/CmfCreateBundle/views/`` and has
@@ -118,4 +118,4 @@ editor parameter:
118118
help, please see the github issue for `aloha`_ integration.
119119

120120
.. _`Aloha editor`: http://www.aloha-editor.org/
121-
.. _`aloha`: https://github.com/symfony-cmf/CreateBundle/issues/32
121+
.. _`aloha`: https://github.com/symfony-cmf/CreateBundle/issues/32

bundles/media/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ is protected by the ``ROLE_CAN_UPLOAD_FILE`` role.
235235

236236
The ``UploadFileHelper`` contains ``UploadEditorHelperInterface`` instances.
237237
This handles the response returned of the file upload depending on the web
238-
editing tool used and can be json, javascript or something else. Implement
238+
editing tool used and can be json, JavaScript or something else. Implement
239239
your own for specific needs, add it to the service configuration and tag the
240240
service with ``cmf_media.upload_editor_helper``, the tag alias is the editor
241241
helper name. The ``UploadFileHelper`` checks the request for the parameter

cookbook/handling_multilang_documents.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ for an example.
4545
Whenever you do a sub-request, for example to call a controller from a twig
4646
template, do not forget to pass the ``app.request.locale`` along or you will
4747
lose the request locale and fall back to the default.
48-
See for example the action to include the create.js javascript files in the
48+
See for example the action to include the create.js JavaScript files in the
4949
:ref:`create.js reference <bundle-create-usage-embed>`.
5050

5151
PHPCR-ODM multi-language Documents

reference/configuration/create.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,49 @@ Configuration
1818
Security
1919
~~~~~~~~
2020

21-
The controller that receives save requests from create.js requires the user to
22-
have a specific role to control who is allowed to edit content. As it would
21+
The controller that receives save requests from create.js does a security check
22+
to determine whether the current user is allowed to edit content. As it would
2323
not be convenient to show the create.js editor to users not allowed to edit the
24-
site, the controller loading the create.js javascripts with the
25-
``includeJSFilesAction`` also checks this role. If the image controller is
26-
activated, it checks for this role as well.
24+
site, the controller loading the create.js JavaScript files with the
25+
``includeJSFilesAction`` also uses the same security check, as does the image
26+
upload controller if it is activated.
2727

28+
The default security check checks if the user has a specified role. If nothing
29+
is configured, the default role is ``ROLE_ADMIN``. If you set the parameter to
30+
boolean ``false``, every user will be allowed to save changes through the REST
31+
controller.
32+
33+
A last option is to configure your own ``checker_service`` to be used instead
34+
of the role based check.
35+
36+
For more information, see the
37+
:ref:`security section in the bundle doc <bundle_create_introduction_access_control>`.
2838

2939
.. configuration-block::
3040

3141
.. code-block:: yaml
3242
3343
cmf_create:
34-
role: ROLE_ADMIN
44+
security:
45+
role: ROLE_ADMIN
46+
checker_service: ~
3547
3648
.. code-block:: xml
3749
3850
<?xml version="1.0" charset="UTF-8" ?>
3951
<container xmlns="http://symfony.com/schema/dic/services">
40-
<config xmlns="http://cmf.symfony.com/schema/dic/create"
41-
role="ROLE_ADMIN"
42-
/>
52+
<config xmlns="http://cmf.symfony.com/schema/dic/create">
53+
<security role="ROLE_ADMIN" checker-service="null"/>
54+
<config/>
4355
</container>
4456
4557
.. code-block:: php
4658
4759
$container->loadFromExtension('cmf_create', array(
48-
'role' => 'ROLE_ADMIN',
60+
'security' => array(
61+
'role' => 'ROLE_ADMIN',
62+
'checker_service' => null,
63+
),
4964
));
5065
5166
.. _config-create-persistence:

0 commit comments

Comments
 (0)