phi_attrs 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f28f8b165404acd488de741070670268bb5e1a3
4
- data.tar.gz: 8610013fc23d93100ba5829327a85c32516a2f38
3
+ metadata.gz: 07c9497b2d8b7c17ad211cd9bd9ed40fdf669e78
4
+ data.tar.gz: 3e42b4499d9b45d1f46a52d325869f171becb27d
5
5
  SHA512:
6
- metadata.gz: 4b181df2aacce039f31c31a97051434f99a5dc96f975f2668eba97a7d7cff0a357f6aed8eca75a03a75945b1b4489083e489318e4ba680a446968b93d3142285
7
- data.tar.gz: 1bfa9fac24405baa8a8e3e91eb8f5db4f7602413254143d9b8526d61f45f396250351bb333ca99da35a49a293d303521466974c79ffa0a83ecf9ce8e391463a7
6
+ metadata.gz: 7f4e4acdcc682ba9b0cca43644f39a248ea3878e2138d8c6105246c74d9df6c1ad1c304cec13a790398c7430b70b140f56d60e701e973c374a9dfc250ef65a3c
7
+ data.tar.gz: 67737de996af40fa8ceea1b68a69f2ce516e7035c02d0e70183e8b56058e2a17ea2e6d5fb2030cf9df25a0e688072e1cc871c0b41ae365544f50132cf6a26bd0
@@ -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
- attribute_names - self.class.__phi_exclude_methods.to_a + self.class.__phi_include_methods.to_a - [self.class.primary_key]
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( *phi_log_keys ) do
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}.\n\t access logging triggered by method: #{method_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
@@ -1,3 +1,3 @@
1
1
  module PhiAttrs
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phi_attrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Kirby