Sometimes, a policy condition can be very long, making the code ugly when formatted and hard to follow, for example:
policy [
action([
:action_1,
:action_2,
:action_3,
:action_4,
:action_5,
:action_6,
:action_7,
:action_8,
:action_9,
:action_10
]),
expr(field = "bla"),
expr(some_other_field = :admin)
] do
authorize_if Check1
forbid_if Check2
authorize_if Check3
authorize_if Check4
end
Can’t we allow the policy condition to be defined inside the policy code block in these cases to make things easier?
Example:
policy do
condition [
action([
:action_1,
:action_2,
:action_3,
:action_4,
:action_5,
:action_6,
:action_7,
:action_8,
:action_9,
:action_10
]),
expr(field = "bla"),
expr(some_other_field = :admin)
]
authorize_if Check1
forbid_if Check2
authorize_if Check3
authorize_if Check4
end
or how I personally would write this:
policy do
@actions [
:action_1,
:action_2,
:action_3,
:action_4,
:action_5,
:action_6,
:action_7,
:action_8,
:action_9,
:action_10
]
condition([action(@actions), expr(field = "bla"), expr(some_other_field = :admin)])
authorize_if(Check1)
forbid_if(Check2)
authorize_if(Check3)
authorize_if(Check4)
end
This would work similarly to how a calculate
call accepts a calculation
call inside the code block too.