--- lib/A3C/Model/User.pm 2008/03/17 13:02:50 23 +++ lib/A3C/Model/Person.pm 2008/04/11 22:02:09 77 @@ -1,7 +1,7 @@ use strict; use warnings; -package A3C::Model::User; +package A3C::Model::Person; use Jifty::DBI::Schema; use utf8; @@ -9,28 +9,26 @@ use A3C::Record schema { column uid => - label is ('uid'), + label is _('UID'), is indexed, is mandatory, is distinct; column hrEduPersonUniqueID => - label is ('hrEduPersonUniqueID'), + label is _('hr Edu Person Unique ID'), is indexed, is distinct, is mandatory; column cn => label is _('Ime i prezime'), - type is 'virtual'; + is mandatory; column sn => - type is 'virtual', label is _('Prezime'), is mandatory; column givenName => - type is 'virtual', label is _('Ime'), is mandatory; @@ -38,6 +36,7 @@ type is 'text', is mandatory, label is _('Email address'), default is '', + is indexed, is immutable, is distinct; @@ -66,7 +65,7 @@ column hrEduPersonUniqueNumber => # is mandatory, - label is _('JMBG'); + label is _('Unique number'); column hrEduPersonDateOfBirth => type is 'date', @@ -90,6 +89,11 @@ label is _('Tip administratora'), valid are [ '', 'AS', 'AI', 'AR', 'AHU' ]; + column hrEduPersonHomeOrg => + label is _('Oznaka matične ustanove'), + hint is 'CARNet', + is mandatory; + column hrEduPersonProfessionalStatus => label is _('Stručni status'), valid are [ @@ -150,6 +154,18 @@ ], default is ''; + column 'o' => + is indexed; + + column 'l'; + column 'postalAddress'; + column 'postalCode'; + column 'street'; + +# column organization => +# refers_to A3C::Model::Organization by 'id', +# is mandatory; + column hrEduPersonAffiliation => label is _('Povezanost s ustanovom'), is mandatory, @@ -253,38 +269,12 @@ label is 'Pripadnost grupi', hint is 'skolskagodina::razred'; - column o => - label is _('Naziv matične ustanove'), - is mandatory; - - column hrEduPersonHomeOrg => - label is _('Oznaka matične ustanove'), - hint is 'CARNet', - is mandatory; - column ou => label is _('Organizacijska jedinica'); column roomNumber => label is _('Broj sobe'); - column postalAddress => - label is _('Poštanska adresa'), - render as 'textarea', - is mandatory; - - column l => - label is _('Mjesto'), - hist is 'Zagreb', - is mandatory; - - column postalCode => - label is _('Poštanski broj'), - hint is 'HR-10000'; - - column street => - label is _('Ulica i kućni broj'); - column homePostalAddress => label is _('Kućna poštanska adresa'), render as 'textarea'; @@ -299,21 +289,18 @@ label is _('Oznaka privatnosti'); column loginShell => - label is _('shell'); + label is _('login shell'); column uidNumber => - label is _('uid'), + label is _('uid number'), type is 'int'; column gidNumber => - label is _('gid'); + label is _('gid number'); type is 'int'; column homeDirectory => - label is _('home'); - - column objectClass => - type is 'virtual'; + label is _('home directory'); }; @@ -351,11 +338,20 @@ sub email { my $self = shift; - return $self->__value('mail'); + return $self->mail; } sub email_confirmed { 1 }; +=head2 name + +=cut + +sub name { + my $self = shift; + return $self->cn . ' <' . $self->mail . '>'; +} + =head2 validate_telephoneNumber =cut @@ -368,6 +364,46 @@ return ( 1, 'OK' ); } +=head2 hrEduPersonUniqueNumber + +Check if JMBG is valid + +=cut + +sub validate_hrEduPersonUniqueNumber { + my ( $self, $value ) = @_; + + if ( $value =~ m/^JMBG:\s+(\d+)$/ ) { + + my $jmbg = $1; + + return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13; + + sub digit_at { + my ($jmbg,$pos) = @_; + return ord(substr($jmbg,$pos,1)) - ord('0'); + } + + my $sum; + my $fact = 7; + + foreach my $i ( 0 .. 11 ) { + my $c = digit_at( $jmbg, $i ); + $sum += $c * $fact; +# warn "## $c * $fact => $sum\n"; + $fact--; + $fact = 7 if $fact == 1; + } + + my $ost = $sum % 11; + $ost = 11 - $ost if $ost > 1; + + return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 ); + } + + return ( 1, 'OK' ); +} + =head2 canonicalize_hrEduPersonExpireDate Support NONE as 2042-12-30 @@ -377,7 +413,7 @@ sub canonicalize_hrEduPersonExpireDate { my ( $self, $value ) = @_; - if ( $value eq 'NONE' ) { + if ( lc($value) eq 'none' ) { $self->log->warn("fixed hrEduPersonExpireDate"); $value = '2042-12-30'; } @@ -385,14 +421,7 @@ return $value; } -=head2 current_user_can - -=cut - -sub current_user_can { - # FIXME no security for now :-) - return 1; -} +use A3C::DefaultACL; 1;