erp_tech_svcs 3.0.10 → 3.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/attribute_type.rb +1 -1
- data/app/models/capability.rb +54 -2
- data/app/models/capability_accessor.rb +4 -0
- data/app/models/extensions/party.rb +1 -0
- data/app/models/file_asset.rb +15 -5
- data/app/models/group.rb +149 -0
- data/app/models/scope_type.rb +5 -0
- data/app/models/security_role.rb +46 -0
- data/app/models/user.rb +99 -5
- data/db/data_migrations/20110109173616_create_capability_scope_types.rb +14 -0
- data/db/data_migrations/20121116155018_create_group_relationship_and_role_types.rb +19 -0
- data/db/data_migrations/20121130212146_note_capabilities.rb +23 -0
- data/db/migrate/20080805000010_base_tech_services.rb +44 -31
- data/db/migrate/20121116151510_create_groups.rb +18 -0
- data/db/migrate/20121126171612_upgrade_security.rb +53 -0
- data/db/migrate/20121126173506_upgrade_security2.rb +274 -0
- data/lib/erp_tech_svcs/engine.rb +7 -7
- data/lib/erp_tech_svcs/extensions/active_record/base.rb +17 -0
- data/lib/erp_tech_svcs/extensions/active_record/has_capability_accessors.rb +131 -0
- data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +9 -1
- data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +89 -0
- data/lib/erp_tech_svcs/extensions/active_record/protected_with_capabilities.rb +203 -0
- data/lib/erp_tech_svcs/extensions.rb +4 -2
- data/lib/erp_tech_svcs/file_support/manager.rb +1 -1
- data/lib/erp_tech_svcs/file_support/s3_manager.rb +3 -3
- data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +29 -24
- data/lib/erp_tech_svcs/version.rb +1 -1
- data/spec/lib/erp_tech_svcs/extensions/active_record/has_roles_spec.rb +4 -5
- data/spec/models/role_spec.rb +2 -2
- data/spec/models/secured_model_spec.rb +1 -1
- data/spec/models/user_spec.rb +2 -2
- metadata +137 -129
- data/app/models/capable_model.rb +0 -4
- data/app/models/role.rb +0 -17
- data/app/models/secured_model.rb +0 -15
- data/db/data_migrations/20120109173616_create_download_capability_type.rb +0 -13
- data/lib/erp_tech_svcs/extensions/active_record/has_capabilities.rb +0 -152
- data/lib/erp_tech_svcs/extensions/active_record/has_roles.rb +0 -130
@@ -1,130 +0,0 @@
|
|
1
|
-
module ErpTechSvcs
|
2
|
-
module Extensions
|
3
|
-
module ActiveRecord
|
4
|
-
module HasRoles
|
5
|
-
|
6
|
-
module Errors
|
7
|
-
exceptions = %w[UserDoesNotHaveAccess]
|
8
|
-
exceptions.each { |e| const_set(e, Class.new(StandardError)) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.included(base)
|
12
|
-
base.extend(ClassMethods)
|
13
|
-
end
|
14
|
-
|
15
|
-
module ClassMethods
|
16
|
-
def has_roles
|
17
|
-
extend HasRoles::SingletonMethods
|
18
|
-
include HasRoles::InstanceMethods
|
19
|
-
|
20
|
-
after_initialize :initialize_secured_model
|
21
|
-
after_update :save_secured_model
|
22
|
-
after_create :save_secured_model
|
23
|
-
after_destroy :destroy_secured_model
|
24
|
-
|
25
|
-
has_one :secured_model, :as => :secured_record, :include => :roles
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
module SingletonMethods
|
30
|
-
end
|
31
|
-
|
32
|
-
module InstanceMethods
|
33
|
-
def roles
|
34
|
-
self.secured_model.roles
|
35
|
-
end
|
36
|
-
|
37
|
-
def has_access?(user)
|
38
|
-
has_access = true
|
39
|
-
unless self.secured_model.roles.empty?
|
40
|
-
has_access = if user.nil?
|
41
|
-
false
|
42
|
-
else
|
43
|
-
user.has_role?(self.secured_model.roles.collect{|item| item.internal_identifier})
|
44
|
-
end
|
45
|
-
end
|
46
|
-
has_access
|
47
|
-
end
|
48
|
-
|
49
|
-
def with_access(user, &block)
|
50
|
-
if has_access?(user)
|
51
|
-
yield
|
52
|
-
else
|
53
|
-
raise ErpTechSvcs::Extensions::ActiveRecord::HasRoles::UserDoesNotHaveAccess
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_role(role)
|
58
|
-
role = role.is_a?(Role) ? role : Role.find_by_internal_identifier(role.to_s)
|
59
|
-
unless self.has_role?(role)
|
60
|
-
self.secured_model.roles << role
|
61
|
-
self.secured_model.save
|
62
|
-
self.reload
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def add_roles(*roles)
|
67
|
-
roles.flatten!
|
68
|
-
roles = roles[0] if roles[0].is_a? Array
|
69
|
-
roles.each do |role|
|
70
|
-
self.add_role(role)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def remove_role(role)
|
75
|
-
role = role.is_a?(Role) ? role : Role.find_by_internal_identifier(role.to_s)
|
76
|
-
self.secured_model.roles.delete(role) if has_role?(role)
|
77
|
-
end
|
78
|
-
|
79
|
-
def remove_roles(*roles)
|
80
|
-
roles.flatten!
|
81
|
-
roles.each do |role|
|
82
|
-
self.remove_role(role)
|
83
|
-
self.reload
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def remove_all_roles
|
88
|
-
self.roles.delete_all
|
89
|
-
self.reload
|
90
|
-
end
|
91
|
-
|
92
|
-
def has_role?(*passed_roles)
|
93
|
-
result = false
|
94
|
-
passed_roles.flatten!
|
95
|
-
passed_roles.each do |role|
|
96
|
-
role_iid = role.is_a?(Role) ? role.internal_identifier : role.to_s
|
97
|
-
self.roles.each do |this_role|
|
98
|
-
result = true if (this_role.internal_identifier == role_iid)
|
99
|
-
break if result
|
100
|
-
end
|
101
|
-
break if result
|
102
|
-
end
|
103
|
-
result
|
104
|
-
end
|
105
|
-
|
106
|
-
def initialize_secured_model
|
107
|
-
if self.new_record? && self.secured_model.nil?
|
108
|
-
secured_model = SecuredModel.new
|
109
|
-
self.secured_model = secured_model
|
110
|
-
secured_model.secured_record = self
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def save_secured_model
|
115
|
-
secured_model.save
|
116
|
-
end
|
117
|
-
|
118
|
-
def destroy_secured_model
|
119
|
-
if self.secured_model && !self.secured_model.frozen?
|
120
|
-
self.secured_model.destroy
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
end #HasRoles
|
126
|
-
end #ActiveRecord
|
127
|
-
end #Extensions
|
128
|
-
end #ErpTechSvcs
|
129
|
-
|
130
|
-
|