/[A3C]/lib/A3C/Model/User.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/User.pm

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

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

Legend:
Removed from v.7  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26