Changeset 2352
- Timestamp:
- 05/26/20 02:14:04 (4 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/MANIFEST
r2296 r2352 100 100 lib/LATMOS/Accounts/Bases/Sql/Stat.pm 101 101 lib/LATMOS/Accounts/Bases/Sql/Sutype.pm 102 lib/LATMOS/Accounts/Bases/Sql/Templates.pm 102 103 lib/LATMOS/Accounts/Bases/Sql/User.pm 103 104 lib/LATMOS/Accounts/Bases/Sql/Userstatus.pm … … 159 160 man/man8/latmos-accounts-faq.pod 160 161 man/man8/latmos-accounts.pod 162 patchset/logas_in_cli.patch 161 163 patchset/no_useless_load.patch 162 164 sample/allowed_values.ini -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r2351 r2352 433 433 return; 434 434 } 435 foreach my $cfield (keys %cdata) { 436 $self->check_allowed_values($otype, $cfield, $cdata{$cfield}) or do { 437 my $last = LATMOS::Accounts::Log::lastmessage(LA_ERR); 438 $self->log(LA_ERR, "Cannot create $otype, wrong value%s", ($last ? ": $last" : '')); 439 return; 440 }; 441 } 435 436 my %data; 442 437 443 438 # populating default value … … 445 440 my %default = $self->compute_default($otype, $id, %cdata); 446 441 foreach my $k (keys %default) { 447 $cdata{$k} = $default{$k} unless(exists($cdata{$k})); 448 } 449 } 450 451 my %data; 442 $data{$k} = $default{$k}; 443 } 444 } 445 446 if ( $self->is_supported_object('templates') ) { 447 if ( $cdata{template} ) { 448 my $template = $self->get_object('templates', $cdata{template} ) or do { 449 $self->log(LA_ERR, "Cannot load template $cdata{template}"); 450 return; 451 }; 452 453 my $TOType = $template->_get_attributes('objecttype'); 454 if ( $TOType ne $otype ) { 455 $self->log(LA_ERR, "Template $cdata{template} is for object type $TOType, not $otype"); 456 return; 457 } 458 459 my $text = join('\n', $template->_get_attributes('data')); 460 my %tdata = LATMOS::Accounts::Utils::parse_obj_text($text || ''); 461 462 foreach my $k ( keys %tdata ) { 463 $data{$k} = $tdata{$k}; 464 } 465 466 delete( $cdata{template} ); 467 } 468 } 469 452 470 my $sub; 453 471 foreach my $cfield (keys %cdata) { … … 462 480 $data{$cfield} = $cdata{$cfield}; 463 481 } 482 } 483 484 foreach my $cfield (keys %data) { 485 $self->check_allowed_values($otype, $cfield, $data{$cfield}) or do { 486 my $last = LATMOS::Accounts::Log::lastmessage(LA_ERR); 487 $self->log(LA_ERR, "Cannot create $otype, wrong value%s", ($last ? ": $last" : '')); 488 return; 489 }; 464 490 } 465 491 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r2296 r2352 18 18 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 19 19 20 sub SCHEMA_VERSION { 3 6};20 sub SCHEMA_VERSION { 37 }; 21 21 22 22 =head1 NAME -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r2328 r2352 262 262 ) ]; 263 263 }, 264 }, 265 template => { 266 reference => 'templates', 267 can_values => sub { 268 $base->search_objects('templates', 'objectType=' . $class->type, 'exported=1') 269 }, 270 ro => sub { ref $_[0] ? 1 : 0 }, 271 set => sub {}, 264 272 }, 265 273 ); -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm
r2296 r2352 1318 1318 ], 1319 1319 }, 1320 { 1321 ver => 37, 1322 sql => [ 1323 qq{ 1324 CREATE TABLE public."templates" 1325 ( 1326 objectType text not NULL, 1327 data text[], 1328 CONSTRAINT template_pkey PRIMARY KEY (name) 1329 ) 1330 INHERITS (public.objects) 1331 WITH ( 1332 OIDS=FALSE 1333 ); 1334 1335 CREATE INDEX templates_rev_idx 1336 ON public."templates" 1337 USING btree 1338 (rev); 1339 1340 CREATE INDEX templates_exported_idx 1341 ON public."templates" 1342 USING btree 1343 (exported); 1344 1345 CREATE TRIGGER templates_rev_tg 1346 BEFORE UPDATE OR DELETE 1347 ON public."templates" 1348 FOR EACH ROW 1349 EXECUTE PROCEDURE public.rev_tg_f(); 1350 } 1351 ], 1352 }, 1320 1353 ); 1354 1321 1355 1322 1356 my $dbi = $self->{_db}; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r2175 r2352 106 106 } 107 107 108 sub _parse_line { 109 my ( $line, $attributes ) = @_; 110 111 $line =~ /^#/ and return; 112 # Empty line are skipped (or space only) 113 $line =~ /^\s*$/ and return; 114 chomp($line); 115 my ($attr, $value) = $line =~ /^\s*(\S+):\s*(.*)\s*$/ or 116 die "Malformed input file\n"; 117 $value =~ s/\s*$//; 118 $value =~ s/\\n/\n/g; 119 if ($attributes->{$attr}) { 120 if (ref $attributes->{$attr}) { 121 push(@{ $attributes->{$attr} }, $value); 122 } else { 123 my $temp = $attributes->{$attr}; 124 $attributes->{$attr} = [ $temp, $value ]; 125 } 126 } else { 127 $attributes->{$attr} = $value eq '' ? undef : $value; 128 # Don't remember why this is here 129 #$attr eq 'exported' && !defined $attributes->{$attr} and $attributes->{$attr} = 1; 130 } 131 } 132 108 133 =head2 parse_obj_file($handle) 109 134 … … 115 140 my ($handle) = @_; 116 141 117 my %attributes;142 my $attributes = {}; 118 143 while (my $line = <$handle>) { 119 $line =~ /^#/ and next; 120 # Empty line are skipped (or space only) 121 $line =~ /^\s*$/ and next; 122 chomp($line); 123 my ($attr, $value) = $line =~ /^\s*(\S+):\s*(.*)\s*$/ or 124 die "Malformed input file\n"; 125 $value =~ s/\s*$//; 126 $value =~ s/\\n/\n/g; 127 if ($attributes{$attr}) { 128 if (ref $attributes{$attr}) { 129 push(@{ $attributes{$attr} }, $value); 130 } else { 131 my $temp = $attributes{$attr}; 132 $attributes{$attr} = [ $temp, $value ]; 133 } 134 } else { 135 $attributes{$attr} = $value eq '' ? undef : $value; 136 # Don't remember why this is here 137 #$attr eq 'exported' && !defined $attributes{$attr} and $attributes{$attr} = 1; 138 } 139 } 140 %attributes 144 _parse_line( $line, $attributes ); 145 } 146 %$attributes 147 } 148 149 =head2 parse_obj_text($text) 150 151 =cut 152 153 sub parse_obj_text { 154 my ( $Text ) = @_; 155 156 my $attributes = {}; 157 158 foreach (split(/\n/, $Text)) { 159 _parse_line( $_, $attributes ); 160 } 161 162 %$attributes 141 163 } 142 164 -
trunk/LATMOS-Accounts/t/05_utils.t
r2071 r2352 1 1 use strict; 2 2 use warnings; 3 use Test::More tests => 4 6;3 use Test::More tests => 48; 4 4 use File::Temp qw(mkstemp); 5 5 … … 27 27 is($attributes{'attr1'}, 'attr1', "can get attribute from file"); 28 28 ok(eq_set($attributes{'attr'}, [ qw(val1 val2) ]), 29 "can get multiple values attribute"); 30 31 my %attributes2 = LATMOS::Accounts::Utils::parse_obj_text( 32 <<EOF 33 attr1: attr1 34 attr: val1 35 attr: val2 36 EOF 37 ); 38 39 # now testing 40 is($attributes2{'attr1'}, 'attr1', "can get attribute from file"); 41 ok(eq_set($attributes2{'attr'}, [ qw(val1 val2) ]), 29 42 "can get multiple values attribute"); 30 43
Note: See TracChangeset
for help on using the changeset viewer.