Module: RestrictionCalculator::Implementation

Defined in:
backend/app/model/mixins/restriction_calculator.rb

Class Method Summary collapse

Class Method Details

.expand_to_tree(model, id_set) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'backend/app/model/mixins/restriction_calculator.rb', line 69

def self.expand_to_tree(model, id_set)
  return {model => id_set} unless model.included_modules.include?(TreeNodes)

  rec_ids = id_set
  new_rec_ids = rec_ids

  while true
    new_rec_ids = model.filter(:id => new_rec_ids).select(:parent_id).map(&:parent_id).compact

    if new_rec_ids.empty?
      break
    else
      rec_ids += new_rec_ids
    end
  end

  rec_ids = rec_ids.uniq

  {
    model => rec_ids,
    model.root_model => model.filter(:id => rec_ids).select(:root_record_id).distinct.map(&:root_record_id)
  }
end