Module: AccountInitializer

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

Overview

Lesli

Copyright © 2025, Lesli Technologies, S. A.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see www.gnu.org/licenses/.

Lesli · Ruby on Rails SaaS Development Framework.

Made with ♥ by LesliTech Building a better future, one line of code at a time.

// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ // ·

Instance Method Summary collapse

Instance Method Details

#initialize_accountObject

initialize minimum resources needed for the account



37
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/account_initializer.rb', line 37

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_privileges
end

#initialize_enginesObject

initialize engines for new accounts



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

def initialize_engines

    LesliSystem.engines.each do |engine, data|

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

        # Skip if the engine is not defined
        next unless Object.const_defined?(engine)

        #next if self.public_send(attribute).blank?

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