Class: Lesli::Role::ActionService

Inherits:
ApplicationLesliService show all
Defined in:
app/services/lesli/role/action_service.rb

Instance Method Summary collapse

Methods inherited from ApplicationLesliService

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

Constructor Details

This class inherits a constructor from Lesli::ApplicationLesliService

Instance Method Details

#clean(action) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/services/lesli/role/action_service.rb', line 11

def clean action 
    {
        :id => action.id,
        :role_id => action.role_id,
        :action_id => action.action_id,
        :deleted_at => action.deleted_at,
        :active => action.active
    }
end

#find(id) ⇒ Object



4
5
6
7
# File 'app/services/lesli/role/action_service.rb', line 4

def find id
    #super(current_user.account.users.joins(:detail).find_by(id: id))
    super(Lesli::Role::Action.with_deleted.find(id))
end

#index(role_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
63
64
65
66
67
68
69
70
71
72
73
# File 'app/services/lesli/role/action_service.rb', line 9

def index role_id

    def clean action 
        {
            :id => action.id,
            :role_id => action.role_id,
            :action_id => action.action_id,
            :deleted_at => action.deleted_at,
            :active => action.active
        }
    end

    role_actions = {}

    Lesli::Role::Action.with_deleted.joins(system_controller_action: :system_controller)
    .where(:role_id => role_id)
    .select(
        :id,
        :role_id,
        :action_id,
        :deleted_at,
        "lesli_system_controllers.id as controller_id",
        "lesli_system_controllers.name as controller_name",
        "lesli_system_controller_actions.name as controller_action_name",
        "case when lesli_role_actions.deleted_at is null then TRUE else FALSE end active"
    ).each do |action|

        unless role_actions.has_key?(action[:controller_name])
            role_actions[action[:controller_name]] = {
                list:nil,
                index: nil,
                show:nil,
                create:nil,
                update:nil,
                destroy:nil
            }
        end

        if  action[:controller_action_name] == "list"
            role_actions[action[:controller_name]][:list] = clean(action)
        end

        if  action[:controller_action_name] == "index"
            role_actions[action[:controller_name]][:index] = clean(action)
        end

        if  action[:controller_action_name] == "show"
            role_actions[action[:controller_name]][:show] = clean(action)
        end

        if  action[:controller_action_name] == "create"
            role_actions[action[:controller_name]][:create] = clean(action)
        end

        if  action[:controller_action_name] == "update"
            role_actions[action[:controller_name]][:update] = clean(action)
        end

        if  action[:controller_action_name] == "destroy"
            role_actions[action[:controller_name]][:destroy] = clean(action)
        end
    end

    role_actions
end