Class: Lesli::DescriptorPrivilegeOperator

Inherits:
ApplicationLesliService show all
Defined in:
app/operators/lesli/descriptor_privilege_operator.rb

Instance Method Summary collapse

Methods inherited from ApplicationLesliService

#create, #delete, #error, #errors, #errors_as_sentence, #find, #found?, #index, #list, #result, #show, #successful?, #update

Constructor Details

#initialize(descriptor) ⇒ DescriptorPrivilegeOperator

Returns a new instance of DescriptorPrivilegeOperator.



38
39
40
# File 'app/operators/lesli/descriptor_privilege_operator.rb', line 38

def initialize descriptor
    @descriptor = descriptor
end

Instance Method Details

#add_owner_privileges(descriptor) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'app/operators/lesli/descriptor_privilege_operator.rb', line 65

def add_owner_privileges(descriptor)

    # Adding default system actions for profile descriptor
    actions = SystemController::Action.all 

    actions.each do |action|
        descriptor.privileges.find_or_create_by(action: action)
    end
end

#add_profile_privileges(descriptor) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/operators/lesli/descriptor_privilege_operator.rb', line 42

def add_profile_privileges(descriptor)

    # Adding default system actions for profile descriptor
    [
        { controller: "lesli_admin/profiles", actions: ["show"] },      # enable profile view
        { controller: "lesli/users", actions: ["options", "update"] },  # enable user edition
        { controller: "lesli/abouts", actions: ["show"] },              # system status
        { controller: "lesli/user/sessions", actions: ["index"] }       # session management
    ].each do |controller_action|

        controller_action[:actions].each do |action_name|

            system_controller_action = SystemController::Action.joins(:system_controller)
            .where("lesli_system_controllers.route = ?", controller_action[:controller])
            .where("lesli_system_controller_actions.name = ?", action_name)

            descriptor.privileges.find_or_create_by(
                action: system_controller_action.first
            )
        end
    end
end