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
# File 'app/models/concerns/lesli/account_initializer.rb', line 38

def 

    # platform role for owners
    owner = self.roles
    .create_with({ permission_level: 2147483647 })
    .find_or_create_by(:name => "owner")

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

    # platform role for guests
    guest = self.roles
    .create_with({ permission_level: 10, path_default: "/administration/profile" })
    .find_or_create_by(name: "guest")


    # Add base privileges to roles
    if defined?(LesliShield)
        LesliShield::RoleActionService.new(nil).add_owner_actions(owner)
        LesliShield::RoleActionService.new(nil).add_owner_actions(admin)
        LesliShield::RoleActionService.new(nil).add_guest_actions(guest)
    end
end

#initialize_enginesObject

initialize engines for new accounts



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

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.find_or_create_by!(account: self)

        self.log(:account_initialization, "Engine: #{engine} initialized successfully")
    end
end