View if User-ID or User-Mail-Address is identical otherwise redirect

Created on 31 May 2023, over 1 year ago
Updated 3 August 2023, about 1 year ago

Problem/Motivation

We are so happy with the ECA-module - it really works perfectly for us - thank you so much!!
We only have one last issue - we are sure you can help us to find a solution.

We have the following case:
Student is creating a request (special content type) and is inserting the ID and/or mail-adress of the teacher.
Only the teacher with the correct ID [current-user:id] and/or mail-adress [current-user:mail] should be able to open and view this request. All the other teachers should be redirected to the front page with a short display message.

We created this rule but it is not working (the tokens are not working).
It doesn't matter if the correct ID oder mail-adress was inserted.
When you first try to open the request you get redirected to the front page, when you do it a second time then you can open all the requests - it doesn't matter what is inserted.

Do you have an idea, what we can use/how we can create a suitable model in ECA?

Thank you so much for your support!

๐Ÿ’ฌ Support request
Status

Closed: outdated

Version

1.1

Component

Miscellaneous

Created by

๐Ÿ‡ฆ๐Ÿ‡นAustria simone.gritsch

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

Comments & Activities

  • Issue created by @simone.gritsch
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    That sounds like your model is getting in conflict with caching.

    Could you please confirm that if you flush all caches, that it works once afterwards, and then it doesn't any more? Is this reproducible?

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria simone.gritsch

    Hi Jรผrgen,
    thanks for your quick response. I tried flushing the cache, but not really with a satisfying outcome.
    My user-id was inserted in the id-field so my user should be able to open the request.
    On the first click I got redirected.
    On the second click I can open the request.
    When I delete the cache on the first click I get redirected again altough I should be able to see it.

    How would you build the ECA-model?
    We used "view content entity" and "Compare field value" with expected field value [current-user:id].

    Thank you!

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    The event view content entity is not what you want at this point, as it's not just dispatched when viewing the node's canonical page. This event is triggered whenever an entity gets rendered for viewing, i.e. if you have a view that lists entities, this event gets dispatched for each contained entity in that view.

    The described use case seems to be about a http request to the canonical page of a node, e.g. /node/1234

    For that, you should start with the Controller found to handle request event and then use a condition Route match to check if the request is for the Route name = entity.node.canonical. If true, you can then load the node into a token with the Token: load route parameter to continue with that for further processing.

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria simone.gritsch

    Hi Jรผrgen,
    we tried your suggestion today but are really unsure what we have to insert in the fields: Name of route parameter and: Name des Tokens.
    Moreover we are not sure how the routine is validating which user is trying to access the data.

    Would it be possible to contact you directly for support? Or is there a documentation where this kind of case is documented?

    We really appreciate your support!!
    All the best

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen

    we tried your suggestion today but are really unsure what we have to insert in the fields: Name of route parameter and: Name des Tokens.

    That should be node. The routes in Drupal are defined like e.g. /node/{node}/edit where the {node} is a route parameter that can be used.

    Moreover we are not sure how the routine is validating which user is trying to access the data.

    There is always a token current_user which contains the user entity of the current user.

    Would it be possible to contact you directly for support? Or is there a documentation where this kind of case is documented?

    Best way is asking questions here, to refer to the ECA Guide and maybe also ask questions in the ECA channel on Drupal Slack, where many other users are online as well, who can help.

  • Status changed to Postponed: needs info over 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen
  • Status changed to Closed: outdated about 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jurgenhaas Gottmadingen
Production build 0.71.5 2024