/[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/CAdmin/Model/User.pm revision 2 by dpavlin, Sun Mar 9 22:39:58 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 CAdmin::Model::User;  package A3C::Model::Person;
5  use Jifty::DBI::Schema;  use Jifty::DBI::Schema;
6    
7  use CAdmin::Record schema {  use A3C::AAIEduHr;
8    
9    use utf8;
10    
11    use A3C::Record schema {
12    
13            column uid =>
14                    label is _('UID'),
15                    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;
24    
25            column cn =>
26                    label is _('Ime i prezime'),
27                    is mandatory;
28    
29            column sn =>
30                    label is _('Prezime'),
31                    is mandatory;
32    
33            column givenName =>
34                    label is _('Ime'),
35                    is mandatory;
36    
37            column mail =>
38                    type is 'text',
39                    is mandatory,
40                    label is _('Email address'), default is '',
41                    is indexed,
42                    is immutable,
43                    is distinct;
44    
45            column password =>
46                    is unreadable,
47                    label is _('Password'),
48                    type is 'varchar',
49                    hints is _('Your password should be at least six characters'),
50                    render_as 'password',
51    #               filters are 'Jifty::DBI::Filter::SaltHash',
52                    is mandatory;
53    
54            column telephoneNumber =>
55                    type is 'text',
56                    label is _('Telefonski broj'),
57                    hint is '+385 xx yyyyyy';
58    
59            column hrEduPersonExtensionNumber =>
60                    label is _('Lokalni telefonski broj');
61    
62            column mobile =>
63                    label is _('Broj mobilnog telefona');
64    
65            column facsimileTelephoneNumber =>
66                    label is _('Fax broj');
67    
68            column hrEduPersonUniqueNumber =>
69    #               is mandatory,
70                    label is _('Unique number');
71    
72            column hrEduPersonDateOfBirth =>
73                    type is 'date',
74                    render as 'date',
75                    label is _('Datum rođenja'),
76                    filters are 'Jifty::DBI::Filter::Date';
77    
78            column hrEduPersonGender =>
79                    label is _('Spol'),
80                    valid are [ { display => 'Nepoznato', value => 0 }, A3C::AAIEduHr->vocabulary('hrEdu002') ];
81    
82            column jpegPhoto =>
83                    label is _('Slika');
84    
85            column userCertificate =>
86                    label is _('Ceritifikat');
87            
88            column labeledURI =>
89                    label is _('URI adresa');
90            
91            column wtAdminType =>
92                    label is _('Tip administratora'),
93                    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 =>
101                    label is _('Stručni status'),
102                    valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu001'), 'VŠS' ],
103                    default is '';
104    
105            column hrEduPersonAcademicStatus =>
106                    label is _('Zvanje'),
107                    valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu002') ],
108                    default is '';
109    
110            column hrEduPersonScienceArea =>
111                    label is _('Područje znanosti'),
112                    valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu007') ],
113                    default is '';
114    
115            column 'o' =>
116                    is indexed;
117    
118            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 =>
128                    label is _('Povezanost s ustanovom'),
129                    is mandatory,
130                    valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
131                    default is 'korisnik usluge';
132    
133            column hrEduPersonPrimaryAffiliation =>
134                    label is _('Temeljna povezanost s ustanovom');
135                    is mandatory,
136                    valid are A3C::AAIEduHr->vocabulary('hrEdu004'),
137                    default is 'korisnik usluge';
138    
139            column hrEduPersonStudentCategory =>
140                    label is 'Vrsta studenta',
141                    valid are [
142                            '',
143                            A3C::AAIEduHr->vocabulary('hrEdu010'),
144                    ],
145                    default is '';
146    
147            column hrEduPersonExpireDate =>
148                    label is _('Datum isteka temeljne povezanosti'),
149                    type is 'date',
150                    render as 'date',
151                    is mandatory,
152                    filters are 'Jifty::DBI::Filter::Date';
153    
154            column hrEduPersonTitle =>
155                    label is 'Položaj u ustanovi',
156                    valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu003') ],
157                    default is '';
158    
159            column hrEduPersonRole =>
160                    label is 'Uloga u ustanovi',
161                    valid are [
162                            '',
163                            A3C::AAIEduHr->vocabulary('hrEdu006'),
164                            'MATICA operater',
165                            'MATICA urednik',
166                    ],
167                    default is '';
168    
169            column hrEduPersonStaffCategory =>
170                    label is 'Vrsta posla u ustanovi',
171                    valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu005') ];
172    
173            column hrEduPersonGroupMember =>
174                    label is 'Pripadnost grupi',
175                    hint is 'skolskagodina::razred';
176    
177            column ou =>
178                    label is _('Organizacijska jedinica');
179            
180            column roomNumber =>
181                    label is _('Broj sobe');
182    
183            column homePostalAddress =>
184                    label is _('Kućna poštanska adresa'),
185                    render as 'textarea';
186            
187            column homePhone =>
188                    label is _('Kućni telefonski broj');
189            
190            column hrEduPersonCommURI =>
191                    label is _('Desktop uređaj');
192    
193            column hrEduPersonPrivacy =>
194                    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    # 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;
215    #use Jifty::Plugin::OpenID::Mixin::Model::User;
216    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
261    
262    =cut
263    
264    sub validate_telephoneNumber {
265            my ( $self, $value ) = @_;
266    
267            return ( 0, _('Telephone number invalid') ) if $value !~ m/^(\+?385)?[\d\s-]+$/;
268    
269            return ( 1, 'OK' );
270    }
271    
272    =head2 hrEduPersonUniqueNumber
273    
274    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.2  
changed lines
  Added in v.94

  ViewVC Help
Powered by ViewVC 1.1.26