|
Lines 51-63
Link Here
|
| 51 |
from univention.management.console.modules.sanitizers import StringSanitizer, DictSanitizer, ListSanitizer, DNSanitizer |
51 |
from univention.management.console.modules.sanitizers import StringSanitizer, DictSanitizer, ListSanitizer, DNSanitizer |
| 52 |
from univention.management.console.modules.schoolexam import util |
52 |
from univention.management.console.modules.schoolexam import util |
| 53 |
|
53 |
|
|
|
54 |
from univention.admin.uexceptions import noObject |
| 54 |
from univention.lib.i18n import Translation |
55 |
from univention.lib.i18n import Translation |
| 55 |
from univention.lib.umc_connection import UMCConnection |
56 |
from univention.lib.umc_connection import UMCConnection |
| 56 |
|
57 |
|
| 57 |
from ucsschool.lib.schoolldap import LDAP_Connection, SchoolBaseModule, SchoolSearchBase, SchoolSanitizer |
58 |
from ucsschool.lib.schoolldap import LDAP_Connection, SchoolBaseModule, SchoolSearchBase, SchoolSanitizer |
| 58 |
from ucsschool.lib import internetrules |
59 |
from ucsschool.lib import internetrules |
| 59 |
from ucsschool.lib.schoollessons import SchoolLessons |
60 |
from ucsschool.lib.schoollessons import SchoolLessons |
| 60 |
from ucsschool.lib.models import ComputerRoom, ExamStudent, Student, User |
61 |
from ucsschool.lib.models import ComputerRoom, ExamStudent, User |
| 61 |
|
62 |
|
| 62 |
_ = Translation('ucs-school-umc-exam').translate |
63 |
_ = Translation('ucs-school-umc-exam').translate |
| 63 |
|
64 |
|
|
Lines 252-283
def _thread():
Link Here
|
| 252 |
percentPerUser = 25.0 / (1 + len(users)) |
253 |
percentPerUser = 25.0 / (1 + len(users)) |
| 253 |
examUsers = set() |
254 |
examUsers = set() |
| 254 |
usersReplicated = set() |
255 |
usersReplicated = set() |
|
|
256 |
home_directories_to_remove = set() |
| 255 |
for iuser in users: |
257 |
for iuser in users: |
| 256 |
progress.info('%s, %s (%s)' % (iuser.lastname, iuser.firstname, iuser.username)) |
258 |
progress.info('%s, %s (%s)' % (iuser.lastname, iuser.firstname, iuser.username)) |
| 257 |
if iuser.dn.endswith(Student.get_container(request.options['school'])): |
259 |
remove_home_directory_prior = False |
| 258 |
# its a student. check if home directory from previous |
260 |
try: |
| 259 |
# user with same username exists and remove it |
261 |
ExamStudent.from_student_dn(ldap_user_read, request.options['school'], iuser.dn) |
| 260 |
exam_dn = 'uid={}{},{}'.format( |
262 |
except noObject: |
| 261 |
user_prefix_exam, |
263 |
remove_home_directory_prior = True |
| 262 |
iuser.username, |
|
|
| 263 |
ExamStudent.get_container(request.options['school'])) |
| 264 |
try: |
| 265 |
ldap_user_read.get(exam_dn, required=True) |
| 266 |
except ldap.NO_SUCH_OBJECT: |
| 267 |
_tmp_split_path = iuser.homedir.rsplit(os.path.sep, 1) |
| 268 |
if len(_tmp_split_path) != 2: |
| 269 |
MODULE.error("Failed parsing homeDirectory of original user: %s" % (iuser.homedir,)) |
| 270 |
else: |
| 271 |
exam_user_homedir = os.path.join(_tmp_split_path[0], iuser.username) |
| 272 |
if os.path.exists(exam_user_homedir): |
| 273 |
MODULE.warn('Removing stale home directory %r.' % exam_user_homedir) |
| 274 |
shutil.rmtree(exam_user_homedir, ignore_errors=True) |
| 275 |
try: |
264 |
try: |
| 276 |
ires = connection.request('schoolexam-master/create-exam-user', dict( |
265 |
ires = connection.request('schoolexam-master/create-exam-user', dict( |
| 277 |
school=request.options['school'], |
266 |
school=request.options['school'], |
| 278 |
userdn=iuser.dn |
267 |
userdn=iuser.dn |
| 279 |
)) |
268 |
)) |
| 280 |
examUsers.add(ires.get('examuserdn')) |
269 |
examUsers.add(ires.get('examuserdn')) |
|
|
270 |
if remove_home_directory_prior: |
| 271 |
home_directories_to_remove.add(ires.get('examuserdn')) |
| 281 |
MODULE.info('Exam user has been created: %s' % ires.get('examuserdn')) |
272 |
MODULE.info('Exam user has been created: %s' % ires.get('examuserdn')) |
| 282 |
except (HTTPException, SocketError) as exc: |
273 |
except (HTTPException, SocketError) as exc: |
| 283 |
MODULE.warn('Could not create exam user account for %r: %s' % (iuser.dn, exc)) |
274 |
MODULE.warn('Could not create exam user account for %r: %s' % (iuser.dn, exc)) |
|
Lines 325-330
def _thread():
Link Here
|
| 325 |
MODULE.error('replication timeout - %s user objects missing: %r ' % ((len(examUsers) - len(usersReplicated)), (examUsers - usersReplicated))) |
316 |
MODULE.error('replication timeout - %s user objects missing: %r ' % ((len(examUsers) - len(usersReplicated)), (examUsers - usersReplicated))) |
| 326 |
raise UMC_Error(_('Replication timeout: could not create all exam users')) |
317 |
raise UMC_Error(_('Replication timeout: could not create all exam users')) |
| 327 |
|
318 |
|
|
|
319 |
for userdn in usersReplicated: |
| 320 |
if userdn in home_directories_to_remove: |
| 321 |
try: |
| 322 |
user = ExamStudent.from_dn(userdn, None, ldap_user_read) |
| 323 |
except noObject: |
| 324 |
continue |
| 325 |
shutil.rmtree(user.homedir, ignore_errors=True) |
| 326 |
|
| 328 |
# update the final list of recipients |
327 |
# update the final list of recipients |
| 329 |
my.project.recipients = recipients |
328 |
my.project.recipients = recipients |
| 330 |
my.project.save() |
329 |
my.project.save() |