Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hubert 9 posts 39 karma points
    Sep 03, 2021 @ 12:46
    Hubert
    0

    Hijacking DocumentType permissions

    Hi

    short version:

    Is there any 'child type provider' in Umbraco? I'd like to filter out (or even replace) available child types for some nodes.

    long version with an explanation:

    My most common scenario for this is a virtual root node for some collection. The node itself is empty and exists only to provide a hierarchy. For example:

    Home (http://mysite.com)

    -> Products (http://mysite.com/products)

    -->Product A (http://mysite.com/products/productA)

    --> Product B (http://mysite.com/products/productB)

    The Products page does not carry any information and its only function is to organize content. Its URL is not listed anywhere, but end-user can easily navigate to it by editing ProductA URL.

    My implementation is very simple - I call it Redirector and it's just an empty DocumentType with a Template responsible to call Response.Redirect to the first child node of the model.

    So far, so good - things work as expected.

    Now for the Permissions - it needs to be permitted in some parent context (ie. Home) and it needs to have some allowed children (ie. ProductPage).

    Things are pretty smooth, but then there is another similar case - Legal. I need to add a new child type (ie. LegalPage) to my Redirector.

    Technically it works, but nothing restricts unaware Editor from adding LegalPages to Product nodes and vice versa.

    To avoid this risk I'll have to create separated Product and Legal document types and let them add only one type of child. In the case of 2 "virtual" nodes, it may be acceptable, in case of more - it'll soon generate a mess.

    Ideally, my Redirector should have a property to select the allowed child types, so now, we return to my question:

    How to intercept the process of getting the list of possible child types? Is there any AllowedChildTypesProvider (TM) in Umbraco?

    EDIT: After a quick review of the Umbraco sources, it seems that a good starting point will be to override the ContentTypeController's GetAllowedChildren method (URL: /umbraco/backoffice/UmbracoApi/ContentType/GetAllowedChildren).

    The code of this method seems to be ideal starting point for my needs, however I have no idea how to replace Umbraco's internal API controller call with my own?

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Sep 03, 2021 @ 13:38
    Patrick de Mooij
    0

    I've created a pull request to allow this sort of logic: https://github.com/umbraco/Umbraco-CMS/pull/9906. Unfortunately it has not been merged yet.

    However, this reply talks about a way to intercept the response so that you can still modify it before this change has been merged: https://github.com/umbraco/Umbraco-CMS/pull/9906#issuecomment-787547487.

  • Hubert 9 posts 39 karma points
    Sep 03, 2021 @ 13:55
    Hubert
    0

    Exactly what I need without hacking the controllers

    +1 for merge :)

Please Sign in or register to post replies

Write your reply to:

Draft