--- lib/CAdmin/Model/User.pm 2008/03/09 22:39:58 2 +++ lib/A3C/Model/User.pm 2008/03/30 22:29:42 45 @@ -1,14 +1,430 @@ use strict; use warnings; -package CAdmin::Model::User; +package A3C::Model::User; use Jifty::DBI::Schema; -use CAdmin::Record schema { +use utf8; + +use A3C::Record schema { + + column uid => + label is ('uid'), + is indexed, + is mandatory, + is distinct; + + column hrEduPersonUniqueID => + label is ('hrEduPersonUniqueID'), + is indexed, + is distinct, + is mandatory; + + column cn => + label is _('Ime i prezime'), + is mandatory; + + column sn => + label is _('Prezime'), + is mandatory; + + column givenName => + label is _('Ime'), + is mandatory; + + column mail => + type is 'text', + is mandatory, + label is _('Email address'), default is '', + is immutable, + is distinct; + + column password => + is unreadable, + label is _('Password'), + type is 'varchar', + hints is _('Your password should be at least six characters'), + render_as 'password', +# filters are 'Jifty::DBI::Filter::SaltHash', + is mandatory; + + column telephoneNumber => + type is 'text', + label is _('Telefonski broj'), + hint is '+385 xx yyyyyy'; + + column hrEduPersonExtensionNumber => + label is _('Lokalni telefonski broj'); + + column mobile => + label is _('Broj mobilnog telefona'); + + column facsimileTelephoneNumber => + label is _('Fax broj'); + + column hrEduPersonUniqueNumber => +# is mandatory, + label is _('Unique number'); + + column hrEduPersonDateOfBirth => + type is 'date', + render as 'date', + label is _('Datum rođenja'), + filters are 'Jifty::DBI::Filter::Date'; + + column hrEduPersonGender => + label is _('Spol'); + + column jpegPhoto => + label is _('Slika'); + + column userCertificate => + label is _('Ceritifikat'); + + column labeledURI => + label is _('URI adresa'); + + column wtAdminType => + 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 [ + '', + 'NKV', + 'PKV', + 'KV', + 'VKV', + 'SSS', + 'VS', + 'VSS', + 'VŠS', + 'MR', + 'DR', + ], + default is ''; + + column hrEduPersonAcademicStatus => + label is _('Zvanje'), + valid are [ + '', + 'knjižničar', + 'viši knjižničar', + 'korepetitor', + 'viši korepetitor', + 'lektor', + 'viši lektor', + 'stručni suradnik', + 'asistent visoke škole', + 'profesor visoke škole', + 'mlađi asistent', + 'znanstveni novak', + 'znanstveni asistent', + 'znanstveni suradnik', + 'predavač', + 'viši predavač', + 'asistent', + 'asistent - predavač', + 'viši asistent', + 'docent', + 'izvanredni profesor', + 'redoviti profesor', + 'znanstveni savjetnik', + 'viši znanstveni suradnik', + ], + default is ''; + + column hrEduPersonScienceArea => + label is _('Područje znanosti'), + valid are [ + '', + 'Tehničke znanosti', + 'Prirodne znanosti', + 'Humanističke znanosti', + 'Društvene znanosti', + 'Biotehničke znanosti', + 'Biomedicina i zdravstvo', + ], + default is ''; + + column 'o'; + column 'l'; + column 'postalAddress'; + +# column organization => +# refers_to A3C::Model::Organization by 'id', +# is mandatory; + + column hrEduPersonAffiliation => + label is _('Povezanost s ustanovom'), + is mandatory, + valid are [ + 'učenik', + 'student', + 'djelatnik', + 'vanjski suradnik', + 'korisnik usluge', + 'gost', + ], + default is 'korisnik usluge'; + + column hrEduPersonPrimaryAffiliation => + label is _('Temeljna povezanost s ustanovom'); + is mandatory, + valid are [ + 'učenik', + 'student', + 'djelatnik', + 'vanjski suradnik', + 'korisnik usluge', + 'gost', + ], + default is 'korisnik usluge'; + + column hrEduPersonStudentCategory => + label is 'Vrsta studenta', + valid are [ + '', + 'osnovnoškolac', + 'srednjoškolac', + 'student stručnog studija', + 'preddiplomac', + 'postdiplomac', + 'dodiplomac', + 'pauzira godinu', + 'prekid studija', + ], + default is ''; + + column hrEduPersonExpireDate => + label is _('Datum isteka temeljne povezanosti'), + type is 'date', + render as 'date', + is mandatory, + filters are 'Jifty::DBI::Filter::Date'; + + column hrEduPersonTitle => + label is 'Položaj u ustanovi', + valid are [ # FIXME reorder + '', + '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', + ], + default is ''; + + column hrEduPersonRole => + label is 'Uloga u ustanovi', + valid are [ + '', + 'administrator imenika', + 'CARNet koordinator', + 'CARNet sistem inženjer', + 'ICT koordinator', + 'ISVU koordinator', + 'kontakt za sigurnosna pitanja', + 'MS koordinator', + 'MATICA operater', + 'MATICA urednik', + ], + default is ''; + + column hrEduPersonStaffCategory => + label is 'Vrsta posla u ustanovi', + valid are [ + 'administrativno osoblje', + 'ICT podrška', + 'istraživači', + 'nastavno osoblje', + 'osoblje knjižnice', + 'tehničko osoblje', + ]; + + column hrEduPersonGroupMember => + label is 'Pripadnost grupi', + hint is 'skolskagodina::razred'; + + column ou => + label is _('Organizacijska jedinica'); + + column roomNumber => + label is _('Broj sobe'); + + column homePostalAddress => + label is _('Kućna poštanska adresa'), + render as 'textarea'; + + column homePhone => + label is _('Kućni telefonski broj'); + + column hrEduPersonCommURI => + label is _('Desktop uređaj'); + + 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'); }; +# 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->__value('mail'); +} + +sub email_confirmed { 1 }; + +=head2 name + +=cut + +sub name { + my $self = shift; + return $self->__value('cn'); +} + +=head2 validate_telephoneNumber + +=cut + +sub validate_telephoneNumber { + my ( $self, $value ) = @_; + + return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/; + + 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 + +=cut + +sub canonicalize_hrEduPersonExpireDate { + my ( $self, $value ) = @_; + + if ( lc($value) eq 'none' ) { + $self->log->warn("fixed hrEduPersonExpireDate"); + $value = '2042-12-30'; + } + + return $value; +} + +=head2 current_user_can + +=cut + +sub current_user_can { + # FIXME no security for now :-) + return 1; +} + + 1;