Restricting extension types | IMAGE AND ASSET UPLOAD VALIDATION

36 views
Skip to first unread message

raja harivansh

unread,
Sep 11, 2017, 7:11:19 AM9/11/17
to Hippo Community
Hi All,

the type of assets that are allowed to be uploaded into the cms can be restricted via assetValidationService-

/hippo:configuration/hippo:frontend/cms/cms-services/assetValidationService

However, any changes I make on this node will be overwritten the next time a fresh installation of hippo is used, or a new patch/version is rolled over.

Is there any way to go around this problem? To make changes in the assetvalidationservice and not have it over-written the next time an update is rolled out?

Thanks in advance :) 

Jasper Floor

unread,
Sep 11, 2017, 7:27:35 AM9/11/17
to Hippo Community
Hi,
In your project add a delta xml for these changes. See 

mvg,
Jasper

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

raja harivansh

unread,
Sep 12, 2017, 5:36:57 AM9/12/17
to Hippo Community
Hi Jasper, 

I dont think i understand..

I make changes under - /hippo:configuration/hippo:frontend/cms/cms-services/assetValidationService
This is a hippo configuration change. 

Now consider this-
1. A patch is rolled out. 
2. It contains an update under /hippo:configuration/hippo:frontend/cms/cms-services
3. This update will over-write my changes at the assetValidationService node. 
4. Now, if you notice all the changes made on this node are stored in a cms.xml, with the path being- configuration\src\main\resources\configuration\frontend\cms.xml . IE, assetValidationService does not have its specific xml! There is only 1 cms.xml.
5. If i deploy my cms.xml , it will over-write the changes of the patch. .. And the patch will over-write my changes. 

It seems to me that I'm stuck in a deadlock. 

I hope I make this clear? Do we have a workaround for this?

Jasper Floor

unread,
Sep 12, 2017, 7:14:13 AM9/12/17
to Hippo Community
Create a specific xml file that only contains delta directives. Don't rely on your cms.xml.

mvg,
Jasper

raja harivansh

unread,
Sep 18, 2017, 3:55:13 AM9/18/17
to Hippo Community
Hi Jasper,

Thanks for the quick reply and the patience against my bugging :D 

My cms.xml is something like this- 

<?xml version="1.0" encoding="UTF-8"?><sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:esv="http://www.onehippo.org/jcr/xmlimport" sv:name="cms" esv:merge="combine">
  <sv:node sv:name="cms-validators" esv:merge="combine">
    <sv:node sv:name="textarea-maxlength">
      <sv:property sv:name="jcr:primaryType" sv:type="Name">
        <sv:value>frontend:plugin</sv:value>
      </sv:property>
      <sv:property sv:name="plugin.class" sv:type="String">
        <sv:value>org.hippoecm.frontend.editor.validator.plugins.RegExCmsValidator</sv:value>
      </sv:property>
      <sv:property sv:name="regex_pattern" sv:type="String">
        <sv:value>^[\s\S]{0,160}$</sv:value>
      </sv:property>
    </sv:node>
  </sv:node>
  <sv:node sv:name="cms-services" esv:merge="combine">
    ---------
    *other nodes* 
    ---------
  </sv:node>
</sv:node>

And my delta file is -- 
<?xml version="1.0" encoding="UTF-8"?>
<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:esv="http://www.onehippo.org/jcr/xmlimport" sv:name="cms" esv:merge="combine">
  <sv:node sv:name="cms-services" esv:merge="combine">
    <sv:node sv:name="assetValidationService">
     <sv:property sv:name="extensions.allowed" sv:type="String" sv:multiple="true">
        <sv:value>*.pdf</sv:value>
      </sv:property>
    </sv:node>
  </sv:node>
</sv:node> 

As you can see, I'm trying to overwrite the  assetValidationService node, adding the extensions.allowed property. 

I have 2 questions here-
1. Is the delta file correctly written?
2. What to name the delta file? and where to place it? ...Should i place it right next to the cms.xml, in the file system? 

raja harivansh

unread,
Sep 19, 2017, 12:36:14 AM9/19/17
to Hippo Community
And how will this delta file be deployed to the cms? Any special configurations needed to be keyed in?

TIA !! :)

Jasper Floor

unread,
Sep 19, 2017, 4:31:35 AM9/19/17
to Hippo Community
Hi,

if you are adding new nodes there is no need for a delta. I would just create the node directly.
Create a file textarea-maxlength.xml

<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="textarea-maxlength" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>frontend:plugin</sv:value>
  </sv:property>
  <sv:property sv:name="plugin.class" sv:type="String">
    <sv:value>org.hippoecm.frontend.editor.validator.plugins.RegExCmsValidator</sv:value>
  </sv:property>
  <sv:property sv:name="regex_pattern" sv:type="String">
    <sv:value>^[\s\S]{0,160}$</sv:value>
  </sv:property>
</sv:node>

Then in your hippoecm-extension.xml

  <sv:node sv:name="myhippoproject-configuration-frontend-cms-cmsvalidator-textarea-maxlength">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
      <sv:value>hippo:initializeitem</sv:value>
    </sv:property>
    <sv:property sv:name="hippo:sequence" sv:type="Double">
      <sv:value>50000</sv:value>
    </sv:property>>
    <sv:property sv:name="hippo:contentresource" sv:type="String">
      <sv:value>path/to/textarea-maxlength.xml</sv:value>
    </sv:property>
    <sv:property sv:name="hippo:contentroot" sv:type="String">
      <sv:value>/hippo:configuration/hippo:frontend/cms/cms-validators</sv:value>
    </sv:property>
  </sv:node>

Use a delta to modify existing nodes that are not under your control. Though for setting a single property you can also do a propset in your hippoecm-extension

<sv:node sv:name="myproject-setproperty">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>hippo:initializeitem</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:sequence" sv:type="Double">
    <sv:value>52000</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:contentroot" sv:type="String">
    <sv:value>/path/to/property</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:contentpropset" sv:type="String">
    <sv:value>one</sv:value>
  </sv:property> 
</sv:node> 


Your deltas seem fine though and should work. The advantage of deltas is that they work on existing nodes. A non delta will reload the entire node, which becomes problematic if you don't control that nodes. If those nodes are reloaded by the library that created them then you lose your changes. The disadvantage is that they cannot be reloaded (ie reloadonstartup). In version 12 this all changes as the whole bootstrapping/configuration management has gotten a major overhaul.

As for naming, I would name files after the (top level) node they add/modify. I would put them in a path that mirrors the repository path. There are of course many ways to do it. I also personally prefer to keep files as small as possible, but this leads to loads of files and init items. For that reason, especially on nodes that won't change much, it is sometimes better to bundle them. As is often done with templates or hosts configurations. 

mvg,
Jasper

On Tue, Sep 19, 2017 at 6:36 AM, raja harivansh <hariva...@gmail.com> wrote:
And how will this delta file be deployed to the cms? Any special configurations needed to be keyed in?

TIA !! :)

--

raja harivansh

unread,
Sep 21, 2017, 7:04:54 AM9/21/17
to Hippo Community
Hi Jasper, 

Apologies, but My approach towards this issue changed. :)  Now instead of restricting asset types on upload, I'd like to restrict them in the asset picker. 

Basically, when the author clicks on the link picker select button and the pop-up box opens up(to select the asset), he should be able to select only the allowed extension types- pdf and word, for example.

Is this possible in hippo?
Reply all
Reply to author
Forward
0 new messages