Preface
You added an interesting comment below your question, part of it is like so:
All users is registered via Keycloak and page will redirect to Drupal site after its successful registration. This redirected page is the custom view plugin created. For users to be able to add its company details. And so users will enter their VAT # to get data from the CVR Register. ...
Followed by this extra comment:
query/query?vat=12345678
. First 'query' is the sitename, then 2nd is the menu path name
So you have a relative path like in this example /query?vat=12345678
. And therefor the answer to your question (= Can this be achieve by Rules?) is Yes, Si, Oui, Ja ... Read on for more details to guide you ...
Solution
You may want to try the "Rules URL argument" module. Here is a quote about it (from its project page):
... provides two rules conditions based on URL arguments:
- check if a URL argument is present.
- compare the value of an URL argument.
It also provides an action that makes the value of an URL argument available as new variable to Rules.
The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.
For an example of how to use it, refer to Comment # 3 in issue # 1686360 which is about "Pass an amount to the url, ie; site/content/node-title?amount=10 or /node-title?=amount:10". Here is the relevant part of it:
- add a "Check if URL argument exist" condition to your rule and set the "ARGUMENT" value to "amount".
- add "Provide URL argument value" action to the rule and set "URL ARGUMENT NAME" value to "amount" and in the "Provided variables" section "ARGUMENT FROM URL - Variable name" to e.g. "
amount_from_url
".
You will now be able to use the amount value as a variable "amount-from-url
" for other actions in this rule.
So with that you can use Rules to (let's say) "monitor" the usage of that path by an authenticated user. Some more details about the custom rule you could create for this:
Rules Event: drupal is initializing (sorry, that's probably the only one that you would be able to use).
Rules Conditions (pick whatever fits, and/or mix however you want):
- user has a specific role (or the negation of it).
- check the current path (verify if it starts with
query
).
- check if URL argument
vat=
is present.
The only thing left to do is to think of something appropriate for some Rules Action(s) to be performed, knowing that you do have these crucial data available:
- the current user who tries to use this path again.
- the actual value (=
12345678
) that was used.
Obviously, at a minimum you'd want to add a Rules Action to perform an appropriate "redirect" if the 3 attempts have been used on the same day already.
You'd have to do some more homework/refinements, but here is a blueprint of a basic solution that could work:
Solution 1 (easiest approach to implement):
- Use the Flag module (eg with 3 none-global flags labeled like attempt 1, attempt 2 and attempt 3).
- Add a Rules Action to flag the user with the relevant flag (corresponding to the number of succeeded attempts before).
- Add an extra Rules Condition to verify that not all flags have been used (with the same flagging date!).
Solution 2 (= my recommended approach, though a bit tougher to implement): Use the Message module to create a custom activity log, to log each event where the actual URL has been used (with success). And improve the Rule above to add a rules condition to count the number of such messages (= custom activity log records) created already in the last 24 hours.
PS: I'm assuming this is about D7 ...