Class: LesliGuard::Descriptor::PrivilegesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/lesli_guard/descriptor/privileges_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /descriptor/privileges



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/lesli_guard/descriptor/privileges_controller.rb', line 50

def create

    descriptor_privilege_status = false

    # search for the privilege we want to add/update
    
    # if the privilege does not exist, we are going to create the privilege
    descriptor_privilege = @descriptor.privileges.with_deleted.find_by(
        :action_id => descriptor_privilege_params[:action_id]
    )

    # if the privilege exist, we are going to update the privilege
    if not descriptor_privilege
        pp "if not descriptor_privilege"
        descriptor_privilege = @descriptor.privileges.new(
            :action_id => descriptor_privilege_params[:action_id]
        )
        descriptor_privilege_status = descriptor_privilege.save
    elsif !descriptor_privilege.deleted?
        pp "elsif !descriptor_privilege.deleted?"
        descriptor_privilege_status = descriptor_privilege.delete
    elsif descriptor_privilege.deleted?
        pp "elsif descriptor_privilege.deleted?"
        descriptor_privilege_status = descriptor_privilege.recover
    end

    if descriptor_privilege_status
        #Role::Activity.log_create_descriptor(current_user, @role, role_descriptor)
        respond_with_successful(descriptor_privilege)
    else
        respond_with_error(descriptor_privilege.errors.full_messages.to_sentence)
    end
end

#destroyObject

DELETE /descriptor/privileges/1



85
86
87
88
89
90
91
# File 'app/controllers/lesli_guard/descriptor/privileges_controller.rb', line 85

def destroy
    if @descriptor_privilege.destroy
        respond_with_successful
    else
        respond_with_error(@descriptor_privilege.errors.full_messages.to_sentence)
    end
end

#indexObject

GET /descriptor/privileges



40
41
42
43
44
45
46
47
# File 'app/controllers/lesli_guard/descriptor/privileges_controller.rb', line 40

def index
    respond_to do |format|
        format.html {}
        format.json do
            respond_with_successful(DescriptorPrivilegeService.new(current_user, @query).index(params))
        end
    end
end