Class: Gitlab::CrossProjectAccess::CheckInfo
- Inherits:
-
Object
- Object
- Gitlab::CrossProjectAccess::CheckInfo
- Defined in:
- lib/gitlab/cross_project_access/check_info.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#negative_condition ⇒ Object
Returns the value of attribute negative_condition.
-
#positive_condition ⇒ Object
Returns the value of attribute positive_condition.
-
#skip ⇒ Object
Returns the value of attribute skip.
Instance Method Summary collapse
- #current_action(object) ⇒ Object
-
#initialize(actions, positive_condition, negative_condition, skip) ⇒ CheckInfo
constructor
A new instance of CheckInfo.
- #negative_condition_is_true?(object) ⇒ Boolean
- #positive_condition_is_false?(object) ⇒ Boolean
- #should_run?(object) ⇒ Boolean
- #should_skip?(object) ⇒ Boolean
Constructor Details
#initialize(actions, positive_condition, negative_condition, skip) ⇒ CheckInfo
Returns a new instance of CheckInfo.
8 9 10 11 12 13 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 8 def initialize(actions, positive_condition, negative_condition, skip) @actions = actions @positive_condition = positive_condition @negative_condition = negative_condition @skip = skip end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
6 7 8 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 6 def actions @actions end |
#negative_condition ⇒ Object
Returns the value of attribute negative_condition.
6 7 8 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 6 def negative_condition @negative_condition end |
#positive_condition ⇒ Object
Returns the value of attribute positive_condition.
6 7 8 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 6 def positive_condition @positive_condition end |
#skip ⇒ Object
Returns the value of attribute skip.
6 7 8 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 6 def skip @skip end |
Instance Method Details
#current_action(object) ⇒ Object
63 64 65 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 63 def current_action(object) object.respond_to?(:action_name) ? object.action_name.to_sym : nil end |
#negative_condition_is_true?(object) ⇒ Boolean
59 60 61 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 59 def negative_condition_is_true?(object) @negative_condition && object.instance_exec(&@negative_condition) end |
#positive_condition_is_false?(object) ⇒ Boolean
55 56 57 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 55 def positive_condition_is_false?(object) @positive_condition && !object.instance_exec(&@positive_condition) end |
#should_run?(object) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 35 def should_run?(object) return !should_skip?(object) if @skip run_for_action = @actions[current_action(object)] run_for_action = true if @actions[current_action(object)].nil? # We need to do the opposite of what was defined in the following cases: # - requires_cross_project_access index: true, if: -> { false } # - requires_cross_project_access index: true, unless: -> { true } if positive_condition_is_false?(object) run_for_action = !run_for_action end if negative_condition_is_true?(object) run_for_action = !run_for_action end run_for_action end |
#should_skip?(object) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/cross_project_access/check_info.rb', line 15 def should_skip?(object) return !should_run?(object) unless @skip skip_for_action = @actions[current_action(object)] skip_for_action = false if @actions[current_action(object)].nil? # We need to do the opposite of what was defined in the following cases: # - skip_cross_project_access_check index: true, if: -> { false } # - skip_cross_project_access_check index: true, unless: -> { true } if positive_condition_is_false?(object) skip_for_action = !skip_for_action end if negative_condition_is_true?(object) skip_for_action = !skip_for_action end skip_for_action end |