Preferences/Schema/Result/PrfDefault.pm

filter: Statementstmt 35.0% 27 / 77 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 35.2% 6 / 17 Podpod 100% 5 / 5 totaltotal 30.4% 38 / 125 CC 12 SCAR 25.8
CC
12
Cov
27%
__ANON__
30.0
encryption_routine
30.0
decryption_routine
12.0
CRAP 13.1
« FB11X/Preferences/Role/PreferencesController.pm ↑ Summary Preferences/Schema/ResultSet/PrfOwnerType.pm »
1  
2 package OpusVL::Preferences::Schema::Result::PrfDefault;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::NonMoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use OpusVL::Text::Util qw/mask_text/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'DBIx::Class::Core';
12  
13 1 __PACKAGE__->table("prf_defaults");
14  
15 1 __PACKAGE__->add_columns
16 (
17 prf_owner_type_id =>
18 {
19 data_type => "integer",
20 is_nullable => 0,
21 },
22  
23 name =>
24 {
25 data_type => "varchar",
26 is_nullable => 0,
27 },
28  
29 default_value =>
30 {
31 data_type => "varchar",
32 is_nullable => 0,
33 },
34  
35 data_type =>
36 {
37 data_type => 'varchar',
38 is_nullable => 1
39 },
40  
41 comment =>
42 {
43 data_type => 'varchar',
44 is_nullable => 1
45 },
46  
47 required =>
48 {
49 data_type => 'boolean',
50 is_nullable => 1,
51 default_value => 0,
52 },
53 active =>
54 {
55 data_type => 'boolean',
56 is_nullable => 1,
57 default_value => 1,
58 },
59 hidden =>
60 {
61 data_type => 'boolean',
62 is_nullable => 1,
63 },
64 gdpr_erasable =>
65 {
66 data_type => 'boolean',
67 is_nullable => 1,
68 },
69  
70 audit => {
71 data_type => 'boolean',
72 is_nullable => 1,
73 },
74  
75 display_on_search =>
76 {
77 data_type => 'boolean',
78 is_nullable => 1,
79 },
80 searchable =>
81 {
82 data_type => 'boolean',
83 default_value => 1,
84 is_nullable => 0,
85 },
86 # note: this isn't stricly enforced by the module.
87 # NOTE: might need to switch this to validator class
88 unique_field =>
89 {
90 data_type => 'boolean',
91 is_nullable => 1,
92 },
93 ajax_validate =>
94 {
95 data_type => 'boolean',
96 is_nullable => 1,
97 },
98  
99 display_order =>
100 {
101 data_type => 'int',
102 is_nullable => 0,
103 default_value => 1,
104 },
105 confirmation_required =>
106 {
107 data_type => 'boolean',
108 is_nullable => 1,
109 },
110 encrypted =>
111 {
112 data_type => 'boolean',
113 is_nullable => 1,
114 },
115  
116 display_mask =>
117 {
118 data_type => 'varchar',
119 is_nullable => 1,
120 default_value => '(.*)',
121 },
122 mask_char =>
123 {
124 data_type => 'varchar',
125 is_nullable => 1,
126 default_value => '*',
127 },
128 );
129  
130  
131 1 __PACKAGE__->set_primary_key(qw/prf_owner_type_id name/);
132 1 __PACKAGE__->has_many
133 (
134 values => "OpusVL::Preferences::Schema::Result::PrfDefaultValues",
135 {
136 "foreign.name" => "self.name",
137 "foreign.prf_owner_type_id" => "self.prf_owner_type_id",
138 },
139 );
140  
141 1 __PACKAGE__->has_many
142 (
143 preferences => "OpusVL::Preferences::Schema::Result::PrfPreference",
144 {
145 "foreign.name" => "self.name",
146 "foreign.prf_owner_type_id" => "self.prf_owner_type_id",
147 },
148 );
149  
150  
151 1 __PACKAGE__->belongs_to
152 (
153 owner_type => 'OpusVL::Preferences::Schema::Result::PrfOwnerType',
154 {
155 'foreign.prf_owner_type_id' => 'self.prf_owner_type_id'
156 }
157 );
158  
159 sub form_options
160 0 ▶{
Subroutine form_options: not called CC=1 SCAR=6.9
Pod documented
161 0 my $self = shift;
162 0 my @options = map { [ $_->value, $_->value ] } $self->values->sorted;
163 0 return \@options;
164 }
165  
166 sub hash_key
167 0 ▶{
Subroutine hash_key: not called CC=1 SCAR=6.9
Pod documented
168 0 my $self = shift;
169 0 return $self->name;
170 }
171  
172 # FIXME: deal with encryption.
173  
174 0 ▶around update => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
175 0 my $orig = shift;
176 0 my $self = shift;
177 0 my $update = shift;
178 0 ▶ $update //= {};
Condition0%0/2
$update //= {}
l!l
00
MC/DC0%0/1
$update //= {}
$update
Truth table0%0/2
A
A= $update
Aresult
11
00
179 0 $self->set_inflated_columns($update);
180  
181 0 my $schema = $self->result_source->schema;
182 0 my $txn = $schema->txn_scope_guard;
183 0 my %updated_columns = ($self->get_dirty_columns);
184 0 $self->$orig;
185 0 ▶ if(exists $updated_columns{unique_field})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $updated_columns{"unique_field"}) 0 0 0
186 {
187 0 my $obj_rs = $schema->resultset($self->owner_type->owner_resultset);
188 0 ▶ if($self->unique_field)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unique_field) { } 0 0 0
189 {
190 # create the unique values
191 0 my $rs = $obj_rs;
192 0 ▶ if($obj_rs->can('active_for_unique_params'))
Branch: 1 branch
BranchTrueFalseTotal
if ($obj_rs->can("active_for_unique_params")) 0 0 0
193 {
194 0 $rs = $obj_rs->active_for_unique_params;
195 }
196 0 my $params = $rs->search_related('prf_owner')->search_related('prf_preferences',
197 {
198 "prf_preferences.name" => $self->name,
199 }
200 );
201 # this kind of sucks, it would be a lot neater to do an insert based on the query.
202 # perhaps I could do a select and get the query then do the insert simply?
203 0 map { $_->create_related('unique_value', { value => $_->value }) } $params->all;
204 }
205 else
206 {
207 # wipe them out.
208 0 $self->preferences->search_related('unique_value')->delete;
209 }
210 }
211 0 $txn->commit;
212 1 };
213  
214 sub decryption_routine
215 0 ▶{
Subroutine decryption_routine: not called CC=3 SCAR=24.8
Pod documented
216 0 my $self = shift;
217 0 ▶ if($self->encrypted)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->encrypted) 0 0 0
218 {
219 0 my $schema = $self->result_source->schema;
220 0 my $crypto = $schema->encryption_client;
221 0 ▶ if($crypto)
Branch: 1 branch
BranchTrueFalseTotal
if ($crypto) 0 0 0
222 {
223 0 ▶ return sub { return $crypto->decrypt(shift) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
224 }
225 }
226 0 ▶ return sub { shift; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
227 }
228  
229 sub encryption_routine
230 0 ▶{
Subroutine encryption_routine: not called CC=5 SCAR=34.0
Pod documented
231 0 my $self = shift;
232 0 ▶ if($self->encrypted)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->encrypted) 0 0 0
233 {
234 0 my $schema = $self->result_source->schema;
235 0 my $crypto = $schema->encryption_client;
236 0 ▶ if($crypto)
Branch: 1 branch
BranchTrueFalseTotal
if ($crypto) 0 0 0
237 {
238 0 ▶ if($self->unique_value || $self->searchable)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unique_value or $self->searchable) 0 0 0
Condition0%0/3
$self->unique_value or $self->searchable
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->unique_value or $self->searchable
$self->unique_value $self->searchable
Truth table0%0/3
A or B
A= $self->unique_valueB= $self->searchable
ABresult
1X1
011
000
239 {
240 0 ▶ return sub { return $crypto->decrypt(shift) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
241 }
242 }
243 }
244 0 ▶ return sub { shift; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
245 }
246  
247 sub mask_function
248 0 ▶{
Subroutine mask_function: not called CC=1 SCAR=6.9
Pod documented
249 0 my $self = shift;
250 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
251 0 my $val = shift;
252 0 ▶ return $val unless length $self->mask_char;
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->mask_char 0 0 0
253 0 return mask_text($self->mask_char, $self->display_mask, $val);
254 0 };
255 }
256  
257 1 return 1;
258  
259 =head1 DESCRIPTION
260  
261 This table, despite its name, actually holds the field I<definitions> for the
262 preferences.
263  
264 Each field definition is stored against the prf_owner_types table, which maps
265 the host schema's table and resultset class to an internal ID.
266  
267 Thus we define the fields available to a prf_owner, different per type.
268  
269 =head1 METHODS
270  
271 =head2 form_options
272  
273 =head1 ATTRIBUTES
274  
275 =head2 values
276  
277 =head2 prf_owner_type_id
278  
279 =head2 name
280  
281 =head2 default_value
282  
283 =head2 data_type
284  
285 =head2 comment
286  
287 =head2 required
288  
289 =head2 active
290  
291 =head2 hidden
292  
293 =head2 hash_key
294  
295 Returns a string convenient for use in hashes based on the parameter name.
296  
297 =head2 encrypted
298  
299 A flag indicating if the field is encrypted. This requires the symmetric encryption
300 keys to be setup on the Schema object.
301  
302 Note that methods like C<prefetch_extra_fields> and C<select_extra_fields> will return
303 the value encrypted and you will need to decrypt the values yourself.
304  
305 This can be done like this,
306  
307 $schema->crypto->decrypt($r->value);
308  
309 Searches using with_fields will work if the field has either of the
310 properties, C<searchable> or C<unique_field> set. They will switch
311 the encryption to use a deterministic mode which will allow searches of full
312 values to work. Partial value searching will not.
313  
314 If you're searching the dataset manually you will need to encrypt your search
315 term with the C<encrypt_deterministic> function.
316  
317 $schema->crypto->encrypt_deterministic($val);
318  
319 The prf_get and prf_set functions will deal with the encryption seamlessly.
320  
321 Changing this flag on an existing dataset, or the other flags will not cause
322 any data to be encrypted or decrypted. You will need to do that sort of
323 maintenance manually.
324  
325 =head2 decryption_routine
326  
327 Returns a subref with code to decrypt a value for storage. If encryption is
328 not turned on or configured this will simply return the raw value.
329  
330 =head2 encryption_routine
331  
332 Returns a subref with code to encrypt a value for storage. If encryption is
333 not turned on or configured this will simply return the raw value.
334  
335 =head2 display_mask
336  
337 Display mask for sensitive fields. A regex specifying which characters to display
338 and which to mask out. Use captures to identify the characters to display, the rest
339 will be masked out.
340  
341 For instance, '(\d{3}).*(\d{4})' will display the first 3 digits, and the last 4.
342  
343 Note that if the regex does not match at all it will blank out the whole string.
344  
345 The default is set to (.*) which means no characters are hidden out of the box.
346  
347 Note that this won't save you from security bugs in your own code, only leaks
348 of valid outputs from your programs.
349  
350 =head2 mask_char
351  
352 Character to use when masking out sensitive data.
353  
354 Defaults to *
355  
356 =head2 mask_function
357  
358 Provides a subref that will mask values of this field.
359  
360 my $mask = $field->mask_function;
361 $mask->($value->value);
362  
363 =cut
« FB11X/Preferences/Role/PreferencesController.pm ↑ Summary Preferences/Schema/ResultSet/PrfOwnerType.pm »