222
declaration = fields.getfirst('declaration')
223
except AttributeError:
224
declaration = None # Will fail next test
225
if declaration != USER_DECLARATION:
228
# Make sure the user's status is "no_agreement", and set status to
229
# pending, within the one transaction. This ensures we only do this
232
# Check that the user's status is "no_agreement".
233
# (Both to avoid redundant calls, and to stop disabled users from
234
# re-enabling their accounts).
235
if user.state != "no_agreement":
236
raise BadRequest("You have already agreed to the terms.")
237
# Write state "pending" to ensure we don't try this again
238
user.state = u"pending"
244
# Get the arguments for usermgt.activate_user from the session
245
# (The user must have already logged in to use this app)
249
msg = {'activate_user': args}
251
# Release our lock on the db so usrmgt can write
254
# Try and contact the usrmgt server
256
response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
257
except cjson.DecodeError:
258
# Gave back rubbish - set the response to failure
259
response = {'response': 'usrmgt-failure'}
261
# Get the staus of the users request
263
status = response['response']
268
user.state = u"enabled"
270
# Reset the user back to no agreement
271
user.state = u"no_agreement"
275
req.content_type = "text/plain"
276
req.write(cjson.encode(response))
215
declaration = fields.getfirst('declaration')
216
except AttributeError:
217
declaration = None # Will fail next test
218
if declaration != USER_DECLARATION:
221
# Make sure the user's status is "no_agreement", and set status to
222
# pending, within the one transaction. This ensures we only do this
225
# Check that the user's status is "no_agreement".
226
# (Both to avoid redundant calls, and to stop disabled users from
227
# re-enabling their accounts).
228
if user.state != "no_agreement":
229
raise BadRequest("You have already agreed to the terms.")
230
# Write state "pending" to ensure we don't try this again
231
user.state = u"pending"
278
233
req.store.rollback()
237
# Get the arguments for usermgt.activate_user from the session
238
# (The user must have already logged in to use this app)
242
msg = {'activate_user': args}
244
# Release our lock on the db so usrmgt can write
247
# Try and contact the usrmgt server
249
response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
250
except cjson.DecodeError:
251
# Gave back rubbish - set the response to failure
252
response = {'response': 'usrmgt-failure'}
254
# Get the staus of the users request
256
status = response['response']
261
user.state = u"enabled"
263
# Reset the user back to no agreement
264
user.state = u"no_agreement"
267
req.content_type = "text/plain"
268
req.write(cjson.encode(response))
281
270
create_user_fields_required = [
282
271
'login', 'fullname', 'rolenm'
514
500
offering = req.store.get(ivle.database.Offering, offeringid)
516
502
dict_projectsets = []
518
for p in offering.project_sets:
519
dict_projectsets.append({
520
'projectsetid': p.id,
521
'max_students_per_group': p.max_students_per_group,
522
'groups': [{'groupid': g.id,
524
'nick': g.nick} for g in p.project_groups]
527
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
503
for p in offering.project_sets:
504
dict_projectsets.append({
505
'projectsetid': p.id,
506
'max_students_per_group': p.max_students_per_group,
507
'groups': [{'groupid': g.id,
509
'nick': g.nick} for g in p.project_groups]
529
512
response = cjson.encode(dict_projectsets)
530
513
req.write(response)
557
540
if nick is not None:
558
541
nick = unicode(nick)
560
# Begin transaction since things can go wrong
543
group = ivle.database.ProjectGroup(name=groupnm,
544
project_set_id=projectsetid,
547
epoch=datetime.datetime.now())
550
# Create the group repository
551
# Yes, this is ugly, and it would be nice to just pass in the groupid,
552
# but the object isn't visible to the extra transaction in
553
# usrmgt-server until we commit, which we only do once the repo is
555
offering = group.project_set.offering
558
"subj_short_name": offering.subject.short_name,
559
"year": offering.semester.year,
560
"semester": offering.semester.semester,
561
"groupnm": group.name,
563
msg = {'create_group_repository': args}
565
# Contact the usrmgt server
562
group = ivle.database.ProjectGroup(name=groupnm,
563
project_set_id=projectsetid,
566
epoch=datetime.datetime.now())
569
# Create the group repository
570
# Yes, this is ugly, and it would be nice to just pass in the groupid,
571
# but the object isn't visible to the extra transaction in
572
# usrmgt-server until we commit, which we only do once the repo is
574
offering = group.project_set.offering
577
"subj_short_name": offering.subject.short_name,
578
"year": offering.semester.year,
579
"semester": offering.semester.semester,
580
"groupnm": group.name,
582
msg = {'create_group_repository': args}
584
# Contact the usrmgt server
586
usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
587
except cjson.DecodeError, e:
588
raise Exception("Could not understand usrmgt server response:" +
591
if 'response' not in usrmgt or usrmgt['response']=='failure':
592
raise Exception("Failure creating repository: " + str(usrmgt))
594
# Everything went OK. Lock it in
598
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
567
usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
568
except cjson.DecodeError, e:
569
raise Exception("Could not understand usrmgt server response:" +
572
if 'response' not in usrmgt or usrmgt['response']=='failure':
573
raise Exception("Failure creating repository: " + str(usrmgt))
600
575
req.content_type = "text/plain"
667
642
# Add membership to database
668
643
# We can't keep a transaction open until the end here, as usrmgt-server
669
644
# needs to see the changes!
645
group.members.add(user)
648
# Rebuild the svn config file
649
# Contact the usrmgt server
650
msg = {'rebuild_svn_group_config': {}}
671
group.members.add(user)
674
# Rebuild the svn config file
675
# Contact the usrmgt server
676
msg = {'rebuild_svn_group_config': {}}
678
usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
679
except cjson.DecodeError, e:
680
raise Exception("Could not understand usrmgt server response: %s" +
683
if 'response' not in usrmgt or usrmgt['response']=='failure':
684
raise Exception("Failure creating repository: " + str(usrmgt))
686
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
652
usrmgt = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
653
except cjson.DecodeError, e:
654
raise Exception("Could not understand usrmgt server response: %s" +
657
if 'response' not in usrmgt or usrmgt['response']=='failure':
658
raise Exception("Failure creating repository: " + str(usrmgt))
688
660
return(cjson.encode({'response': 'okay'}))