How to limit to one node per user ?

Created on 19 January 2025, 1 day ago

I have a node type "profile". I want a user with the role "premium" to be able to create only one node of this type. If the user tries to create another node of the same type:

- Access denied, when displaying the creation form. OR. Redirect to the user's already existing node.

- Display an error message, "You have reached the limit".

How can I do this ? Do you have an example to import ?

💬 Support request
Status

Active

Version

2.1

Component

Documentation

Created by

🇫🇷France zenimagine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @zenimagine
  • 🇩🇪Germany jurgenhaas Gottmadingen

    You could start with the Controller found to handle request event, check for the path if the user is trying to create a profile. Then you can try and load a profile entity with the Entity: load action by load it by property with the author ID being the current user.

    If that action can't find any such entity, then the ECA model finishes automatically. If it does, however, that means that such a profile already exists and you can continue by redirecting to a different page and output a message.

  • 🇫🇷France zenimagine

    I don't know how to create this rule, can you tell me if it's a good start?

    I don't know what to put for "profile exists".

  • 🇩🇪Germany jurgenhaas Gottmadingen

    As I mentioned in #2 you want to load that entity by properties. So you have to select that type. In the Property values field you will then have to define your property in yaml syntax on how to find a previous node of the current user. Probably something like:

    uid: "[user:uid]"
    type: "profile"
    

    Tip: if you could provide screenshots in English, then more people will have a chance in reading them. You can also embed the screenshots so that they're visible without having to open them separately. Just a bit of best practice which makes free support a bit more efficient.

  • 🇫🇷France zenimagine

    @jurgenhaas Would you have an archive to import? For example for the content type "article".

    It would be possible to create only one content of type "article" per user (with the role "content_editor").

  • 🇩🇪Germany jurgenhaas Gottmadingen

    Maybe some day, but I can't do that soon. All required information is provided above, so maybe someone will be able to build such a model.

Production build 0.71.5 2024