I'm trying to store rules for web requests in a JSON object and am having trouble thinking of a good structure. Here are some examples of my rules:
Possible Conditions
the user must be logged in
the user must belong to an account of type [____]
the user must belong to an account named [___]
the user must have a username [___]
the user must have the account role [___]
the current time must be between [___] and [___]
the variable [___] must be set to [___]
Possible Success Actions
allow access to the requested view
redirect to download a specific file
Possible Failure Actions
redirect to a certain view to display reasons why access was denied
redirect to a purchase page
redirect to a login page with a notice explaining why access was denied
I need to store multiple rules in a single object. I also need to be able to store boolean relationships like this:
(rule1 && rule2) || rule3
Object structure normally comes easy to me, but I'm struggling putting this together. Here's an example of a requirement the JSON object should be able to store:
A user can access the control panel if they are logged in and belong to an account named "Owners". If the user has the account role "Employee" then they can only login during Monday-Friday, not weekends. If the user has the name "root" they can login regardless of any other rule. If none of the rules succeed, then redirect the user to a page telling them specifically why they are unable to get to the control panel. E.g., "It's the weekend and you are only allowed to login Monday-Friday."