Skip to content

Commit

Permalink
fix: check condition on can_approve
Browse files Browse the repository at this point in the history
  • Loading branch information
matthv committed Nov 18, 2024
1 parent 9e82785 commit 4cab4e8
Showing 1 changed file with 9 additions and 3 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 @@ -35,7 +35,7 @@ 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')
elsif @smart_action['approvalRequired'].include?(@user['roleId'])
approval_condition = @smart_action['approvalRequiredConditions'].find { |c| c['roleId'] }
approval_condition = condition_by_role_id(@smart_action['approvalRequiredConditions'])

if approval_condition.blank? || match_conditions('approvalRequiredConditions')
raise ForestLiana::Ability::Exceptions::RequireApproval.new(@smart_action['userApprovalEnabled'])
Expand All @@ -50,7 +50,7 @@ def can_trigger?
def match_conditions(condition_name)
begin
attributes = @parameters[:data][:attributes]
condition = @smart_action[condition_name].find { |c| c['roleId'] == @user['roleId'] }
condition = condition_by_role_id(@smart_action[condition_name])

records = FiltersParser.new(
condition['filter'],
Expand All @@ -71,6 +71,12 @@ def match_conditions(condition_name)
raise ForestLiana::Ability::Exceptions::ActionConditionError.new
end
end

private

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

0 comments on commit 4cab4e8

Please sign in to comment.