/[A3C]/lib/A3C/Model/Person.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/Model/Person.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

lib/A3C/Model/User.pm revision 11 by dpavlin, Thu Mar 13 14:22:53 2008 UTC lib/A3C/Model/Person.pm revision 94 by dpavlin, Wed Apr 30 17:23:46 2008 UTC
# Line 1  Line 1 
1  use strict;  use strict;
2  use warnings;  use warnings;
3    
4  package A3C::Model::User;  package A3C::Model::Person;
5  use Jifty::DBI::Schema;  use Jifty::DBI::Schema;
6    
7    use A3C::AAIEduHr;
8    
9    use utf8;
10    
11  use A3C::Record schema {  use A3C::Record schema {
12    
13          column name =>          column uid =>
14                  type is 'text',                  label is _('UID'),
15                  label is _('Ime'),                  is indexed,
16                    is mandatory,
17                    is distinct;
18    
19            column hrEduPersonUniqueID =>
20                    label is _('hr Edu Person Unique ID'),
21                    is indexed,
22                    is distinct,
23                  is mandatory;                  is mandatory;
24    
25          column cn =>          column cn =>
26                  label is _('Ime'),                  label is _('Ime i prezime'),
27                  type is 'virtual';                  is mandatory;
28    
29          column sn =>          column sn =>
                 type is 'virtual',  
30                  label is _('Prezime'),                  label is _('Prezime'),
31                  is mandatory;                  is mandatory;
32    
33          column givenName =>          column givenName =>
                 type is 'virtual',  
34                  label is _('Ime'),                  label is _('Ime'),
35                  is mandatory;                  is mandatory;
36    
37          column email =>          column mail =>
38                  type is 'text',                  type is 'text',
39                  is mandatory,                  is mandatory,
40                  label is _('Email address'), default is '', is immutable, is distinct;                  label is _('Email address'), default is '',
41                    is indexed,
42          column email_confirmed =>                  is immutable,
43                  label is _('Email address confirmed?'),                  is distinct;
                 type is 'boolean';  
44    
45          column password =>          column password =>
46                  is unreadable,                  is unreadable,
# Line 59  use A3C::Record schema { Line 67  use A3C::Record schema {
67    
68          column hrEduPersonUniqueNumber =>          column hrEduPersonUniqueNumber =>
69  #               is mandatory,  #               is mandatory,
70                  label is _('JMBG');                  label is _('Unique number');
71    
72          column hrEduPersonDateOfBirth =>          column hrEduPersonDateOfBirth =>
73                  type is 'date',                  type is 'date',
74                  label is _('Datum rođenja');                  render as 'date',
75                    label is _('Datum rođenja'),
76                    filters are 'Jifty::DBI::Filter::Date';
77    
78          column hrEduPersonGender =>          column hrEduPersonGender =>
79                  label is _('Spol');                  label is _('Spol'),
80                    valid are [ { display => 'Nepoznato', value => 0 }, A3C::AAIEduHr->vocabulary('hrEdu002') ];
81    
82          column jpegPhoto =>          column jpegPhoto =>
83                  label is _('Slika');                  label is _('Slika');
# Line 79  use A3C::Record schema { Line 90  use A3C::Record schema {
90                    
91          column wtAdminType =>          column wtAdminType =>
92                  label is _('Tip administratora'),                  label is _('Tip administratora'),
93                  available are qw( AS AI AR AHU );                  valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
94    
95            column hrEduPersonHomeOrg =>
96                    label is _('Oznaka matične ustanove'),
97                    hint is 'CARNet',
98                    is mandatory;
99    
100          column hrEduPersonProfessionalStatus =>          column hrEduPersonProfessionalStatus =>
101                  label is _('Stručni status'),                  label is _('Stručni status'),
102                  available are qw( DR KV MR NKV PKV SSS VKV VS VSS VŠS );                  valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu001'), 'VŠS' ],
103                    default is '';
104    
105          column hrEduPersonAcademicStatus =>          column hrEduPersonAcademicStatus =>
106                  label is _('Zvanje'),                  label is _('Zvanje'),
107                  available are [                  valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu002') ],
108                          'asistent',                  default is '';
                         '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',  
                 ];  
109    
110          column hrEduPersonScienceArea =>          column hrEduPersonScienceArea =>
111                  label is _('Područje znanosti'),                  label is _('Područje znanosti'),
112                  available are [                  valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu007') ],
113                          'Tehničke znanosti',                  default is '';
114                          'Prirodne znanosti',  
115                          'Humanističke znanosti',          column 'o' =>
116                          'Društvene znanosti',                  is indexed;
117                          'Biotehničke znanosti',  
118                          'Biomedicina i zdravstvo',          column 'l';
119                  ];          column 'postalAddress';
120            column 'postalCode';
121            column 'street';
122    
123    #       column organization =>
124    #               refers_to A3C::Model::Organization by 'id',
125    #               is mandatory;
126    
127          column hrEduPersonAffiliation =>          column hrEduPersonAffiliation =>
128                  label is _('Povezanost s ustanovom'),                  label is _('Povezanost s ustanovom'),
129                  is mandatory,                  is mandatory,
130                  available are [                  valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
131                          'djelatnik',                  default is 'korisnik usluge';
                         'gost',  
                         'korisnik usluge',  
                         'student',  
                         'učenik',  
                         'vanjski suradnik',  
                 ];  
132    
133          column hrEduPersonPrimaryAffiliation =>          column hrEduPersonPrimaryAffiliation =>
134                  label is _('Temeljna povezanost s ustanovom');                  label is _('Temeljna povezanost s ustanovom');
135                  is mandatory,                  is mandatory,
136                  available are [                  valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
137                          'djelatnik',                  default is 'korisnik usluge';
                         'gost',  
                         'korisnik usluge',  
                         'student',  
                         'učenik',  
                         'vanjski suradnik',  
                 ];  
138    
139          column hrEduPersonStudentCategory =>          column hrEduPersonStudentCategory =>
140                  label is 'Vrsta studenta',                  label is 'Vrsta studenta',
141                  available are [                  valid are [
142                          'dodiplomac',                          '',
143                          'osnovnoškolac',                          A3C::AAIEduHr->vocabulary('hrEdu010'),
144                          'pauzira godinu',                  ],
145                          'postdiplomac',                  default is '';
                         'preddiplomac',  
                         'prekid studija',  
                         'srednjoškolac',  
                         'student stručnog studija',  
                 ];  
146    
147          column hrEduPersonExpireDate =>          column hrEduPersonExpireDate =>
148                  label is _('Datum isteka temeljne povezanosti'),                  label is _('Datum isteka temeljne povezanosti'),
149                  type is 'date',                  type is 'date',
150                  hint is 'dd.mm.gggg',                  render as 'date',
151                  is mandatory,                  is mandatory,
152                    filters are 'Jifty::DBI::Filter::Date';
153    
154          column hrEduPersonTitle =>          column hrEduPersonTitle =>
155                  label is 'Položaj u ustanovi',                  label is 'Položaj u ustanovi',
156                  available are [                  valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu003') ],
157                          'dekan',                  default is '';
                         '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',  
                 ];  
158    
159          column hrEduPersonRole =>          column hrEduPersonRole =>
160                  label is 'Uloga u ustanovi',                  label is 'Uloga u ustanovi',
161                  available are [                  valid are [
162                          'administrator imenika',                          '',
163                          'CARNet koordinator',                          A3C::AAIEduHr->vocabulary('hrEdu006'),
                         'CARNet sistem inženjer',  
                         'ICT koordinator',  
                         'ISVU koordinator',  
                         'kontakt za sigurnosna pitanja',  
                         'MS koordinator',  
164                          'MATICA operater',                          'MATICA operater',
165                          'MATICA urednik',                          'MATICA urednik',
166                  ];                  ],
167                    default is '';
168    
169          column hrEduPersonStaffCategory =>          column hrEduPersonStaffCategory =>
170                  label is 'Vrsta posla u ustanovi',                  label is 'Vrsta posla u ustanovi',
171                  available are [                  valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu005') ];
                         'administrativno osoblje',  
                         'ICT podrška',  
                         'istraživači',  
                         'nastavno osoblje',  
                         'osoblje knjižnice',  
                         'tehničko osoblje',  
                 ];  
172    
173          column hrEduPersonGroupMember =>          column hrEduPersonGroupMember =>
174                  label is 'Pripadnost grupi',                  label is 'Pripadnost grupi',
175                  hint is 'skolskagodina::razred';                  hint is 'skolskagodina::razred';
176    
         column o =>  
                 label is _('Naziv matične ustanove'),  
                 is mandatory;  
           
         column hrEduPersonHomeOrg =>  
                 label is _('Oznaka matične ustanove'),  
                 hint is 'CARNet',  
                 is mandatory;  
   
177          column ou =>          column ou =>
178                  label is _('Organizacijska jedinica');                  label is _('Organizacijska jedinica');
179                    
180          column roomNumber =>          column roomNumber =>
181                  label is _('Broj sobe');                  label is _('Broj sobe');
182    
         column postalAddress =>  
                 label is _('Poštanska adresa'),  
                 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');  
           
183          column homePostalAddress =>          column homePostalAddress =>
184                  label is _('Kućna poštanska adresa');                  label is _('Kućna poštanska adresa'),
185                    render as 'textarea';
186                    
187          column homePhone =>          column homePhone =>
188                  label is _('Kućni telefonski broj');                  label is _('Kućni telefonski broj');
# Line 261  use A3C::Record schema { Line 193  use A3C::Record schema {
193          column hrEduPersonPrivacy =>          column hrEduPersonPrivacy =>
194                  label is _('Oznaka privatnosti');                  label is _('Oznaka privatnosti');
195    
196            column loginShell =>
197                    label is _('login shell');
198    
199            column uidNumber =>
200                    label is _('uid number'),
201                    type is 'int';
202    
203            column gidNumber =>
204                    label is _('gid number');
205                    type is 'int';
206    
207            column homeDirectory =>
208                    label is _('home directory');
209    
210  };  };
211    
212  use Jifty::Plugin::User::Mixin::Model::User;  # we don't use following mixing because it wants to send notificaitons on e-mail address change
213    #use Jifty::Plugin::User::Mixin::Model::User;
214  use Jifty::Plugin::Authentication::Password::Mixin::Model::User;  use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
215  #use Jifty::Plugin::OpenID::Mixin::Model::User;  #use Jifty::Plugin::OpenID::Mixin::Model::User;
216  use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on  use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata; # created_by, created_on, updated_on
217    
218  # Your model-specific methods go here.  # Your model-specific methods go here.
219    
220    =head2 before_create
221    
222    Implement virtual columns, for now put mail from ldap into email row
223    
224    =cut
225    
226    =for later
227    
228    sub before_create {
229            my ($self, $attr) = @_;
230            if ( ! $attr->{'email'} ) {
231                    warn "push mail to email";
232                    $attr->{'email'} = $attr->{'mail'};
233            }
234    }
235    
236    =cut
237    
238    =head2 email
239    
240    Accessor for compatibility with Jifty mixins
241    
242    =cut
243    
244    sub email {
245            my $self = shift;
246            return $self->mail;
247    }
248    
249    sub email_confirmed { 1 };
250    
251    =head2 name
252    
253    =cut
254    
255    sub name {
256            my $self = shift;
257            return $self->cn . ' <' . $self->mail . '>';
258    }
259    
260  =head2 validate_telephoneNumber  =head2 validate_telephoneNumber
261    
262  =cut  =cut
# Line 282  sub validate_telephoneNumber { Line 269  sub validate_telephoneNumber {
269          return ( 1, 'OK' );          return ( 1, 'OK' );
270  }  }
271    
272  sub current_user_can {  =head2 hrEduPersonUniqueNumber
273          # FIXME no security for now :-)  
274          return 1;  Check if JMBG is valid
275    
276    =cut
277    
278    sub validate_hrEduPersonUniqueNumber {
279            my ( $self, $value ) = @_;
280    
281            if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
282    
283                    my $jmbg = $1;
284    
285                    return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
286    
287                    sub digit_at {
288                            my ($jmbg,$pos) = @_;
289                            return ord(substr($jmbg,$pos,1)) - ord('0');
290                    }
291    
292                    my $sum;
293                    my $fact = 7;
294    
295                    foreach my $i ( 0 .. 11 ) {
296                            my $c = digit_at( $jmbg, $i );
297                            $sum += $c * $fact;
298    #                       warn "## $c * $fact => $sum\n";
299                            $fact--;
300                            $fact = 7 if $fact == 1;
301                    }
302    
303                    my $ost = $sum % 11;
304                    $ost = 11 - $ost if $ost > 1;
305    
306                    return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
307            }
308    
309            return ( 1, 'OK' );
310  }  }
311    
312    =head2 canonicalize_hrEduPersonExpireDate
313    
314    Support NONE as 2042-12-30
315    
316    =cut
317    
318    sub canonicalize_hrEduPersonExpireDate {
319            my ( $self, $value ) = @_;
320    
321            if ( lc($value) eq 'none' ) {
322                    $self->log->warn("fixed hrEduPersonExpireDate");
323                    $value = '2042-12-30';
324            }
325    
326            return $value;
327    }
328    
329    use A3C::DefaultACL;
330    
331  1;  1;
332    

Legend:
Removed from v.11  
changed lines
  Added in v.94

  ViewVC Help
Powered by ViewVC 1.1.26