Skip to content

Commit

Permalink
fix(permission): get approval conditions by role id (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthv authored Nov 18, 2024
1 parent 9af9bcb commit 73d9874
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def can_execute?

def can_approve?
@parameters = RequestPermission.decodeSignedApprovalRequest(@parameters)
if ((@smart_action['userApprovalConditions'].empty? || match_conditions('userApprovalConditions')) &&
if ((condition_by_role_id(@smart_action['userApprovalConditions']).blank? || match_conditions('userApprovalConditions')) &&
(@parameters[:data][:attributes][:requester_id] != @user['id'] || @smart_action['selfApprovalEnabled'].include?(@user['roleId']))
)
return true
Expand All @@ -33,12 +33,12 @@ def can_approve?

def can_trigger?
if @smart_action['triggerEnabled'].include?(@user['roleId']) && @smart_action['approvalRequired'].exclude?(@user['roleId'])
return true if @smart_action['triggerConditions'].empty? || match_conditions('triggerConditions')
return true if condition_by_role_id(@smart_action['triggerConditions']).blank? || match_conditions('triggerConditions')
elsif @smart_action['approvalRequired'].include?(@user['roleId'])
if @smart_action['approvalRequiredConditions'].empty? || match_conditions('approvalRequiredConditions')
if condition_by_role_id(@smart_action['approvalRequiredConditions']).blank? || match_conditions('approvalRequiredConditions')
raise ForestLiana::Ability::Exceptions::RequireApproval.new(@smart_action['userApprovalEnabled'])
else
return true if @smart_action['triggerConditions'].empty? || match_conditions('triggerConditions')
return true if condition_by_role_id(@smart_action['triggerConditions']).blank? || match_conditions('triggerConditions')
end
end

Expand All @@ -48,8 +48,10 @@ def can_trigger?
def match_conditions(condition_name)
begin
attributes = @parameters[:data][:attributes]
condition = condition_by_role_id(@smart_action[condition_name])

records = FiltersParser.new(
@smart_action[condition_name][0]['filter'],
condition['filter'],
@collection,
@parameters[:timezone],
@parameters
Expand All @@ -67,6 +69,10 @@ def match_conditions(condition_name)
raise ForestLiana::Ability::Exceptions::ActionConditionError.new
end
end

def condition_by_role_id(condition)
condition.find { |c| c['roleId'] == @user['roleId'] }
end
end
end
end
Expand Down

0 comments on commit 73d9874

Please sign in to comment.