1 # -*- coding: utf-8 -*-
4 ## This file is part of Indico.
5 ## Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN).
7 ## Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 3 of the
10 ## License, or (at your option) any later version.
12 ## Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with Indico;if not, see <http://www.gnu.org/licenses/>.
21 sys
.path
.append("c:/development/indico/code/code")
24 from MaKaC
.common
import DBMgr
25 from MaKaC
import user
30 Migration tool has imported users into Indico. Due to the format of agenda, the new users
31 in Indico don't have Surname nor affilation, and both fields are mandatory. This script is
32 aim to fix it, taking the info from NICE LDAP.
36 def getNiceUserByEmail(email
):
38 ldapserver
.protocol_version
= ldap
.VERSION3
39 baseDN
= "ou=people, o=cern, c=ch"
40 searchScope
= ldap
.SCOPE_ONELEVEL
41 retrieveAttributes
= None
42 searchFilter
="mail=%s"%email
43 ldap_result_id
= ldapserver
.search(baseDN
, searchScope
, searchFilter
, retrieveAttributes
)
44 result_type
, result_data
= ldapserver
.result(ldap_result_id
, 0)
45 if (result_data
== []):
50 for k
in result_data
[0][1].keys():
51 dict[k
] = result_data
[0][1][k
][0]
58 DBMgr
.getInstance().startRequest()
59 ldapserver
= ldap
.open("ldap.cern.ch:389")
62 ah
=user
.AvatarHolder()
67 for av
in ah
.getList():
68 if av
.getEmail().strip() == "":
69 withoutEmail
.append(av
.getId())
71 niceUserData
=getNiceUserByEmail(av
.getEmail())
72 if av
.getSurName().strip() == "" or \
73 av
.getFirstName().strip() == "" or \
74 av
.getOrganisation().strip() == "":
75 if niceUserData
!= {}:
77 if niceUserData
['givenname']:
79 if niceUserData
['sn']:
81 if niceUserData
['homeinstitute']:
83 modified
.append(av
.getId())
84 av
.setName(niceUserData
['givenname'])
85 av
.setSurName(niceUserData
['sn'])
86 if niceUserData
['homeinstitute'].lower() != "unknown" or av
.getOrganisation().strip()=="":
87 av
.setOrganisation(niceUserData
['homeinstitute'])
89 print "error:%s,email:%s"%(e
, av
.getEmail())
91 notmodified
.append(av
.getId())
92 elif av
.isNotConfirmed() and niceUserData
!= {}:
93 if len(av
.getIdentityList()) == 1 and av
.getIdentityList()[0].getAuthenticatorTag() == "Nice":
95 notconfirmedNice
.append(av
.getId())
97 DBMgr
.getInstance().commit()
98 DBMgr
.getInstance().sync()
103 print "Without email (%s): %s"%(len(withoutEmail
), withoutEmail
)
104 print "NICE to confirm (%s): %s"%(len(notconfirmedNice
), notconfirmedNice
)
105 print "No data - Will be modified (%s): %s"%(len(modified
), modified
)
106 print "No data - Will NOT be modified (%s): %s"%(len(notmodified
), notmodified
)
109 # DBMgr.getInstance().endRequest()
110 # print "No error. The change are saved"
112 # print "There were errors. The changes was not saved"
114 DBMgr
.getInstance().endRequest()
119 print "Without email (%s): %s"%(len(withoutEmail
), withoutEmail
)
120 print "NICE to confirm (%s): %s"%(len(notconfirmedNice
), notconfirmedNice
)
121 print "No data - Will be modified (%s): %s"%(len(modified
), modified
)
122 print "No data - Will NOT be modified (%s): %s"%(len(notmodified
), notmodified
)
126 print "Without email (%s): %s"%(len(withoutEmail
), withoutEmail
)
127 print "NICE to confirm (%s): %s"%(len(notconfirmedNice
), notconfirmedNice
)
128 print "No data - Will be modified (%s): %s"%(len(modified
), modified
)
129 print "No data - Will NOT be modified (%s): %s"%(len(notmodified
), notmodified
)