@@ -22,7 +22,7 @@ def can_execute?
2222
2323 def can_approve?
2424 @parameters = RequestPermission . decodeSignedApprovalRequest ( @parameters )
25- if ( ( @smart_action [ 'userApprovalConditions' ] . empty ? || match_conditions ( 'userApprovalConditions' ) ) &&
25+ if ( ( condition_by_role_id ( @smart_action [ 'userApprovalConditions' ] ) . blank ? || match_conditions ( 'userApprovalConditions' ) ) &&
2626 ( @parameters [ :data ] [ :attributes ] [ :requester_id ] != @user [ 'id' ] || @smart_action [ 'selfApprovalEnabled' ] . include? ( @user [ 'roleId' ] ) )
2727 )
2828 return true
@@ -33,12 +33,12 @@ def can_approve?
3333
3434 def can_trigger?
3535 if @smart_action [ 'triggerEnabled' ] . include? ( @user [ 'roleId' ] ) && @smart_action [ 'approvalRequired' ] . exclude? ( @user [ 'roleId' ] )
36- return true if @smart_action [ 'triggerConditions' ] . empty ? || match_conditions ( 'triggerConditions' )
36+ return true if condition_by_role_id ( @smart_action [ 'triggerConditions' ] ) . blank ? || match_conditions ( 'triggerConditions' )
3737 elsif @smart_action [ 'approvalRequired' ] . include? ( @user [ 'roleId' ] )
38- if @smart_action [ 'approvalRequiredConditions' ] . empty ? || match_conditions ( 'approvalRequiredConditions' )
38+ if condition_by_role_id ( @smart_action [ 'approvalRequiredConditions' ] ) . blank ? || match_conditions ( 'approvalRequiredConditions' )
3939 raise ForestLiana ::Ability ::Exceptions ::RequireApproval . new ( @smart_action [ 'userApprovalEnabled' ] )
4040 else
41- return true if @smart_action [ 'triggerConditions' ] . empty ? || match_conditions ( 'triggerConditions' )
41+ return true if condition_by_role_id ( @smart_action [ 'triggerConditions' ] ) . blank ? || match_conditions ( 'triggerConditions' )
4242 end
4343 end
4444
@@ -48,8 +48,10 @@ def can_trigger?
4848 def match_conditions ( condition_name )
4949 begin
5050 attributes = @parameters [ :data ] [ :attributes ]
51+ condition = condition_by_role_id ( @smart_action [ condition_name ] )
52+
5153 records = FiltersParser . new (
52- @smart_action [ condition_name ] [ 0 ] [ 'filter' ] ,
54+ condition [ 'filter' ] ,
5355 @collection ,
5456 @parameters [ :timezone ] ,
5557 @parameters
@@ -67,6 +69,10 @@ def match_conditions(condition_name)
6769 raise ForestLiana ::Ability ::Exceptions ::ActionConditionError . new
6870 end
6971 end
72+
73+ def condition_by_role_id ( condition )
74+ condition . find { |c | c [ 'roleId' ] == @user [ 'roleId' ] }
75+ end
7076 end
7177 end
7278 end
0 commit comments