Module: Lesli::AccountInitializer

Extended by:
ActiveSupport::Concern
Included in:
Account
Defined in:
app/models/concerns/lesli/account_initializer.rb

Instance Method Summary collapse

Instance Method Details

#initialize_accountObject

initialize minimum resources needed for the account



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/concerns/lesli/account_initializer.rb', line 38

def 


    # create default roles for the new account
    owner = self.roles
    .create_with({ permission_level: 2147483647 })
    .find_or_create_by(:name => "owner")


    # platform administrator role
    admin = self.roles
    .create_with({ permission_level: 100000})
    .find_or_create_by(name: "admin")


    # access only to user profile
    limited = self.roles
    .create_with({ permission_level: 10, path_default: "/administration/profile" })
    .find_or_create_by(name: "limited")


    # Add base privileges to roles
    Lesli::RoleOperator.new(owner).add_owner_actions
    Lesli::RoleOperator.new(admin).add_owner_actions
    Lesli::RoleOperator.new(limited).add_profile_actions

end

#initialize_enginesObject

initialize engines for new accounts



68
69
70
71
72
73
74
75
76
77
# File 'app/models/concerns/lesli/account_initializer.rb', line 68

def initialize_engines

    LesliSystem.engines.each do |engine, data|

        next if ["Lesli", "LesliBabel", "Root"].include?(engine)

        # Create an associated account if the attribute is blank
        engine.constantize::Account.create!(account: self)
    end
end