erp_tech_svcs 4.0.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -24
- data/app/controllers/api/v1/audit_log_items_controller.rb +33 -0
- data/app/controllers/api/v1/audit_logs_controller.rb +32 -0
- data/app/controllers/api/v1/capabilities_controller.rb +160 -0
- data/app/controllers/api/v1/file_assets_controller.rb +40 -0
- data/app/controllers/api/v1/groups_controller.rb +236 -0
- data/app/controllers/api/v1/security_roles_controller.rb +276 -0
- data/app/controllers/api/v1/users_controller.rb +262 -0
- data/app/controllers/erp_tech_svcs/session_controller.rb +8 -5
- data/app/controllers/erp_tech_svcs/user_controller.rb +14 -15
- data/app/mailers/user_mailer.rb +8 -5
- data/app/models/audit_log.rb +111 -36
- data/app/models/audit_log_item.rb +30 -0
- data/app/models/audit_log_item_type.rb +1 -0
- data/app/models/audit_log_type.rb +19 -0
- data/app/models/capability.rb +22 -6
- data/app/models/extensions/tracked_status_type.rb +3 -0
- data/app/models/file_asset.rb +245 -20
- data/app/models/file_asset_holder.rb +20 -0
- data/app/models/group.rb +38 -25
- data/app/models/notification.rb +32 -13
- data/app/models/notification_type.rb +13 -0
- data/app/models/security_role.rb +17 -4
- data/app/models/user.rb +116 -29
- data/app/validators/password_strength_validator.rb +1 -1
- data/app/views/user_mailer/activation_needed_email.html.erb +293 -15
- data/app/views/user_mailer/reset_password_email.html.erb +268 -13
- data/config/initializers/logger.rb +19 -0
- data/config/initializers/sorcery.rb +2 -0
- data/config/initializers/wickedpdf.rb +4 -0
- data/config/routes.rb +64 -0
- data/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb +1 -5
- data/db/data_migrations/20150819140550_create_job_tracker_for_notification.rb +14 -0
- data/db/migrate/20080805000010_base_tech_services.rb +99 -39
- data/db/migrate/20150414151421_add_nested_set_columns_to_security_role.rb +13 -0
- data/db/migrate/20150609003216_update_user_for_sorcery.rb +11 -0
- data/db/migrate/20150819135108_add_custom_fields_to_notifications.rb +5 -0
- data/db/migrate/20160122155402_add_description_to_file_asset.rb +13 -0
- data/db/migrate/20160310163060_add_created_by_updated_by_to_erp_tech_svcs.rb +35 -0
- data/db/migrate/20160313161611_add_tenant_id_to_audit_log.rb +16 -0
- data/lib/erp_tech_svcs.rb +6 -10
- data/lib/erp_tech_svcs/config.rb +7 -2
- data/lib/erp_tech_svcs/delayed_jobs/delete_expired_sessions_job.rb +49 -0
- data/lib/erp_tech_svcs/delayed_jobs/notification_job.rb +50 -0
- data/lib/erp_tech_svcs/engine.rb +0 -1
- data/lib/erp_tech_svcs/erp_tech_svcs_audit_log.rb +12 -6
- data/lib/erp_tech_svcs/extensions.rb +0 -1
- data/lib/erp_tech_svcs/extensions/active_record/has_capability_accessors.rb +57 -29
- data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +57 -31
- data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +12 -4
- data/lib/erp_tech_svcs/extensions/active_record/is_json.rb +22 -15
- data/lib/erp_tech_svcs/extensions/active_record/scoped_by.rb +16 -13
- data/lib/erp_tech_svcs/extensions/compass_ae/erp_base_erp_svcs/controllers/api/parties_controller.rb +15 -0
- data/lib/erp_tech_svcs/file_support.rb +1 -0
- data/lib/erp_tech_svcs/file_support/file_system_manager.rb +77 -44
- data/lib/erp_tech_svcs/file_support/manager.rb +12 -3
- data/lib/erp_tech_svcs/file_support/railties/compass_ae_resolver.rb +49 -0
- data/lib/erp_tech_svcs/file_support/s3_manager.rb +73 -51
- data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +11 -2
- data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +238 -46
- data/lib/erp_tech_svcs/version.rb +1 -1
- data/lib/tasks/erp_tech_svcs_tasks.rake +43 -5
- metadata +73 -42
- data/app/models/user_defined_data.rb +0 -6
- data/app/models/user_defined_field.rb +0 -8
- data/config/initializers/pdfkit.rb +0 -18
- data/db/data_migrations/20121130212146_note_capabilities.rb +0 -23
- data/db/migrate/20121116151510_create_groups.rb +0 -18
- data/db/migrate/20121126171612_upgrade_security.rb +0 -53
- data/db/migrate/20121126173506_upgrade_security2.rb +0 -274
- data/db/migrate/20130410135419_add_queue_to_delayed_jobs.rb +0 -13
- data/db/migrate/20130610163240_create_notifications.rb +0 -37
- data/db/migrate/20130725212647_add_party_id_idx_to_users.rb +0 -9
- data/db/migrate/20131113213843_add_audit_log_item_old_value.rb +0 -13
- data/db/migrate/20131113213844_add_erp_tech_svcs_missing_indexes.rb +0 -31
- data/db/migrate/20131129203603_add_user_defined_fields.rb +0 -43
- data/db/migrate/20141013060204_add_custom_fields_to_notifications.rb +0 -12
- data/db/migrate/20141108182427_add_scoped_by_to_file_assets.rb +0 -14
- data/lib/erp_tech_svcs/extensions/active_record/has_user_defined_data.rb +0 -147
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_job.rb +0 -47
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_service.rb +0 -15
- data/lib/erp_tech_svcs/utils/compass_logger.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d1afe3f18154c03bf81d9834702592ce388f4aa
|
4
|
+
data.tar.gz: 71878b46f921999cfcb0d5651f2a544215756971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e9fe984a85bda80e67b9252d55433e1ed45f6d236cb38de233c88da6eae3778cbdb1332d318ad2cead6e190fcadfff5781df59dcbe0c91a44b6f283c7cd76fe
|
7
|
+
data.tar.gz: db7c9b363d446511aea7d6425c08d8d4dd4328237d372b9a15daa787b8d783f78f1dc41756d0c9598e9c1c9eb7d1be91c4f9391fdd78f03159d4d058a18bab24
|
data/README.md
CHANGED
@@ -61,27 +61,3 @@ To override these settings simple create a erp_tech_svcs.rb file in your initial
|
|
61
61
|
config.s3_protocol = 'https' # Can be either 'http' or 'https'
|
62
62
|
end
|
63
63
|
Rails.application.config.erp_tech_svcs.configure!
|
64
|
-
|
65
|
-
##Notes
|
66
|
-
|
67
|
-
We use [pdfkit](https://github.com/jdpace/PDFKit) and there is an initializer in erp\_tech\_svcs to set it up with some defaults. You will need to create your
|
68
|
-
own initializer to overwrite this if you have wkhtmltopdf in another location
|
69
|
-
|
70
|
-
# config/initializers/pdfkit.rb
|
71
|
-
PDFKit.configure do |config|
|
72
|
-
if RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
73
|
-
# set path to wkhtmltopdf on windows here
|
74
|
-
config.wkhtmltopdf = '/opt/local/bin/wkhtmltopdf'
|
75
|
-
else
|
76
|
-
config.wkhtmltopdf = '/opt/local/bin/wkhtmltopdf'
|
77
|
-
end
|
78
|
-
|
79
|
-
config.default_options = {
|
80
|
-
:page_size => 'Letter',
|
81
|
-
:print_media_type => true,
|
82
|
-
:disable_smart_shrinking => true,
|
83
|
-
:dpi => 300,
|
84
|
-
:no_background => true
|
85
|
-
# :use_xserver => true
|
86
|
-
}
|
87
|
-
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class AuditLogItemsController < BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
|
7
|
+
sort = sort_hash[:property] || 'description'
|
8
|
+
dir = sort_hash[:direction] || 'ASC'
|
9
|
+
limit = params[:limit] || 25
|
10
|
+
start = params[:start] || 0
|
11
|
+
# query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
|
12
|
+
|
13
|
+
if params[:audit_log_id].present?
|
14
|
+
audit_log_items = AuditLogItem.where(audit_log_id: params[:audit_log_id])
|
15
|
+
|
16
|
+
total_count = audit_log_items.count
|
17
|
+
audit_log_items = audit_log_items.limit(limit).offset(start)
|
18
|
+
audit_log_items.order("#{sort} #{dir}")
|
19
|
+
|
20
|
+
render json: {success: true,
|
21
|
+
total_count: total_count,
|
22
|
+
audit_log_items: audit_log_items.collect { |audit_log_item| audit_log_item.to_data_hash }}
|
23
|
+
|
24
|
+
else
|
25
|
+
render json: {success: false,
|
26
|
+
message: 'Audit Log id must be passed'}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end # AuditLogItemsController
|
32
|
+
end # V1
|
33
|
+
end # Api
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class AuditLogsController < BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
|
7
|
+
sort = sort_hash[:property] || 'description'
|
8
|
+
dir = sort_hash[:direction] || 'ASC'
|
9
|
+
limit = params[:limit] || 25
|
10
|
+
start = params[:start] || 0
|
11
|
+
query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
|
12
|
+
|
13
|
+
# if no file asset holder was passed we need to scope by dba_organization
|
14
|
+
unless query_filter[:tenant].present?
|
15
|
+
query_filter[:tenant] = current_user.dba_organization
|
16
|
+
end
|
17
|
+
|
18
|
+
# apply filters
|
19
|
+
audit_logs = AuditLog.apply_filters(query_filter)
|
20
|
+
|
21
|
+
total_count = audit_logs.count
|
22
|
+
audit_logs = audit_logs.limit(limit).offset(start)
|
23
|
+
audit_logs.order("#{sort} #{dir}")
|
24
|
+
|
25
|
+
render json: {success: true,
|
26
|
+
total_count: total_count,
|
27
|
+
file_assets: audit_logs.collect { |audit_log| audit_log.to_data_hash }}
|
28
|
+
end
|
29
|
+
|
30
|
+
end # AuditLogsController
|
31
|
+
end # V1
|
32
|
+
end # Api
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class CapabilitiesController < BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
if params[:user_id].present?
|
7
|
+
capabilities = User.find(params[:user_id]).capabilities
|
8
|
+
else
|
9
|
+
capabilities = Capability
|
10
|
+
end
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.json do
|
14
|
+
query = params[:query]
|
15
|
+
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
|
16
|
+
sort = sort_hash[:property] || 'description'
|
17
|
+
dir = sort_hash[:direction] || 'ASC'
|
18
|
+
limit = params[:limit]
|
19
|
+
start = params[:start]
|
20
|
+
|
21
|
+
if query
|
22
|
+
capability_role_tbl = Capability.arel_table
|
23
|
+
capabilities = capabilities.where(capability_role_tbl[:description].matches("%#{query}%"))
|
24
|
+
|
25
|
+
total_count = capabilities.count
|
26
|
+
capabilities = capabilities.order("#{sort} #{dir}")
|
27
|
+
else
|
28
|
+
total_count = capabilities.count
|
29
|
+
capabilities = capabilities.order("#{sort} #{dir}")
|
30
|
+
end
|
31
|
+
|
32
|
+
if limit and start
|
33
|
+
capabilities = capabilities.limit(limit).offset(start)
|
34
|
+
end
|
35
|
+
|
36
|
+
render json: {success: true, total_count: total_count, capabilities: capabilities.collect{|capability| capability.to_data_hash}}
|
37
|
+
end
|
38
|
+
format.tree do
|
39
|
+
nodes = [].tap do |nodes|
|
40
|
+
capabilities.all.each do |capability|
|
41
|
+
nodes.push({
|
42
|
+
leaf: true,
|
43
|
+
internal_identifier: capability.id,
|
44
|
+
text: capability.description
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
render json: {success: true, capabilities: nodes}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def available
|
55
|
+
type = params[:type]
|
56
|
+
id = params[:id]
|
57
|
+
|
58
|
+
sort = (params[:sort] || 'description').downcase
|
59
|
+
sort = 'capabilities.description' if sort == 'description'
|
60
|
+
dir = (params[:dir] || 'asc').downcase
|
61
|
+
query_filter = params[:query_filter].strip rescue nil
|
62
|
+
scope_type_ids = [ScopeType.find_by_internal_identifier('class').id, ScopeType.find_by_internal_identifier('query').id]
|
63
|
+
|
64
|
+
statement = id.blank? ? Capability.joins(:capability_type) : type.constantize.find(id).capabilities_not.where("scope_type_id IN (#{scope_type_ids.join(',')})")
|
65
|
+
statement = (params[:query_filter].blank? ? statement : statement.where("(UPPER(capabilities.description) LIKE UPPER('%#{query_filter}%'))"))
|
66
|
+
available = statement.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
|
67
|
+
|
68
|
+
render :json => {:total_count => statement.count, :capabilities => available.map { |capability| capability.to_data_hash }}
|
69
|
+
end
|
70
|
+
|
71
|
+
def selected
|
72
|
+
type = params[:type]
|
73
|
+
id = params[:id]
|
74
|
+
|
75
|
+
sort = (params[:sort] || 'description').downcase
|
76
|
+
sort = 'capabilities.description' if sort == 'description'
|
77
|
+
dir = (params[:dir] || 'asc').downcase
|
78
|
+
query_filter = params[:query_filter].strip rescue nil
|
79
|
+
scope_type_ids = [ScopeType.find_by_internal_identifier('class').id, ScopeType.find_by_internal_identifier('query').id]
|
80
|
+
|
81
|
+
statement = id.blank? ? Capability.joins(:capability_type) : type.constantize.find(id).capabilities.where("scope_type_id IN (#{scope_type_ids.join(',')})")
|
82
|
+
statement = (params[:query_filter].blank? ? statement : statement.where("(UPPER(capabilities.description) LIKE UPPER('%#{query_filter}%'))"))
|
83
|
+
selected = statement.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
|
84
|
+
|
85
|
+
render :json => {:total_count => statement.count, :capabilities => selected.map { |capability| capability.to_data_hash }}
|
86
|
+
end
|
87
|
+
|
88
|
+
def add
|
89
|
+
begin
|
90
|
+
type = params[:type]
|
91
|
+
id = params[:id]
|
92
|
+
capability_ids = JSON.parse(params[:capability_ids])
|
93
|
+
|
94
|
+
assign_to = type.constantize.find(id)
|
95
|
+
capability_ids.each do |capability_id|
|
96
|
+
capability = Capability.find(capability_id)
|
97
|
+
case type
|
98
|
+
when 'User'
|
99
|
+
assign_to.add_capability(capability)
|
100
|
+
when 'SecurityRole'
|
101
|
+
assign_to.add_capability(capability)
|
102
|
+
when 'Group'
|
103
|
+
assign_to.add_capability(capability)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
render :json => {:success => true, :message => 'Capability(s) Added'}
|
108
|
+
rescue Exception => e
|
109
|
+
Rails.logger.error e.message
|
110
|
+
Rails.logger.error e.backtrace.join("\n")
|
111
|
+
render :inline => {
|
112
|
+
:success => false,
|
113
|
+
:message => e.message
|
114
|
+
}.to_json
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def remove
|
119
|
+
begin
|
120
|
+
type = params[:type]
|
121
|
+
id = params[:id]
|
122
|
+
capability_ids = JSON.parse(params[:capability_ids])
|
123
|
+
|
124
|
+
assign_to = type.constantize.find(id)
|
125
|
+
capability_ids.each do |capability_id|
|
126
|
+
capability = Capability.find(capability_id)
|
127
|
+
case type
|
128
|
+
when 'User'
|
129
|
+
assign_to.remove_capability(capability)
|
130
|
+
when 'SecurityRole'
|
131
|
+
assign_to.remove_capability(capability)
|
132
|
+
when 'Group'
|
133
|
+
assign_to.remove_capability(capability)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
render :json => {:success => true, :message => 'Capability(s) Removed'}
|
138
|
+
rescue Exception => e
|
139
|
+
Rails.logger.error e.message
|
140
|
+
Rails.logger.error e.backtrace.join("\n")
|
141
|
+
render :inline => {
|
142
|
+
:success => false,
|
143
|
+
:message => e.message
|
144
|
+
}.to_json
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def page
|
150
|
+
offset = params[:start].to_f
|
151
|
+
offset > 0 ? (offset / params[:limit].to_f).to_i + 1 : 1
|
152
|
+
end
|
153
|
+
|
154
|
+
def per_page
|
155
|
+
params[:limit].nil? ? 10 : params[:limit].to_i
|
156
|
+
end
|
157
|
+
|
158
|
+
end # CapabilitiesController
|
159
|
+
end # V1
|
160
|
+
end # Api
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class FileAssetsController < BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
|
7
|
+
sort = sort_hash[:property] || 'description'
|
8
|
+
dir = sort_hash[:direction] || 'ASC'
|
9
|
+
limit = params[:limit] || 25
|
10
|
+
start = params[:start] || 0
|
11
|
+
query_filter = params[:query_filter].blank? ? {} : JSON.parse(params[:query_filter]).symbolize_keys
|
12
|
+
|
13
|
+
# apply filters
|
14
|
+
file_assets = FileAsset.apply_filters(query_filter)
|
15
|
+
|
16
|
+
# if no file asset holder was passed we need to scope by dba_organization
|
17
|
+
if !query_filter[:file_asset_holder_type].present? && !query_filter[:file_asset_holder_id].present?
|
18
|
+
file_assets = file_assets.scope_by_dba_org(current_user.party.dba_organization)
|
19
|
+
end
|
20
|
+
|
21
|
+
total_count = file_assets.count
|
22
|
+
file_assets = file_assets.limit(limit).offset(start)
|
23
|
+
file_assets.order("#{sort} #{dir}")
|
24
|
+
|
25
|
+
render json: {success: true,
|
26
|
+
total_count: total_count,
|
27
|
+
file_assets: file_assets.collect { |file| file.to_data_hash }}
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
file_asset = FileAsset.find(params[:id])
|
32
|
+
|
33
|
+
file_asset.destroy
|
34
|
+
|
35
|
+
render json: {success: true}
|
36
|
+
end
|
37
|
+
|
38
|
+
end # FileAssetsController
|
39
|
+
end # V1
|
40
|
+
end # Api
|
@@ -0,0 +1,236 @@
|
|
1
|
+
module Api
|
2
|
+
module V1
|
3
|
+
class GroupsController < BaseController
|
4
|
+
|
5
|
+
def index
|
6
|
+
if params[:user_id].present?
|
7
|
+
groups = User.find(params[:user_id]).groups
|
8
|
+
else
|
9
|
+
groups = Group
|
10
|
+
end
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.json do
|
14
|
+
query = params[:query]
|
15
|
+
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
|
16
|
+
sort = sort_hash[:property] || 'description'
|
17
|
+
dir = sort_hash[:direction] || 'ASC'
|
18
|
+
limit = params[:limit]
|
19
|
+
start = params[:start]
|
20
|
+
|
21
|
+
if query
|
22
|
+
group_role_tbl = Group.arel_table
|
23
|
+
groups = groups.where(group_role_tbl[:description].matches("%#{query}%"))
|
24
|
+
|
25
|
+
total_count = groups.count
|
26
|
+
groups = groups.order("#{sort} #{dir}")
|
27
|
+
else
|
28
|
+
total_count = groups.count
|
29
|
+
groups = groups.order("#{sort} #{dir}")
|
30
|
+
end
|
31
|
+
|
32
|
+
if limit and start
|
33
|
+
groups = groups.limit(limit).offset(start)
|
34
|
+
end
|
35
|
+
|
36
|
+
render json: {success: true, total_count: total_count, groups: groups.collect{|group| group.to_data_hash}}
|
37
|
+
end
|
38
|
+
format.tree do
|
39
|
+
nodes = [].tap do |nodes|
|
40
|
+
groups.all.each do |group|
|
41
|
+
nodes.push({
|
42
|
+
leaf: true,
|
43
|
+
internal_identifier: group.id,
|
44
|
+
text: group.description
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
render json: {success: true, groups: nodes}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def available
|
55
|
+
type = params[:type]
|
56
|
+
id = params[:id]
|
57
|
+
|
58
|
+
sort = (params[:sort] || 'description').downcase
|
59
|
+
sort = 'groups.description' if sort == 'description'
|
60
|
+
dir = (params[:dir] || 'asc').downcase
|
61
|
+
query_filter = params[:query_filter].strip rescue nil
|
62
|
+
|
63
|
+
statement = id.blank? ? Group : type.constantize.find(id).groups_not
|
64
|
+
|
65
|
+
statement = (params[:query_filter].blank? ? statement : statement.where("UPPER(groups.description) LIKE UPPER('%#{query_filter}%')"))
|
66
|
+
available = statement.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
|
67
|
+
|
68
|
+
render :json => {:total_count => statement.count, :groups => available.map { |group| group.to_data_hash }}
|
69
|
+
end
|
70
|
+
|
71
|
+
def selected
|
72
|
+
type = params[:type]
|
73
|
+
id = params[:id]
|
74
|
+
|
75
|
+
sort = (params[:sort] || 'description').downcase
|
76
|
+
sort = 'groups.description' if sort == 'description'
|
77
|
+
dir = (params[:dir] || 'asc').downcase
|
78
|
+
query_filter = params[:query_filter].strip rescue nil
|
79
|
+
|
80
|
+
statement = id.blank? ? Group : type.constantize.find(id).groups
|
81
|
+
statement = (params[:query_filter].blank? ? statement : ar.where("UPPER(groups.description) LIKE UPPER('%#{query_filter}%')"))
|
82
|
+
selected = statement.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
|
83
|
+
|
84
|
+
render :json => {:total_count => statement.count, :groups => selected.map { |group| group.to_data_hash }}
|
85
|
+
end
|
86
|
+
|
87
|
+
def add
|
88
|
+
begin
|
89
|
+
type = params[:type]
|
90
|
+
id = params[:id]
|
91
|
+
selected = JSON.parse(params[:group_ids])
|
92
|
+
|
93
|
+
assign_to = type.constantize.find(id)
|
94
|
+
selected.each do |group_id|
|
95
|
+
group = Group.find(group_id)
|
96
|
+
case type
|
97
|
+
when 'User'
|
98
|
+
group.add_user(assign_to)
|
99
|
+
when 'SecurityRole'
|
100
|
+
group.add_role(assign_to)
|
101
|
+
when 'Capability'
|
102
|
+
group.add_capability(assign_to)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
render :json => {:success => true, :message => 'Group(s) Added'}
|
107
|
+
rescue => ex
|
108
|
+
Rails.logger.error ex.message
|
109
|
+
Rails.logger.error ex.backtrace.join("\n")
|
110
|
+
|
111
|
+
ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
|
112
|
+
|
113
|
+
render :json => {:success => false, :message => ex.message}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def remove
|
118
|
+
begin
|
119
|
+
type = params[:type]
|
120
|
+
id = params[:id]
|
121
|
+
selected = JSON.parse(params[:group_ids])
|
122
|
+
|
123
|
+
assign_to = type.constantize.find(id)
|
124
|
+
selected.each do |group_id|
|
125
|
+
group = Group.find(group_id)
|
126
|
+
case type
|
127
|
+
when 'User'
|
128
|
+
group.remove_user(assign_to)
|
129
|
+
when 'SecurityRole'
|
130
|
+
group.remove_role(assign_to)
|
131
|
+
when 'Capability'
|
132
|
+
group.remove_capability(assign_to)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
render :json => {:success => true, :message => 'Group(s) Removed'}
|
137
|
+
rescue => ex
|
138
|
+
Rails.logger.error ex.message
|
139
|
+
Rails.logger.error ex.backtrace.join("\n")
|
140
|
+
|
141
|
+
ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
|
142
|
+
|
143
|
+
render :json => {:success => false, :message => ex.message}
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def create
|
148
|
+
begin
|
149
|
+
ActiveRecord::Base.connection.transaction do
|
150
|
+
group = Group.create(description: params[:description].strip)
|
151
|
+
|
152
|
+
render json: {success: true, security_role: group.to_data_hash}
|
153
|
+
end
|
154
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
155
|
+
Rails.logger.error invalid.record.errors
|
156
|
+
|
157
|
+
message = "<ul>"
|
158
|
+
invalid.record.errors.collect do |e, m|
|
159
|
+
message << "<li>#{e} #{m}</li>"
|
160
|
+
end
|
161
|
+
message << "</ul>"
|
162
|
+
|
163
|
+
render :json => {:success => false, :message => message}
|
164
|
+
rescue StandardError => ex
|
165
|
+
Rails.logger.error ex.message
|
166
|
+
Rails.logger.error ex.backtrace.join("\n")
|
167
|
+
|
168
|
+
ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
|
169
|
+
|
170
|
+
render :json => {:success => false, :message => 'Error creating Group'}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def update
|
175
|
+
begin
|
176
|
+
ActiveRecord::Base.connection.transaction do
|
177
|
+
group = Group.find(params[:id])
|
178
|
+
|
179
|
+
group.description = params[:description].strip
|
180
|
+
group.save!
|
181
|
+
|
182
|
+
render json: {success: true, group: group.to_data_hash}
|
183
|
+
end
|
184
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
185
|
+
Rails.logger.error invalid.record.errors
|
186
|
+
|
187
|
+
message = "<ul>"
|
188
|
+
invalid.record.errors.collect do |e, m|
|
189
|
+
message << "<li>#{e} #{m}</li>"
|
190
|
+
end
|
191
|
+
message << "</ul>"
|
192
|
+
|
193
|
+
render :json => {:success => false, :message => message}
|
194
|
+
rescue StandardError => ex
|
195
|
+
Rails.logger.error ex.message
|
196
|
+
Rails.logger.error ex.backtrace.join("\n")
|
197
|
+
|
198
|
+
ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
|
199
|
+
|
200
|
+
render :json => {:success => false, :message => 'Error update Group'}
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def destroy
|
205
|
+
group = Group.find(params[:id])
|
206
|
+
|
207
|
+
render json: {success: group.destroy}
|
208
|
+
end
|
209
|
+
|
210
|
+
def effective_security
|
211
|
+
begin
|
212
|
+
render :json => {:success => true, :capabilities => Group.find(params[:id]).class_capabilities_to_hash}
|
213
|
+
rescue => ex
|
214
|
+
Rails.logger.error ex.message
|
215
|
+
Rails.logger.error ex.backtrace.join("\n")
|
216
|
+
|
217
|
+
ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier
|
218
|
+
|
219
|
+
render :inline => {:success => false, :message => ex.message}
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
protected
|
224
|
+
|
225
|
+
def page
|
226
|
+
offset = params[:start].to_f
|
227
|
+
offset > 0 ? (offset / params[:limit].to_f).to_i + 1 : 1
|
228
|
+
end
|
229
|
+
|
230
|
+
def per_page
|
231
|
+
params[:limit].nil? ? 10 : params[:limit].to_i
|
232
|
+
end
|
233
|
+
|
234
|
+
end # GroupsController
|
235
|
+
end # V1
|
236
|
+
end # Api
|