phi_attrs 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phi_attrs/phi_record.rb +18 -3
- data/lib/phi_attrs/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07c9497b2d8b7c17ad211cd9bd9ed40fdf669e78
|
4
|
+
data.tar.gz: 3e42b4499d9b45d1f46a52d325869f171becb27d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f4e4acdcc682ba9b0cca43644f39a248ea3878e2138d8c6105246c74d9df6c1ad1c304cec13a790398c7430b70b140f56d60e701e973c374a9dfc250ef65a3c
|
7
|
+
data.tar.gz: 67737de996af40fa8ceea1b68a69f2ce516e7035c02d0e70183e8b56058e2a17ea2e6d5fb2030cf9df25a0e688072e1cc871c0b41ae365544f50132cf6a26bd0
|
data/lib/phi_attrs/phi_record.rb
CHANGED
@@ -13,6 +13,7 @@ module PhiAttrs
|
|
13
13
|
after_initialize :wrap_phi
|
14
14
|
|
15
15
|
self.__phi_methods_wrapped = []
|
16
|
+
self.__phi_extended_methods = []
|
16
17
|
end
|
17
18
|
|
18
19
|
class_methods do
|
@@ -59,11 +60,14 @@ module PhiAttrs
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def __phi_wrapped_methods
|
62
|
-
|
63
|
+
associations = self.class.reflect_on_all_associations.map(&:name).map(&:to_s)
|
64
|
+
excluded_methods = self.class.__phi_exclude_methods.to_a
|
65
|
+
included_methods = self.class.__phi_include_methods.to_a
|
66
|
+
associations + attribute_names - excluded_methods + included_methods - [self.class.primary_key]
|
63
67
|
end
|
64
68
|
|
65
69
|
def allow_phi!(user_id, reason)
|
66
|
-
PhiAttrs::Logger.tagged(
|
70
|
+
PhiAttrs::Logger.tagged(*phi_log_keys) do
|
67
71
|
@__phi_access_allowed = true
|
68
72
|
@__phi_user_id = user_id
|
69
73
|
@__phi_access_reason = reason
|
@@ -112,10 +116,21 @@ module PhiAttrs
|
|
112
116
|
raise PhiAttrs::Exceptions::PhiAccessException, "Attempted PHI access for #{self.class.name} #{@__phi_user_id}" unless phi_allowed?
|
113
117
|
|
114
118
|
unless @__phi_access_logged
|
115
|
-
PhiAttrs::Logger.info("'#{phi_allowed_by}' accessing #{self.class.name}
|
119
|
+
PhiAttrs::Logger.info("'#{phi_allowed_by}' accessing #{self.class.name}. Triggered by method: #{method_name}")
|
116
120
|
@__phi_access_logged = true
|
117
121
|
end
|
118
122
|
|
123
|
+
# extend PHI access to relationships if needed
|
124
|
+
if self.class.__phi_extended_methods.include? method_name
|
125
|
+
|
126
|
+
# get the unwrapped relation
|
127
|
+
relation = send(unwrapped_method, *args, &block)
|
128
|
+
|
129
|
+
if relation.class.included_modules.include?(PhiRecord)
|
130
|
+
relation.allow_phi!(phi_allowed_by, phi_access_reason) unless relation.phi_allowed?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
119
134
|
send(unwrapped_method, *args, &block)
|
120
135
|
end
|
121
136
|
end
|
data/lib/phi_attrs/version.rb
CHANGED