Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
DeviseTokenAuth::Concerns::User
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.stove_adminObject


34
35
36
# File 'app/models/user.rb', line 34

def self.stove_admin
  self.admin.first
end

Instance Method Details

#remap_more_attributes(more_attributes, ingredient) ⇒ Object (private)

Re-assign deployment recommendation ingredient IDs in more_attributes to match the all_leafs IDs of ingredient. Assumption: all_leafs follows the same order as more_attributes['ingredients']


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/user.rb', line 61

def remap_more_attributes(more_attributes, ingredient)
  new_more_attributes = more_attributes
  new_leaf_ids = ingredient.all_leafs.map(&:id)
  new_mappings = {}
  if more_attributes['ingredients'].present?
    more_attributes['ingredients'].values.each_with_index do |resource, index|
      new_id = new_leaf_ids[index]
      new_mappings[new_id] = resource
    end
    new_more_attributes['ingredients'] = new_mappings
    new_more_attributes
  else
    more_attributes
  end
end

#seed_userObject (private)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/user.rb', line 40

def seed_user
  unless Rails.env.test? || self.is_admin
    # Use application from first admin user as seed for new users
    admin = User.admin.first
    app = (admin.ingredients.select { |i| i.application_root? && !i.is_template }).first
    app_copy = app.copy
    app_copy.assign_user!(self)
    app.deployment_recommendations.each do |recommendation|
      app_copy.deployment_recommendations << DeploymentRecommendation.create(
        status: recommendation.status,
        num_simultaneous_users: recommendation.num_simultaneous_users,
        more_attributes: remap_more_attributes(recommendation.more_attributes, app_copy),
        user: self
      )
    end
  end
end