/[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 12 by dpavlin, Thu Mar 13 16:34:47 2008 UTC lib/A3C/Model/Person.pm revision 73 by dpavlin, Fri Apr 11 15:49:50 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 utf8;
8    
9  use A3C::Record schema {  use A3C::Record schema {
10    
11          column name =>          column uid =>
12                  type is 'text',                  label is ('uid'),
13                  label is _('Ime'),                  is indexed,
14                    is mandatory,
15                    is distinct;
16    
17            column hrEduPersonUniqueID =>
18                    label is ('hrEduPersonUniqueID'),
19                    is indexed,
20                    is distinct,
21                  is mandatory;                  is mandatory;
22    
23          column cn =>          column cn =>
24                  label is _('Ime'),                  label is _('Ime i prezime'),
25                  type is 'virtual';                  is mandatory;
26    
27          column sn =>          column sn =>
                 type is 'virtual',  
28                  label is _('Prezime'),                  label is _('Prezime'),
29                  is mandatory;                  is mandatory;
30    
31          column givenName =>          column givenName =>
                 type is 'virtual',  
32                  label is _('Ime'),                  label is _('Ime'),
33                  is mandatory;                  is mandatory;
34    
35          column email =>          column mail =>
36                  type is 'text',                  type is 'text',
37                  is mandatory,                  is mandatory,
38                  label is _('Email address'), default is '', is immutable, is distinct;                  label is _('Email address'), default is '',
39                    is indexed,
40          column email_confirmed =>                  is immutable,
41                  label is _('Email address confirmed?'),                  is distinct;
                 type is 'boolean';  
42    
43          column password =>          column password =>
44                  is unreadable,                  is unreadable,
# Line 59  use A3C::Record schema { Line 65  use A3C::Record schema {
65    
66          column hrEduPersonUniqueNumber =>          column hrEduPersonUniqueNumber =>
67  #               is mandatory,  #               is mandatory,
68                  label is _('JMBG');                  label is _('Unique number');
69    
70          column hrEduPersonDateOfBirth =>          column hrEduPersonDateOfBirth =>
71                  type is 'date',                  type is 'date',
72                  label is _('Datum rođenja');                  render as 'date',
73                    label is _('Datum rođenja'),
74                    filters are 'Jifty::DBI::Filter::Date';
75    
76          column hrEduPersonGender =>          column hrEduPersonGender =>
77                  label is _('Spol');                  label is _('Spol');
# Line 79  use A3C::Record schema { Line 87  use A3C::Record schema {
87                    
88          column wtAdminType =>          column wtAdminType =>
89                  label is _('Tip administratora'),                  label is _('Tip administratora'),
90                  available are qw( AS AI AR AHU );                  valid are [ '', 'AS', 'AI', 'AR', 'AHU' ];
91    
92            column hrEduPersonHomeOrg =>
93                    label is _('Oznaka matične ustanove'),
94                    hint is 'CARNet',
95                    is mandatory;
96    
97          column hrEduPersonProfessionalStatus =>          column hrEduPersonProfessionalStatus =>
98                  label is _('Stručni status'),                  label is _('Stručni status'),
99                  available are qw( DR KV MR NKV PKV SSS VKV VS VSS VŠS );                  valid are [
100                            '',
101                            'NKV',
102                            'PKV',
103                            'KV',
104                            'VKV',
105                            'SSS',
106                            'VS',
107                            'VSS',
108                            'VŠS',
109                            'MR',
110                            'DR',
111                    ],
112                    default is '';
113    
114          column hrEduPersonAcademicStatus =>          column hrEduPersonAcademicStatus =>
115                  label is _('Zvanje'),                  label is _('Zvanje'),
116                  available are [                  valid are [
117                          'asistent',                          '',
                         'asistent - predavač',  
                         'asistent visoke škole',  
                         'docent',  
                         'izvanredni profesor',  
118                          'knjižničar',                          'knjižničar',
119                            'viši knjižničar',
120                          'korepetitor',                          'korepetitor',
121                            'viši korepetitor',
122                          'lektor',                          'lektor',
123                            'viši lektor',
124                            'stručni suradnik',
125                            'asistent visoke škole',
126                            'profesor visoke škole',
127                          'mlađi asistent',                          'mlađi asistent',
128                            'znanstveni novak',
129                            'znanstveni asistent',
130                            'znanstveni suradnik',
131                          'predavač',                          'predavač',
                         'profesor visoke škole',  
                         'redoviti profesor',  
                         'stručni suradnik',  
                         'viši asistent',  
                         'viši knjižničar',  
                         'viši korepetitor',  
                         'viši lektor',  
132                          'viši predavač',                          'viši predavač',
133                          'viši znanstveni suradnik',                          'asistent',
134                          'znanstveni asistent',                          'asistent - predavač',
135                          'znanstveni novak',                          'viši asistent',
136                            'docent',
137                            'izvanredni profesor',
138                            'redoviti profesor',
139                          'znanstveni savjetnik',                          'znanstveni savjetnik',
140                          'znanstveni suradnik',                          'viši znanstveni suradnik',
141                  ];                  ],
142                    default is '';
143    
144          column hrEduPersonScienceArea =>          column hrEduPersonScienceArea =>
145                  label is _('Područje znanosti'),                  label is _('Područje znanosti'),
146                  available are [                  valid are [
147                            '',
148                          'Tehničke znanosti',                          'Tehničke znanosti',
149                          'Prirodne znanosti',                          'Prirodne znanosti',
150                          'Humanističke znanosti',                          'Humanističke znanosti',
151                          'Društvene znanosti',                          'Društvene znanosti',
152                          'Biotehničke znanosti',                          'Biotehničke znanosti',
153                          'Biomedicina i zdravstvo',                          'Biomedicina i zdravstvo',
154                  ];                  ],
155                    default is '';
156    
157            column 'o';
158            column 'l';
159            column 'postalAddress';
160    
161    #       column organization =>
162    #               refers_to A3C::Model::Organization by 'id',
163    #               is mandatory;
164    
165          column hrEduPersonAffiliation =>          column hrEduPersonAffiliation =>
166                  label is _('Povezanost s ustanovom'),                  label is _('Povezanost s ustanovom'),
167                  is mandatory,                  is mandatory,
168                  available are [                  valid are [
                         'djelatnik',  
                         'gost',  
                         'korisnik usluge',  
                         'student',  
169                          'učenik',                          'učenik',
170                            'student',
171                            'djelatnik',
172                          'vanjski suradnik',                          'vanjski suradnik',
173                  ];                          'korisnik usluge',
174                            'gost',
175                    ],
176                    default is 'korisnik usluge';
177    
178          column hrEduPersonPrimaryAffiliation =>          column hrEduPersonPrimaryAffiliation =>
179                  label is _('Temeljna povezanost s ustanovom');                  label is _('Temeljna povezanost s ustanovom');
180                  is mandatory,                  is mandatory,
181                  available are [                  valid are [
                         'djelatnik',  
                         'gost',  
                         'korisnik usluge',  
                         'student',  
182                          'učenik',                          'učenik',
183                            'student',
184                            'djelatnik',
185                          'vanjski suradnik',                          'vanjski suradnik',
186                  ];                          'korisnik usluge',
187                            'gost',
188                    ],
189                    default is 'korisnik usluge';
190    
191          column hrEduPersonStudentCategory =>          column hrEduPersonStudentCategory =>
192                  label is 'Vrsta studenta',                  label is 'Vrsta studenta',
193                  available are [                  valid are [
194                          'dodiplomac',                          '',
195                          'osnovnoškolac',                          'osnovnoškolac',
                         'pauzira godinu',  
                         'postdiplomac',  
                         'preddiplomac',  
                         'prekid studija',  
196                          'srednjoškolac',                          'srednjoškolac',
197                          'student stručnog studija',                          'student stručnog studija',
198                  ];                          'preddiplomac',
199                            'postdiplomac',
200                            'dodiplomac',
201                            'pauzira godinu',
202                            'prekid studija',
203                    ],
204                    default is '';
205    
206          column hrEduPersonExpireDate =>          column hrEduPersonExpireDate =>
207                  label is _('Datum isteka temeljne povezanosti'),                  label is _('Datum isteka temeljne povezanosti'),
208                  type is 'date',                  type is 'date',
209                  hint is 'dd.mm.gggg',                  render as 'date',
210                  is mandatory,                  is mandatory,
211                    filters are 'Jifty::DBI::Filter::Date';
212    
213          column hrEduPersonTitle =>          column hrEduPersonTitle =>
214                  label is 'Položaj u ustanovi',                  label is 'Položaj u ustanovi',
215                  available are [                  valid are [     # FIXME reorder
216                            '',
217                          'dekan',                          'dekan',
218                          'direktor',                          'direktor',
219                          'pomoćnik ravnatelja',                          'pomoćnik ravnatelja',
# Line 187  use A3C::Record schema { Line 231  use A3C::Record schema {
231                          'voditelj projekta',                          'voditelj projekta',
232                          'zamjenik pročelnika sveučilišn',                          'zamjenik pročelnika sveučilišn',
233                          'zamjenik ravnatelja',                          'zamjenik ravnatelja',
234                  ];                  ],
235                    default is '';
236    
237          column hrEduPersonRole =>          column hrEduPersonRole =>
238                  label is 'Uloga u ustanovi',                  label is 'Uloga u ustanovi',
239                  available are [                  valid are [
240                            '',
241                          'administrator imenika',                          'administrator imenika',
242                          'CARNet koordinator',                          'CARNet koordinator',
243                          'CARNet sistem inženjer',                          'CARNet sistem inženjer',
# Line 201  use A3C::Record schema { Line 247  use A3C::Record schema {
247                          'MS koordinator',                          'MS koordinator',
248                          'MATICA operater',                          'MATICA operater',
249                          'MATICA urednik',                          'MATICA urednik',
250                  ];                  ],
251                    default is '';
252    
253          column hrEduPersonStaffCategory =>          column hrEduPersonStaffCategory =>
254                  label is 'Vrsta posla u ustanovi',                  label is 'Vrsta posla u ustanovi',
255                  available are [                  valid are [
256                          'administrativno osoblje',                          'administrativno osoblje',
257                          'ICT podrška',                          'ICT podrška',
258                          'istraživači',                          'istraživači',
# Line 218  use A3C::Record schema { Line 265  use A3C::Record schema {
265                  label is 'Pripadnost grupi',                  label is 'Pripadnost grupi',
266                  hint is 'skolskagodina::razred';                  hint is 'skolskagodina::razred';
267    
         column o =>  
                 label is _('Naziv matične ustanove'),  
                 is mandatory;  
           
         column hrEduPersonHomeOrg =>  
                 label is _('Oznaka matične ustanove'),  
                 hint is 'CARNet',  
                 is mandatory;  
   
268          column ou =>          column ou =>
269                  label is _('Organizacijska jedinica');                  label is _('Organizacijska jedinica');
270                    
271          column roomNumber =>          column roomNumber =>
272                  label is _('Broj sobe');                  label is _('Broj sobe');
273    
         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');  
           
274          column homePostalAddress =>          column homePostalAddress =>
275                  label is _('Kućna poštanska adresa'),                  label is _('Kućna poštanska adresa'),
276                  render as 'textarea';                  render as 'textarea';
# Line 263  use A3C::Record schema { Line 284  use A3C::Record schema {
284          column hrEduPersonPrivacy =>          column hrEduPersonPrivacy =>
285                  label is _('Oznaka privatnosti');                  label is _('Oznaka privatnosti');
286    
287            column loginShell =>
288                    label is _('login shell');
289    
290            column uidNumber =>
291                    label is _('uid number'),
292                    type is 'int';
293    
294            column gidNumber =>
295                    label is _('gid number');
296                    type is 'int';
297    
298            column homeDirectory =>
299                    label is _('home directory');
300    
301  };  };
302    
303  use Jifty::Plugin::User::Mixin::Model::User;  # we don't use following mixing because it wants to send notificaitons on e-mail address change
304    #use Jifty::Plugin::User::Mixin::Model::User;
305  use Jifty::Plugin::Authentication::Password::Mixin::Model::User;  use Jifty::Plugin::Authentication::Password::Mixin::Model::User;
306  #use Jifty::Plugin::OpenID::Mixin::Model::User;  #use Jifty::Plugin::OpenID::Mixin::Model::User;
307  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
308    
309  # Your model-specific methods go here.  # Your model-specific methods go here.
310    
311    =head2 before_create
312    
313    Implement virtual columns, for now put mail from ldap into email row
314    
315    =cut
316    
317    =for later
318    
319    sub before_create {
320            my ($self, $attr) = @_;
321            if ( ! $attr->{'email'} ) {
322                    warn "push mail to email";
323                    $attr->{'email'} = $attr->{'mail'};
324            }
325    }
326    
327    =cut
328    
329    =head2 email
330    
331    Accessor for compatibility with Jifty mixins
332    
333    =cut
334    
335    sub email {
336            my $self = shift;
337            return $self->mail;
338    }
339    
340    sub email_confirmed { 1 };
341    
342    =head2 name
343    
344    =cut
345    
346    sub name {
347            my $self = shift;
348            return $self->cn . ' <' . $self->mail . '>';
349    }
350    
351  =head2 validate_telephoneNumber  =head2 validate_telephoneNumber
352    
353  =cut  =cut
# Line 284  sub validate_telephoneNumber { Line 360  sub validate_telephoneNumber {
360          return ( 1, 'OK' );          return ( 1, 'OK' );
361  }  }
362    
363  sub current_user_can {  =head2 hrEduPersonUniqueNumber
364          # FIXME no security for now :-)  
365          return 1;  Check if JMBG is valid
366    
367    =cut
368    
369    sub validate_hrEduPersonUniqueNumber {
370            my ( $self, $value ) = @_;
371    
372            if ( $value =~ m/^JMBG:\s+(\d+)$/ ) {
373    
374                    my $jmbg = $1;
375    
376                    return ( 0, _('JMBG must have 13 digits') ) unless length($jmbg) == 13;
377    
378                    sub digit_at {
379                            my ($jmbg,$pos) = @_;
380                            return ord(substr($jmbg,$pos,1)) - ord('0');
381                    }
382    
383                    my $sum;
384                    my $fact = 7;
385    
386                    foreach my $i ( 0 .. 11 ) {
387                            my $c = digit_at( $jmbg, $i );
388                            $sum += $c * $fact;
389    #                       warn "## $c * $fact => $sum\n";
390                            $fact--;
391                            $fact = 7 if $fact == 1;
392                    }
393    
394                    my $ost = $sum % 11;
395                    $ost = 11 - $ost if $ost > 1;
396    
397                    return ( 0, _("JMBG is invalid") ) if $ost != digit_at( $jmbg, 12 );
398            }
399    
400            return ( 1, 'OK' );
401  }  }
402    
403    =head2 canonicalize_hrEduPersonExpireDate
404    
405    Support NONE as 2042-12-30
406    
407    =cut
408    
409    sub canonicalize_hrEduPersonExpireDate {
410            my ( $self, $value ) = @_;
411    
412            if ( lc($value) eq 'none' ) {
413                    $self->log->warn("fixed hrEduPersonExpireDate");
414                    $value = '2042-12-30';
415            }
416    
417            return $value;
418    }
419    
420    use A3C::DefaultACL;
421    
422  1;  1;
423    

Legend:
Removed from v.12  
changed lines
  Added in v.73

  ViewVC Help
Powered by ViewVC 1.1.26