--- lib/A3C/Model/User.pm 2008/03/13 16:34:47 12 +++ lib/A3C/Model/Person.pm 2008/05/15 19:18:45 121 @@ -1,38 +1,52 @@ use strict; use warnings; -package A3C::Model::User; +=head1 WARNING + +B since application is using L + +=cut + +package A3C::Model::Person; use Jifty::DBI::Schema; +use A3C::AAIEduHr; + +use utf8; + use A3C::Record schema { - column name => - type is 'text', - label is _('Ime'), + column uid => + label is _('UID'), + is indexed, + is mandatory, + is distinct; + + column hrEduPersonUniqueID => + label is _('hr Edu Person Unique ID'), + is indexed, + is distinct, is mandatory; column cn => - label is _('Ime'), - type is 'virtual'; + label is _('Ime i prezime'), + is mandatory; column sn => - type is 'virtual', label is _('Prezime'), is mandatory; column givenName => - type is 'virtual', label is _('Ime'), is mandatory; - column email => + column mail => type is 'text', is mandatory, - label is _('Email address'), default is '', is immutable, is distinct; - - column email_confirmed => - label is _('Email address confirmed?'), - type is 'boolean'; + label is _('Email address'), default is '', + is indexed, + is immutable, + is distinct; column password => is unreadable, @@ -59,14 +73,17 @@ column hrEduPersonUniqueNumber => # is mandatory, - label is _('JMBG'); + label is _('Unique number'); column hrEduPersonDateOfBirth => type is 'date', - label is _('Datum rođenja'); + render as 'date', + label is _('Datum rođenja'), + filters are 'Jifty::DBI::Filter::Date'; column hrEduPersonGender => - label is _('Spol'); + label is _('Spol'), + valid are [ { display => 'Nepoznato', value => 0 }, A3C::AAIEduHr->vocabulary('hrEdu002') ]; column jpegPhoto => label is _('Slika'); @@ -79,177 +96,96 @@ column wtAdminType => label is _('Tip administratora'), - available are qw( AS AI AR AHU ); + 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'), - available are qw( DR KV MR NKV PKV SSS VKV VS VSS VŠS ); + valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu001'), 'VŠS' ], + default is ''; column hrEduPersonAcademicStatus => label is _('Zvanje'), - available are [ - 'asistent', - 'asistent - predavač', - 'asistent visoke škole', - 'docent', - 'izvanredni profesor', - 'knjižničar', - 'korepetitor', - 'lektor', - 'mlađi asistent', - 'predavač', - 'profesor visoke škole', - 'redoviti profesor', - 'stručni suradnik', - 'viši asistent', - 'viši knjižničar', - 'viši korepetitor', - 'viši lektor', - 'viši predavač', - 'viši znanstveni suradnik', - 'znanstveni asistent', - 'znanstveni novak', - 'znanstveni savjetnik', - 'znanstveni suradnik', - ]; + valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu002') ], + default is ''; column hrEduPersonScienceArea => label is _('Područje znanosti'), - available are [ - 'Tehničke znanosti', - 'Prirodne znanosti', - 'Humanističke znanosti', - 'Društvene znanosti', - 'Biotehničke znanosti', - 'Biomedicina i zdravstvo', - ]; + valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu007') ], + 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, - available are [ - 'djelatnik', - 'gost', - 'korisnik usluge', - 'student', - 'učenik', - 'vanjski suradnik', - ]; + valid are A3C::AAIEduHr->vocabulary('hrEdu004'), + default is 'korisnik usluge'; column hrEduPersonPrimaryAffiliation => label is _('Temeljna povezanost s ustanovom'); is mandatory, - available are [ - 'djelatnik', - 'gost', - 'korisnik usluge', - 'student', - 'učenik', - 'vanjski suradnik', - ]; + valid are A3C::AAIEduHr->vocabulary('hrEdu004'), + default is 'korisnik usluge'; column hrEduPersonStudentCategory => label is 'Vrsta studenta', - available are [ - 'dodiplomac', - 'osnovnoškolac', - 'pauzira godinu', - 'postdiplomac', - 'preddiplomac', - 'prekid studija', - 'srednjoškolac', - 'student stručnog studija', - ]; + valid are [ + '', + A3C::AAIEduHr->vocabulary('hrEdu010'), + ], + default is ''; column hrEduPersonExpireDate => label is _('Datum isteka temeljne povezanosti'), type is 'date', - hint is 'dd.mm.gggg', + render as 'date', is mandatory, + filters are 'Jifty::DBI::Filter::Date'; column hrEduPersonTitle => label is 'Položaj u ustanovi', - available are [ - 'dekan', - 'direktor', - 'pomoćnik ravnatelja', - 'predstojnik zavoda', - 'pročelnik katedre', - 'pročelnik odsjeka', - 'pročelnik sveučilišnog odjela', - 'prodekan', - 'prorektor', - 'ravnatelj', - 'rektor', - 'voditelj laboratorija', - 'voditelj odjela', - 'voditelj organizacijske jedini', - 'voditelj projekta', - 'zamjenik pročelnika sveučilišn', - 'zamjenik ravnatelja', - ]; + valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu003') ], + default is ''; column hrEduPersonRole => label is 'Uloga u ustanovi', - available are [ - 'administrator imenika', - 'CARNet koordinator', - 'CARNet sistem inženjer', - 'ICT koordinator', - 'ISVU koordinator', - 'kontakt za sigurnosna pitanja', - 'MS koordinator', + valid are [ + '', + A3C::AAIEduHr->vocabulary('hrEdu006'), 'MATICA operater', 'MATICA urednik', - ]; + ], + default is ''; column hrEduPersonStaffCategory => label is 'Vrsta posla u ustanovi', - available are [ - 'administrativno osoblje', - 'ICT podrška', - 'istraživači', - 'nastavno osoblje', - 'osoblje knjižnice', - 'tehničko osoblje', - ]; + valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu005') ]; column hrEduPersonGroupMember => 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'; @@ -263,15 +199,70 @@ column hrEduPersonPrivacy => label is _('Oznaka privatnosti'); + column loginShell => + label is _('login shell'); + + column uidNumber => + label is _('uid number'), + type is 'int'; + + column gidNumber => + label is _('gid number'); + type is 'int'; + + column homeDirectory => + label is _('home directory'); + }; -use Jifty::Plugin::User::Mixin::Model::User; +# we don't use following mixing because it wants to send notificaitons on e-mail address change +#use Jifty::Plugin::User::Mixin::Model::User; use Jifty::Plugin::Authentication::Password::Mixin::Model::User; #use Jifty::Plugin::OpenID::Mixin::Model::User; use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on # Your model-specific methods go here. +=head2 before_create + +Implement virtual columns, for now put mail from ldap into email row + +=cut + +=for later + +sub before_create { + my ($self, $attr) = @_; + if ( ! $attr->{'email'} ) { + warn "push mail to email"; + $attr->{'email'} = $attr->{'mail'}; + } +} + +=cut + +=head2 email + +Accessor for compatibility with Jifty mixins + +=cut + +sub email { + my $self = shift; + return $self->mail; +} + +sub email_confirmed { 1 }; + +=head2 name + +=cut + +sub name { + my $self = shift; + return $self->cn . ' <' . $self->mail . '>'; +} + =head2 validate_telephoneNumber =cut @@ -284,10 +275,64 @@ return ( 1, 'OK' ); } -sub current_user_can { - # FIXME no security for now :-) - return 1; +=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 + +=cut + +sub canonicalize_hrEduPersonExpireDate { + my ( $self, $value ) = @_; + + if ( lc($value) eq 'none' ) { + $self->log->warn("fixed hrEduPersonExpireDate"); + $value = '2042-12-30'; + } + + return $value; +} + +use A3C::DefaultACL; + 1;