Preferences/Schema/Result/PrfDefault.pm

filter: Statementstmt 35.5% 27 / 76 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 35.2% 6 / 17 Podpod 100% 5 / 5 totaltotal 31.1% 38 / 122 CC 11 SCAR 25.8
CC
11
Cov
28%
__ANON__
30.0
encryption_routine
30.0
decryption_routine
12.0
CRAP 13.3
« Preferences/RolesFor/ResultSet/PrfOwner.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  
65 audit => {
66 data_type => 'boolean',
67 is_nullable => 1,
68 },
69  
70 display_on_search =>
71 {
72 data_type => 'boolean',
73 is_nullable => 1,
74 },
75 searchable =>
76 {
77 data_type => 'boolean',
78 default_value => 1,
79 is_nullable => 0,
80 },
81 # note: this isn't stricly enforced by the module.
82 # NOTE: might need to switch this to validator class
83 unique_field =>
84 {
85 data_type => 'boolean',
86 is_nullable => 1,
87 },
88 ajax_validate =>
89 {
90 data_type => 'boolean',
91 is_nullable => 1,
92 },
93  
94 display_order =>
95 {
96 data_type => 'int',
97 is_nullable => 0,
98 default_value => 1,
99 },
100 confirmation_required =>
101 {
102 data_type => 'boolean',
103 is_nullable => 1,
104 },
105 encrypted =>
106 {
107 data_type => 'boolean',
108 is_nullable => 1,
109 },
110  
111 display_mask =>
112 {
113 data_type => 'varchar',
114 is_nullable => 0,
115 default_value => '(.*)',
116 },
117 mask_char =>
118 {
119 data_type => 'varchar',
120 is_nullable => 0,
121 default_value => '*',
122 },
123 );
124  
125  
126 1 __PACKAGE__->set_primary_key(qw/prf_owner_type_id name/);
127 1 __PACKAGE__->has_many
128 (
129 values => "OpusVL::Preferences::Schema::Result::PrfDefaultValues",
130 {
131 "foreign.name" => "self.name",
132 "foreign.prf_owner_type_id" => "self.prf_owner_type_id",
133 },
134 );
135  
136 1 __PACKAGE__->has_many
137 (
138 preferences => "OpusVL::Preferences::Schema::Result::PrfPreference",
139 {
140 "foreign.name" => "self.name",
141 "foreign.prf_owner_type_id" => "self.prf_owner_type_id",
142 },
143 );
144  
145  
146 1 __PACKAGE__->belongs_to
147 (
148 owner_type => 'OpusVL::Preferences::Schema::Result::PrfOwnerType',
149 {
150 'foreign.prf_owner_type_id' => 'self.prf_owner_type_id'
151 }
152 );
153  
154 sub form_options
155 {
156 0 ▶ my $self = shift;
Subroutine form_options: not called CC=1 SCAR=6.9
Pod documented
157 0 my @options = map { [ $_->value, $_->value ] } $self->values->sorted;
158 0 return \@options;
159 }
160  
161 sub hash_key
162 {
163 0 ▶ my $self = shift;
Subroutine hash_key: not called CC=1 SCAR=6.9
Pod documented
164 0 return $self->name;
165 }
166  
167 # FIXME: deal with encryption.
168  
169 around update => sub {
170 0 ▶ my $orig = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
171 0 my $self = shift;
172 0 my $update = shift;
173 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
174 0 $self->set_inflated_columns($update);
175  
176 0 my $schema = $self->result_source->schema;
177 0 my $txn = $schema->txn_scope_guard;
178 0 my %updated_columns = ($self->get_dirty_columns);
179 0 $self->$orig;
180 0 ▶ if(exists $updated_columns{unique_field})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $updated_columns{"unique_field"}) 0 0 0
181 {
182 0 my $obj_rs = $schema->resultset($self->owner_type->owner_resultset);
183 0 ▶ if($self->unique_field)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unique_field) { } 0 0 0
184 {
185 # create the unique values
186 0 my $rs = $obj_rs;
187 0 ▶ if($obj_rs->can('active_for_unique_params'))
Branch: 1 branch
BranchTrueFalseTotal
if ($obj_rs->can("active_for_unique_params")) 0 0 0
188 {
189 0 $rs = $obj_rs->active_for_unique_params;
190 }
191 0 my $params = $rs->search_related('prf_owner')->search_related('prf_preferences',
192 {
193 "prf_preferences.name" => $self->name,
194 }
195 );
196 # this kind of sucks, it would be a lot neater to do an insert based on the query.
197 # perhaps I could do a select and get the query then do the insert simply?
198 0 map { $_->create_related('unique_value', { value => $_->value }) } $params->all;
199 }
200 else
201 {
202 # wipe them out.
203 0 $self->preferences->search_related('unique_value')->delete;
204 }
205 }
206 0 $txn->commit;
207 1 };
208  
209 sub decryption_routine
210 {
211 0 ▶ my $self = shift;
Subroutine decryption_routine: not called CC=3 SCAR=24.8
Pod documented
212 0 ▶ if($self->encrypted)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->encrypted) 0 0 0
213 {
214 0 my $schema = $self->result_source->schema;
215 0 my $crypto = $schema->encryption_client;
216 0 ▶ if($crypto)
Branch: 1 branch
BranchTrueFalseTotal
if ($crypto) 0 0 0
217 {
218 0 ▶ return sub { return $crypto->decrypt(shift) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
219 }
220 }
221 0 ▶ return sub { shift; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 }
223  
224 sub encryption_routine
225 {
226 0 ▶ my $self = shift;
Subroutine encryption_routine: not called CC=5 SCAR=34.0
Pod documented
227 0 ▶ if($self->encrypted)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->encrypted) 0 0 0
228 {
229 0 my $schema = $self->result_source->schema;
230 0 my $crypto = $schema->encryption_client;
231 0 ▶ if($crypto)
Branch: 1 branch
BranchTrueFalseTotal
if ($crypto) 0 0 0
232 {
233 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
234 {
235 0 ▶ return sub { return $crypto->decrypt(shift) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
236 }
237 }
238 }
239 0 ▶ return sub { shift; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
240 }
241  
242 sub mask_function
243 {
244 0 ▶ my $self = shift;
Subroutine mask_function: not called CC=1 SCAR=6.9
Pod documented
245 return sub {
246 0 ▶ my $val = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
247 0 return mask_text($self->mask_char, $self->display_mask, $val);
248 0 };
249 }
250  
251 1 return 1;
252  
253 __END__
254  
255 =pod
256  
257 =encoding UTF-8
258  
259 =head1 NAME
260  
261 OpusVL::Preferences::Schema::Result::PrfDefault
262  
263 =head1 VERSION
264  
265 version 0.24
266  
267 =head1 DESCRIPTION
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 =head1 AUTHOR
364  
365 OpusVL - www.opusvl.com
366  
367 =head1 COPYRIGHT AND LICENSE
368  
369 This software is copyright (c) 2011 by OpusVL - www.opusvl.com.
370  
371 This is free software; you can redistribute it and/or modify it under
372 the same terms as the Perl 5 programming language system itself.
373  
374 =cut
« Preferences/RolesFor/ResultSet/PrfOwner.pm ↑ Summary Preferences/Schema/ResultSet/PrfOwnerType.pm »