Class: ViewModel::AccessControl::Tree::Node

Inherits:
Composed show all
Defined in:
lib/view_model/access_control/tree.rb

Constant Summary

Constants included from Callbacks

Callbacks::ALWAYS

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Composed

each_check, edit_valid_if!, edit_valid_unless!, editable_if!, editable_unless!, include_from, initialize_as_composed_access_control, inspect, new_permission_check, #valid_edit_check, visible_if!, visible_unless!

Methods inherited from ViewModel::AccessControl

#editable!, #valid_edit_check, #visible!

Methods included from Callbacks

#ineligible, #run_callback, wrap_deserialize, wrap_serialize

Constructor Details

#initialize(tree_access_control) ⇒ Node

Returns a new instance of Node.



204
205
206
207
# File 'lib/view_model/access_control/tree.rb', line 204

def initialize(tree_access_control)
  super()
  @tree_access_control = tree_access_control
end

Class Attribute Details

.root_children_editable_ifsObject (readonly)

Returns the value of attribute root_children_editable_ifs.



147
148
149
# File 'lib/view_model/access_control/tree.rb', line 147

def root_children_editable_ifs
  @root_children_editable_ifs
end

.root_children_editable_unlessesObject (readonly)

Returns the value of attribute root_children_editable_unlesses.



147
148
149
# File 'lib/view_model/access_control/tree.rb', line 147

def root_children_editable_unlesses
  @root_children_editable_unlesses
end

.root_children_visible_ifsObject (readonly)

Returns the value of attribute root_children_visible_ifs.



147
148
149
# File 'lib/view_model/access_control/tree.rb', line 147

def root_children_visible_ifs
  @root_children_visible_ifs
end

.root_children_visible_unlessesObject (readonly)

Returns the value of attribute root_children_visible_unlesses.



147
148
149
# File 'lib/view_model/access_control/tree.rb', line 147

def root_children_visible_unlesses
  @root_children_visible_unlesses
end

Class Method Details

.inherited(subclass) ⇒ Object



152
153
154
155
# File 'lib/view_model/access_control/tree.rb', line 152

def inherited(subclass)
  super
  subclass.initialize_as_node
end

.initialize_as_nodeObject



157
158
159
160
161
162
163
164
# File 'lib/view_model/access_control/tree.rb', line 157

def initialize_as_node
  @root = false

  @root_children_editable_ifs      = []
  @root_children_editable_unlesses = []
  @root_children_visible_ifs       = []
  @root_children_visible_unlesses  = []
end

.inspect_checksObject



192
193
194
195
196
197
198
199
200
201
# File 'lib/view_model/access_control/tree.rb', line 192

def inspect_checks
  checks = super
  if root?
    checks << "root_children_visible_if: #{root_children_visible_ifs.map(&:reason)}"            if root_children_visible_ifs.present?
    checks << "root_children_visible_unless: #{root_children_visible_unlesses.map(&:reason)}"   if root_children_visible_unlesses.present?
    checks << "root_children_editable_if: #{root_children_editable_ifs.map(&:reason)}"          if root_children_editable_ifs.present?
    checks << "root_children_editable_unless: #{root_children_editable_unlesses.map(&:reason)}" if root_children_editable_unlesses.present?
  end
  checks
end

.root?Boolean Also known as: requires_root?

Returns:

  • (Boolean)


186
187
188
# File 'lib/view_model/access_control/tree.rb', line 186

def root?
  @root
end

.root_children_editable_if!(reason, &block) ⇒ Object



176
177
178
179
# File 'lib/view_model/access_control/tree.rb', line 176

def root_children_editable_if!(reason, &block)
  @root = true
  root_children_editable_ifs << new_permission_check(reason, &block)
end

.root_children_editable_unless!(reason, &block) ⇒ Object



181
182
183
184
# File 'lib/view_model/access_control/tree.rb', line 181

def root_children_editable_unless!(reason, &block)
  @root = true
  root_children_editable_unlesses << new_permission_check(reason, &block)
end

.root_children_visible_if!(reason, &block) ⇒ Object



166
167
168
169
# File 'lib/view_model/access_control/tree.rb', line 166

def root_children_visible_if!(reason, &block)
  @root = true
  root_children_visible_ifs << new_permission_check(reason, &block)
end

.root_children_visible_unless!(reason, &block) ⇒ Object



171
172
173
174
# File 'lib/view_model/access_control/tree.rb', line 171

def root_children_visible_unless!(reason, &block)
  @root = true
  root_children_visible_unlesses << new_permission_check(reason, &block)
end

Instance Method Details

#editable_check(traversal_env) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/view_model/access_control/tree.rb', line 228

def editable_check(traversal_env)
  view                = traversal_env.view
  deserialize_context = traversal_env.deserialize_context

  validate_root!(view, deserialize_context)

  if deserialize_context.root?
    save_root_editability!(traversal_env)
    super
  else
    root_editability = fetch_descendent_editability(deserialize_context.nearest_root_viewmodel)
    root_editability.merge { super }
  end
end

#visible_check(traversal_env) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/view_model/access_control/tree.rb', line 213

def visible_check(traversal_env)
  view    = traversal_env.view
  context = traversal_env.context

  validate_root!(view, context)

  if context.root?
    save_root_visibility!(traversal_env)
    super
  else
    root_visibility = fetch_descendent_visibility(context.nearest_root_viewmodel)
    root_visibility.merge { super }
  end
end