erp_app 3.0.13 → 3.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/app/controllers/erp_app/desktop/audit_log_viewer/base_controller.rb +1 -1
  2. data/app/controllers/erp_app/desktop/file_manager/base_controller.rb +5 -5
  3. data/app/controllers/erp_app/desktop/scaffold/role_controller.rb +1 -1
  4. data/app/controllers/erp_app/desktop/security_management/base_controller.rb +47 -0
  5. data/app/controllers/erp_app/desktop/security_management/capabilities_controller.rb +129 -0
  6. data/app/controllers/erp_app/desktop/security_management/groups_controller.rb +201 -0
  7. data/app/controllers/erp_app/desktop/security_management/roles_controller.rb +188 -0
  8. data/app/controllers/erp_app/desktop/security_management/users_controller.rb +145 -0
  9. data/app/controllers/erp_app/desktop/user_management/base_controller.rb +2 -2
  10. data/app/controllers/erp_app/desktop/user_management/role_management_controller.rb +6 -6
  11. data/app/controllers/erp_app/public_controller.rb +3 -14
  12. data/app/models/application.rb +1 -10
  13. data/app/models/configuration_item_type.rb +1 -1
  14. data/app/models/configuration_option.rb +1 -1
  15. data/app/models/widget.rb +2 -11
  16. data/config/routes.rb +6 -3
  17. data/db/data_migrations/20110728201729_erp_app_setup.rb +2 -48
  18. data/db/data_migrations/20110816161238_create_desktop_app_audit_log_viewer.rb +4 -1
  19. data/db/data_migrations/20111108183739_add_default_capabilities.rb +11 -18
  20. data/db/data_migrations/20111108183740_add_new_contact_widgets.rb +4 -13
  21. data/db/data_migrations/20120229160222_add_userinfo_widget.rb +6 -8
  22. data/db/data_migrations/20120418164215_create_configuration_management_desktop_application.rb +4 -0
  23. data/db/data_migrations/20121130201859_upgrade_remove_system_mgmt_app.rb +15 -0
  24. data/db/data_migrations/20121218175028_create_security_management_desktop_application.rb +28 -0
  25. data/lib/erp_app/engine.rb +5 -5
  26. data/lib/erp_app/extensions/railties/action_view/helpers/include_helper.rb +4 -3
  27. data/lib/erp_app/extensions/railties/action_view/helpers/tag_helper.rb +8 -2
  28. data/lib/erp_app/version.rb +1 -1
  29. data/lib/erp_app/widgets/base.rb +4 -0
  30. data/lib/erp_app/widgets/loader.rb +40 -34
  31. data/public/images/icons/add/Thumbs.db +0 -0
  32. data/public/images/icons/calendar/Thumbs.db +0 -0
  33. data/public/images/icons/copy/Thumbs.db +0 -0
  34. data/public/images/icons/cut/Thumbs.db +0 -0
  35. data/public/images/icons/delete/Thumbs.db +0 -0
  36. data/public/images/icons/edit/Thumbs.db +0 -0
  37. data/public/images/icons/folder/Thumbs.db +0 -0
  38. data/public/images/icons/gear/Thumbs.db +0 -0
  39. data/public/images/icons/globe/Thumbs.db +0 -0
  40. data/public/images/icons/grid/Thumbs.db +0 -0
  41. data/public/images/icons/help/Thumbs.db +0 -0
  42. data/public/images/icons/information/Thumbs.db +0 -0
  43. data/public/images/icons/key/Thumbs.db +0 -0
  44. data/public/images/icons/log_out/Thumbs.db +0 -0
  45. data/public/images/icons/mail/Thumbs.db +0 -0
  46. data/public/images/icons/new/Thumbs.db +0 -0
  47. data/public/images/icons/next/Thumbs.db +0 -0
  48. data/public/images/icons/open/Thumbs.db +0 -0
  49. data/public/images/icons/paste/Thumbs.db +0 -0
  50. data/public/images/icons/picture/Thumbs.db +0 -0
  51. data/public/images/icons/presentation/Thumbs.db +0 -0
  52. data/public/images/icons/preview/Thumbs.db +0 -0
  53. data/public/images/icons/previous/Thumbs.db +0 -0
  54. data/public/images/icons/print/Thumbs.db +0 -0
  55. data/public/images/icons/properties/Thumbs.db +0 -0
  56. data/public/images/icons/redo/Thumbs.db +0 -0
  57. data/public/images/icons/refresh/Thumbs.db +0 -0
  58. data/public/images/icons/remove/Thumbs.db +0 -0
  59. data/public/images/icons/rename/Thumbs.db +0 -0
  60. data/public/images/icons/save/Thumbs.db +0 -0
  61. data/public/images/icons/search/Thumbs.db +0 -0
  62. data/public/images/icons/send/Thumbs.db +0 -0
  63. data/public/images/icons/settings/Thumbs.db +0 -0
  64. data/public/images/icons/synchronize/Thumbs.db +0 -0
  65. data/public/images/icons/undo/Thumbs.db +0 -0
  66. data/public/images/icons/upload/Thumbs.db +0 -0
  67. data/public/images/icons/user/Thumbs.db +0 -0
  68. data/public/images/icons/zoom_in/Thumbs.db +0 -0
  69. data/public/images/icons/zoom_out/Thumbs.db +0 -0
  70. data/public/javascripts/erp_app/authentication/compass_user.js +22 -19
  71. data/public/javascripts/erp_app/authentication/widget_manager.js +107 -107
  72. data/public/javascripts/erp_app/ckeditor/plugins/inlineeditsave/plugin.js +23 -23
  73. data/public/javascripts/erp_app/ckeditor/plugins/jwplayer/jwplayer/Thumbs.db +0 -0
  74. data/public/javascripts/erp_app/desktop/applications/file_manager/module.js +2 -2
  75. data/public/javascripts/erp_app/desktop/applications/security_management/capabilities_panel.js +82 -0
  76. data/public/javascripts/erp_app/desktop/applications/security_management/capabilities_widget.js +254 -0
  77. data/public/javascripts/erp_app/desktop/applications/security_management/groups_effective_security.js +98 -0
  78. data/public/javascripts/erp_app/desktop/applications/security_management/groups_panel.js +295 -0
  79. data/public/javascripts/erp_app/desktop/applications/security_management/groups_widget.js +254 -0
  80. data/public/javascripts/erp_app/desktop/applications/security_management/module.js +71 -0
  81. data/public/javascripts/erp_app/desktop/applications/security_management/roles_panel.js +298 -0
  82. data/public/javascripts/erp_app/desktop/applications/security_management/roles_widget.js +254 -0
  83. data/public/javascripts/erp_app/desktop/applications/security_management/users_effective_security.js +125 -0
  84. data/public/javascripts/erp_app/desktop/applications/security_management/users_panel.js +95 -0
  85. data/public/javascripts/erp_app/desktop/applications/security_management/users_widget.js +254 -0
  86. data/public/javascripts/erp_app/desktop/applications/user_management/module.js +38 -58
  87. data/public/javascripts/erp_app/organizer/applications/crm/base.js +698 -698
  88. data/public/javascripts/erp_app/organizer/applications/crm/contact_mechanism_grid.js +1 -4
  89. data/public/javascripts/erp_app/shared/compass_codemirror.js +1 -1
  90. data/public/javascripts/erp_app/shared/dynamic_editable_grid_loader_panel.js +1 -1
  91. data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_form_fields.js +99 -0
  92. data/public/javascripts/erp_app/shared/file_manager_tree.js +1 -2
  93. data/public/javascripts/erp_app/shared/notes_grid.js +4 -13
  94. data/public/stylesheets/erp_app/shared/compass-ext-all.css +5 -0
  95. metadata +70 -20
  96. data/config/environment.rb +0 -0
  97. data/spec/dummy/db/schema.rb +0 -806
  98. data/spec/dummy/db/spec.sqlite3 +0 -0
  99. data/spec/dummy/log/adam.log +0 -1
  100. data/spec/dummy/log/spec.log +0 -92886
@@ -10,7 +10,7 @@ module ErpApp
10
10
 
11
11
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
12
12
  sort = sort_hash[:property] || 'id'
13
- dir = sort_hash[:direction] || 'ASC'
13
+ dir = sort_hash[:direction] || 'DESC'
14
14
  limit = params[:limit] || 15
15
15
  start = params[:start] || 0
16
16
 
@@ -53,12 +53,13 @@ module ErpApp
53
53
  nodes_to_move.each do |node|
54
54
  path = node
55
55
  new_parent_path = (params[:parent_node] == ROOT_NODE) ? base_path : params[:parent_node]
56
+ new_parent_path = new_parent_path.gsub(base_path,'') # target path must be relative
56
57
  result, message = @file_support.save_move(path, new_parent_path)
57
58
  messages << message
58
59
  end
59
- render :json => {:success => true, :error => messages.join(',')}
60
+ render :json => {:success => true, :msg => messages.join(',')}
60
61
  rescue Exception => e
61
- render :json => {:success => false, :message => ex.message}
62
+ render :json => {:success => false, :error => ex.message}
62
63
  end
63
64
  end
64
65
 
@@ -80,15 +81,14 @@ module ErpApp
80
81
  result, message = @file_support.delete_file(path)
81
82
  messages << message
82
83
  end
83
- render :json => {:success => true, :error => messages.join(',')}
84
+ render :json => {:success => true, :msg => messages.join(',')}
84
85
  rescue Exception => e
85
- render :json => {:success => false, :message => ex.message}
86
+ render :json => {:success => false, :error => ex.message}
86
87
  end
87
88
  end
88
89
 
89
90
  def expand_directory
90
91
  path = (params[:node] == ROOT_NODE) ? base_path : params[:node]
91
-
92
92
  render :json => @file_support.build_tree(path)
93
93
  end
94
94
 
@@ -2,7 +2,7 @@ module ErpApp
2
2
  module Desktop
3
3
  module Scaffold
4
4
  class RoleController < ErpApp::Desktop::Scaffold::BaseController
5
- active_ext Role do |options|
5
+ active_ext SecurityRole do |options|
6
6
  options[:inline_edit] = true
7
7
  options[:use_ext_forms] = false
8
8
  options[:ignore_associations] = true
@@ -0,0 +1,47 @@
1
+ module ErpApp
2
+ module Desktop
3
+ module SecurityManagement
4
+ class BaseController < ::ErpApp::Desktop::BaseController
5
+
6
+ # used for related_searchbox
7
+ def search
8
+ if params[:model].blank? or (params[:displayField].blank? and params[:search_fields].blank?)
9
+ render :inline => '[]'
10
+ else
11
+ related_model = params[:model].camelize.constantize
12
+ query = related_model
13
+
14
+ unless params[:search_fields].blank?
15
+ #related_searchbox
16
+ search_fields = params[:search_fields].split(',')
17
+ unless params[:query].blank?
18
+ sql = ''
19
+ search_fields.each_with_index do |f,i|
20
+ sql += " OR " if i > 0
21
+ sql += "UPPER(#{f}) LIKE UPPER('%#{params[:query]}%')"
22
+ end
23
+ query = query.where(sql)
24
+ end
25
+ query = query.paginate(:page => page, :per_page => per_page)
26
+ end
27
+
28
+ total = query.count
29
+ data = query.all
30
+ render :inline => { :data => data, :total => total}.to_json
31
+ end
32
+ end
33
+
34
+ protected
35
+ def page
36
+ offset = params[:start].to_f
37
+ offset > 0 ? (offset / params[:limit].to_f).to_i + 1 : 1
38
+ end
39
+
40
+ def per_page
41
+ params[:limit].nil? ? 10 : params[:limit].to_i
42
+ end
43
+
44
+ end
45
+ end#SecurityManagement
46
+ end#Desktop
47
+ end#ErpApp
@@ -0,0 +1,129 @@
1
+ module ErpApp
2
+ module Desktop
3
+ module SecurityManagement
4
+ class CapabilitiesController < ErpApp::Desktop::SecurityManagement::BaseController
5
+
6
+ def available_setup
7
+ begin
8
+ columns = []
9
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Description", :name => 'description', :xtype => 'textfield', :width => 395 })
10
+
11
+ definition = []
12
+ definition << DynamicFormField.textfield({ :fieldLabel => "Description", :name => 'description' })
13
+ definition << DynamicFormField.hidden({ :fieldLabel => "ID", :name => 'id' })
14
+
15
+ render :inline => "{
16
+ \"success\": true,
17
+ \"columns\": [#{columns.join(',')}],
18
+ \"fields\": #{definition.to_json}
19
+ }"
20
+ rescue Exception => e
21
+ Rails.logger.error e.message
22
+ Rails.logger.error e.backtrace.join("\n")
23
+ render :inline => {
24
+ :success => false,
25
+ :message => e.message
26
+ }.to_json
27
+ end
28
+ end
29
+
30
+ def selected_setup
31
+ available_setup
32
+ end
33
+
34
+ def available
35
+ assign_to = params[:assign_to]
36
+ assign_to_id = params[:id]
37
+ sort = (params[:sort] || 'description').downcase
38
+ dir = (params[:dir] || 'asc').downcase
39
+ query_filter = params[:query_filter].strip rescue nil
40
+
41
+ scope_type_ids = [ScopeType.find_by_internal_identifier('class').id, ScopeType.find_by_internal_identifier('query').id]
42
+
43
+ ar = assign_to_id.blank? ? Capability.joins(:capability_type) : assign_to.constantize.find(assign_to_id).capabilities_not.where("scope_type_id IN (#{scope_type_ids.join(',')})")
44
+ ar = (params[:query_filter].blank? ? ar : ar.where("(UPPER(capabilities.description) LIKE UPPER('%#{query_filter}%'))"))
45
+ available = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
46
+
47
+ render :json => {:total => ar.count, :data => available.map{|x| {:description => x.description, :id => x.id}}}
48
+ end
49
+
50
+ def selected
51
+ assign_to = params[:assign_to]
52
+ assign_to_id = params[:id]
53
+ sort = (params[:sort] || 'description').downcase
54
+ dir = (params[:dir] || 'asc').downcase
55
+ query_filter = params[:query_filter].strip rescue nil
56
+
57
+ scope_type_ids = [ScopeType.find_by_internal_identifier('class').id, ScopeType.find_by_internal_identifier('query').id]
58
+
59
+ ar = assign_to_id.blank? ? Capability.joins(:capability_type) : assign_to.constantize.find(assign_to_id).capabilities.where("scope_type_id IN (#{scope_type_ids.join(',')})")
60
+ ar = (params[:query_filter].blank? ? ar : ar.where("(UPPER(capabilities.description) LIKE UPPER('%#{query_filter}%'))"))
61
+ selected = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
62
+
63
+ render :json => {:total => ar.count, :data => selected.map{|x| {:total => ar.count, :description => x.description, :id => x.id}}}
64
+ end
65
+
66
+ def add
67
+ begin
68
+ assign_to = params[:assign_to]
69
+ assign_to_id = params[:id]
70
+ selected = JSON.parse(params[:selection])
71
+
72
+ a = assign_to.constantize.find(assign_to_id)
73
+ selected.each do |c|
74
+ capability = Capability.find(c)
75
+ case assign_to
76
+ when 'User'
77
+ a.add_capability(capability)
78
+ when 'SecurityRole'
79
+ a.add_capability(capability)
80
+ when 'Group'
81
+ a.add_capability(capability)
82
+ end
83
+ end
84
+
85
+ render :json => {:success => true, :message => 'Security Roles(s) Added'}
86
+ rescue Exception => e
87
+ Rails.logger.error e.message
88
+ Rails.logger.error e.backtrace.join("\n")
89
+ render :inline => {
90
+ :success => false,
91
+ :message => e.message
92
+ }.to_json
93
+ end
94
+ end
95
+
96
+ def remove
97
+ begin
98
+ assign_to = params[:assign_to]
99
+ assign_to_id = params[:id]
100
+ selected = JSON.parse(params[:selection])
101
+
102
+ a = assign_to.constantize.find(assign_to_id)
103
+ selected.each do |c|
104
+ capability = Capability.find(c)
105
+ case assign_to
106
+ when 'User'
107
+ a.remove_capability(capability)
108
+ when 'SecurityRole'
109
+ a.remove_capability(capability)
110
+ when 'Group'
111
+ a.remove_capability(capability)
112
+ end
113
+ end
114
+
115
+ render :json => {:success => true, :message => 'Security Roles(s) Removed'}
116
+ rescue Exception => e
117
+ Rails.logger.error e.message
118
+ Rails.logger.error e.backtrace.join("\n")
119
+ render :inline => {
120
+ :success => false,
121
+ :message => e.message
122
+ }.to_json
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,201 @@
1
+ module ErpApp
2
+ module Desktop
3
+ module SecurityManagement
4
+ class GroupsController < ErpApp::Desktop::SecurityManagement::BaseController
5
+
6
+ def available_setup
7
+ begin
8
+ columns = []
9
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Group Name", :name => 'description', :xtype => 'textfield', :width => 395 })
10
+
11
+ definition = []
12
+ definition << DynamicFormField.textfield({ :fieldLabel => "Group Name", :name => 'description' })
13
+ definition << DynamicFormField.hidden({ :fieldLabel => "ID", :name => 'id' })
14
+
15
+ render :inline => "{
16
+ \"success\": true,
17
+ \"columns\": [#{columns.join(',')}],
18
+ \"fields\": #{definition.to_json}
19
+ }"
20
+ rescue Exception => e
21
+ Rails.logger.error e.message
22
+ Rails.logger.error e.backtrace.join("\n")
23
+ render :inline => {
24
+ :success => false,
25
+ :message => e.message
26
+ }.to_json
27
+ end
28
+ end
29
+
30
+ def selected_setup
31
+ available_setup
32
+ end
33
+
34
+ def available
35
+ assign_to = params[:assign_to]
36
+ assign_to_id = params[:id]
37
+ sort = (params[:sort] || 'description').downcase
38
+ dir = (params[:dir] || 'asc').downcase
39
+ query_filter = params[:query_filter].strip rescue nil
40
+
41
+ ar = assign_to_id.blank? ? Group : assign_to.constantize.find(assign_to_id).groups_not
42
+ ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(groups.description) LIKE UPPER('%#{query_filter}%')"))
43
+ available = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
44
+
45
+ render :json => {:total => ar.count, :data => available.map{|x| {:description => x.description, :id => x.id}}}
46
+ end
47
+
48
+ def selected
49
+ assign_to = params[:assign_to]
50
+ assign_to_id = params[:id]
51
+ sort = (params[:sort] || 'description').downcase
52
+ dir = (params[:dir] || 'asc').downcase
53
+ query_filter = params[:query_filter].strip rescue nil
54
+
55
+ ar = assign_to_id.blank? ? Group : assign_to.constantize.find(assign_to_id).groups
56
+ ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(groups.description) LIKE UPPER('%#{query_filter}%')"))
57
+ selected = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
58
+
59
+ render :json => {:total => ar.count, :data => selected.map{|x| {:description => x.description, :id => x.id}}}
60
+ end
61
+
62
+ def create
63
+ begin
64
+ description = params[:description].strip
65
+
66
+ unless description.blank?
67
+ Group.create(:description => params[:description])
68
+ render :json => {:success => true, :message => 'Group created'}
69
+ else
70
+ raise "Group name blank"
71
+ end
72
+ rescue Exception => e
73
+ Rails.logger.error e.message
74
+ Rails.logger.error e.backtrace.join("\n")
75
+ render :inline => {
76
+ :success => false,
77
+ :message => e.message
78
+ }.to_json
79
+ end
80
+ end
81
+
82
+ def update
83
+ begin
84
+ description = params[:description].strip
85
+
86
+ unless description.blank? or params[:id].blank?
87
+ g = Group.find(params[:id])
88
+ g.description = description
89
+ g.save
90
+ render :json => {:success => true, :message => 'Group updated'}
91
+ else
92
+ raise "Group name blank or no group ID"
93
+ end
94
+ rescue Exception => e
95
+ Rails.logger.error e.message
96
+ Rails.logger.error e.backtrace.join("\n")
97
+ render :inline => {
98
+ :success => false,
99
+ :message => e.message
100
+ }.to_json
101
+ end
102
+ end
103
+
104
+ def delete
105
+ begin
106
+ unless params[:id].blank?
107
+ Group.destroy(params[:id])
108
+ render :json => {:success => true, :message => 'Group deleted'}
109
+ else
110
+ raise "No Group ID"
111
+ end
112
+ rescue Exception => e
113
+ Rails.logger.error e.message
114
+ Rails.logger.error e.backtrace.join("\n")
115
+ render :inline => {
116
+ :success => false,
117
+ :message => e.message
118
+ }.to_json
119
+ end
120
+ end
121
+
122
+ def add
123
+ begin
124
+ assign_to = params[:assign_to]
125
+ assign_to_id = params[:id]
126
+ selected = JSON.parse(params[:selection])
127
+
128
+ a = assign_to.constantize.find(assign_to_id)
129
+ selected.each do |g|
130
+ group = Group.find(g)
131
+ case assign_to
132
+ when 'User'
133
+ group.add_user(a)
134
+ when 'SecurityRole'
135
+ group.add_role(a)
136
+ when 'Capability'
137
+ group.add_capability(a)
138
+ end
139
+ end
140
+
141
+ render :json => {:success => true, :message => 'Group(s) Added'}
142
+ rescue Exception => e
143
+ Rails.logger.error e.message
144
+ Rails.logger.error e.backtrace.join("\n")
145
+ render :inline => {
146
+ :success => false,
147
+ :message => e.message
148
+ }.to_json
149
+ end
150
+ end
151
+
152
+ def remove
153
+ begin
154
+ assign_to = params[:assign_to]
155
+ assign_to_id = params[:id]
156
+ selected = JSON.parse(params[:selection])
157
+
158
+ a = assign_to.constantize.find(assign_to_id)
159
+ selected.each do |g|
160
+ group = Group.find(g)
161
+ case assign_to
162
+ when 'User'
163
+ group.remove_user(a)
164
+ when 'SecurityRole'
165
+ group.remove_role(a)
166
+ when 'Capability'
167
+ group.remove_capability(a)
168
+ end
169
+ end
170
+
171
+ render :json => {:success => true, :message => 'Group(s) Removed'}
172
+ rescue Exception => e
173
+ Rails.logger.error e.message
174
+ Rails.logger.error e.backtrace.join("\n")
175
+ render :inline => {
176
+ :success => false,
177
+ :message => e.message
178
+ }.to_json
179
+ end
180
+ end
181
+
182
+ def effective_security
183
+ begin
184
+ assign_to_id = params[:id]
185
+ u = Group.find(assign_to_id)
186
+
187
+ render :json => {:success => true, :capabilities => u.class_capabilities_to_hash }
188
+ rescue Exception => e
189
+ Rails.logger.error e.message
190
+ Rails.logger.error e.backtrace.join("\n")
191
+ render :inline => {
192
+ :success => false,
193
+ :message => e.message
194
+ }.to_json
195
+ end
196
+ end
197
+
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,188 @@
1
+ module ErpApp
2
+ module Desktop
3
+ module SecurityManagement
4
+ class RolesController < ErpApp::Desktop::SecurityManagement::BaseController
5
+
6
+ def available_setup
7
+ begin
8
+ columns = []
9
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Security Role Name", :name => 'description', :xtype => 'textfield', :width => 200 })
10
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Internal ID", :name => 'internal_identifier', :xtype => 'textfield', :width => 195 })
11
+
12
+ definition = []
13
+ definition << DynamicFormField.textfield({ :fieldLabel => "Security Role Name", :name => 'description' })
14
+ definition << DynamicFormField.textfield({ :fieldLabel => "Internal ID", :name => 'internal_identifier' })
15
+ definition << DynamicFormField.hidden({ :fieldLabel => "ID", :name => 'id' })
16
+
17
+ render :inline => "{
18
+ \"success\": true,
19
+ \"columns\": [#{columns.join(',')}],
20
+ \"fields\": #{definition.to_json}
21
+ }"
22
+ rescue Exception => e
23
+ Rails.logger.error e.message
24
+ Rails.logger.error e.backtrace.join("\n")
25
+ render :inline => {
26
+ :success => false,
27
+ :message => e.message
28
+ }.to_json
29
+ end
30
+ end
31
+
32
+ def selected_setup
33
+ available_setup
34
+ end
35
+
36
+ def available
37
+ assign_to = params[:assign_to]
38
+ assign_to_id = params[:id]
39
+ sort = (params[:sort] || 'description').downcase
40
+ dir = (params[:dir] || 'asc').downcase
41
+ query_filter = params[:query_filter].strip rescue nil
42
+
43
+ ar = assign_to_id.blank? ? SecurityRole : assign_to.constantize.find(assign_to_id).roles_not
44
+ ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(security_roles.description) LIKE UPPER('%#{query_filter}%')"))
45
+ available = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
46
+
47
+ render :json => {:total => ar.count, :data => available.map{|x| {:description => x.description, :internal_identifier => x.internal_identifier, :id => x.id}}}
48
+ end
49
+
50
+ def selected
51
+ assign_to = params[:assign_to]
52
+ assign_to_id = params[:id]
53
+ sort = (params[:sort] || 'description').downcase
54
+ dir = (params[:dir] || 'asc').downcase
55
+ query_filter = params[:query_filter].strip rescue nil
56
+
57
+ ar = assign_to_id.blank? ? SecurityRole : assign_to.constantize.find(assign_to_id).roles
58
+ ar = (params[:query_filter].blank? ? ar : ar.where("UPPER(security_roles.description) LIKE UPPER('%#{query_filter}%')"))
59
+ selected = ar.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
60
+
61
+ render :json => {:total => ar.count, :data => selected.map{|x| {:description => x.description, :internal_identifier => x.internal_identifier, :id => x.id}}}
62
+ end
63
+
64
+ def create
65
+ begin
66
+ description = params[:description].strip
67
+ iid = params[:internal_identifier].strip
68
+
69
+ unless description.blank?
70
+ SecurityRole.create(:description => description, :internal_identifier => iid)
71
+ render :json => {:success => true, :message => 'Security Role created'}
72
+ else
73
+ raise "Role name blank"
74
+ end
75
+ rescue Exception => e
76
+ Rails.logger.error e.message
77
+ Rails.logger.error e.backtrace.join("\n")
78
+ render :inline => {
79
+ :success => false,
80
+ :message => e.message
81
+ }.to_json
82
+ end
83
+ end
84
+
85
+ def update
86
+ begin
87
+ description = params[:description].strip
88
+
89
+ unless description.blank? or params[:id].blank?
90
+ r = SecurityRole.find(params[:id])
91
+ r.description = description
92
+ r.save
93
+ render :json => {:success => true, :message => 'Security Role updated'}
94
+ else
95
+ raise "Role name blank or no role ID"
96
+ end
97
+ rescue Exception => e
98
+ Rails.logger.error e.message
99
+ Rails.logger.error e.backtrace.join("\n")
100
+ render :inline => {
101
+ :success => false,
102
+ :message => e.message
103
+ }.to_json
104
+ end
105
+ end
106
+
107
+ def delete
108
+ begin
109
+ unless params[:id].blank?
110
+ SecurityRole.destroy(params[:id])
111
+ render :json => {:success => true, :message => 'Security Role deleted'}
112
+ else
113
+ raise "No Role ID"
114
+ end
115
+ rescue Exception => e
116
+ Rails.logger.error e.message
117
+ Rails.logger.error e.backtrace.join("\n")
118
+ render :inline => {
119
+ :success => false,
120
+ :message => e.message
121
+ }.to_json
122
+ end
123
+ end
124
+
125
+ def add
126
+ begin
127
+ assign_to = params[:assign_to]
128
+ assign_to_id = params[:id]
129
+ selected = JSON.parse(params[:selection])
130
+
131
+ a = assign_to.constantize.find(assign_to_id)
132
+ selected.each do |r|
133
+ role = SecurityRole.find(r)
134
+ case assign_to
135
+ when 'User'
136
+ a.add_role(role)
137
+ when 'Group'
138
+ a.add_role(role)
139
+ when 'Capability'
140
+ role.add_capability(a)
141
+ end
142
+ end
143
+
144
+ render :json => {:success => true, :message => 'Security Roles(s) Added'}
145
+ rescue Exception => e
146
+ Rails.logger.error e.message
147
+ Rails.logger.error e.backtrace.join("\n")
148
+ render :inline => {
149
+ :success => false,
150
+ :message => e.message
151
+ }.to_json
152
+ end
153
+ end
154
+
155
+ def remove
156
+ begin
157
+ assign_to = params[:assign_to]
158
+ assign_to_id = params[:id]
159
+ selected = JSON.parse(params[:selection])
160
+
161
+ a = assign_to.constantize.find(assign_to_id)
162
+ selected.each do |r|
163
+ role = SecurityRole.find(r)
164
+ case assign_to
165
+ when 'User'
166
+ a.remove_role(role)
167
+ when 'Group'
168
+ a.remove_role(role)
169
+ when 'Capability'
170
+ role.remove_capability(a)
171
+ end
172
+ end
173
+
174
+ render :json => {:success => true, :message => 'Security Roles(s) Removed'}
175
+ rescue Exception => e
176
+ Rails.logger.error e.message
177
+ Rails.logger.error e.backtrace.join("\n")
178
+ render :inline => {
179
+ :success => false,
180
+ :message => e.message
181
+ }.to_json
182
+ end
183
+ end
184
+
185
+ end
186
+ end
187
+ end
188
+ end