Class: ForemanDatacenter::ApplicationController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForemanDatacenter::ApplicationController
show all
- Defined in:
- app/controllers/foreman_datacenter/application_controller.rb
Direct Known Subclasses
CommentsController, ConsolePortTemplatesController, ConsolePortsController, ConsoleServerPortTemplatesController, ConsoleServerPortsController, DeviceBayTemplatesController, DeviceBaysController, DeviceInterfaceConnectionsController, DeviceInterfacesController, DeviceModulesController, DeviceRolesController, DeviceTypesController, DevicesController, InterfaceTemplatesController, ManagementDevicesController, ManufacturersController, PlatformsController, PowerOutletTemplatesController, PowerOutletsController, PowerPortTemplatesController, PowerPortsController, RackGroupsController, RacksController, SitesController
Instance Method Summary
collapse
Instance Method Details
#action_permission ⇒ Object
def resource_base_search_and_page(tables = [])
base = tables.empty? ? resource_base_with_search : resource_base_with_search.eager_load(*tables)
base.paginate(:page => params[:page], :per_page => params[:per_page])
end
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 73
def action_permission
case params[:action]
when 'new_connection'
'new_connection'
when 'connect'
'connect'
when 'planned'
'planned'
when 'connected'
'connected'
when 'disconnect'
'disconnect'
when 'populate_new'
'populate_new'
when 'depopulate'
'depopulate'
when 'populate'
'populate'
when 'move'
'move'
when 'racks'
'racks'
else
super
end
end
|
#controller_permission ⇒ Object
29
30
31
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 29
def controller_permission
controller_name
end
|
#find_resource ⇒ Object
14
15
16
17
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 14
def find_resource
instance_variable_set("@#{resource_name}",
resource_finder(resource_scope, params[:id]))
end
|
#not_found(exception = nil) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 5
def not_found(exception = nil)
logger.debug "not found: #{exception}" if exception
respond_to do |format|
format.html { render "foreman_datacenter/common/404", :status => :not_found }
format.any { head :not_found}
end
true
end
|
#resource_class ⇒ Object
37
38
39
40
41
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 37
def resource_class
@resource_class ||= resource_class_for(resource_name)
raise NameError, "Could not find resource class for resource #{resource_name}" if @resource_class.nil?
@resource_class
end
|
#resource_class_for(resource) ⇒ Object
61
62
63
64
65
66
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 61
def resource_class_for(resource)
klass = "ForemanDatacenter::#{resource.classify}".constantize
klass
rescue NameError
nil
end
|
#resource_finder(scope, id) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 19
def resource_finder(scope, id)
raise ActiveRecord::RecordNotFound if scope.empty?
result = scope.from_param(id) if scope.respond_to?(:from_param)
begin
result ||= scope.friendly.find(id) if scope.respond_to?(:friendly)
rescue ActiveRecord::RecordNotFound
end
result || scope.find(id)
end
|
#resource_name(resource = controller_name) ⇒ Object
33
34
35
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 33
def resource_name(resource = controller_name)
resource.singularize
end
|
#resource_scope(options = {}) ⇒ Object
43
44
45
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 43
def resource_scope(options = {})
@resource_scope ||= scope_for(resource_class, options)
end
|
#scope_for(resource, options = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/foreman_datacenter/application_controller.rb', line 47
def scope_for(resource, options = {})
controller = options.delete(:controller){ controller_permission }
permission = options.delete(:permission)
if resource.respond_to?(:authorized)
permission ||= "#{action_permission}_#{controller}"
resource = resource.authorized(permission, resource)
end
resource.where(options)
end
|