652
652
req.throw_error(req.HTTP_FORBIDDEN,
653
653
"You do not have permission to manage groups.")
654
654
# Get required fields
655
projectsetid = fields.getfirst('projectsetid')
656
groupnm = fields.getfirst('groupnm')
655
projectsetid = fields.getfirst('projectsetid').value
656
groupnm = fields.getfirst('groupnm').value
657
657
if projectsetid is None or groupnm is None:
658
658
req.throw_error(req.HTTP_BAD_REQUEST,
659
659
"Required: projectsetid, groupnm")
660
groupnm = unicode(groupnm)
661
662
projectsetid = int(projectsetid)
663
664
req.throw_error(req.HTTP_BAD_REQUEST,
664
665
"projectsetid must be an int")
665
666
# Get optional fields
666
nick = fields.getfirst('nick')
671
createdby = req.user.id
672
epoch = time.localtime()
667
nick = fields.getfirst('nick').value
674
671
# Begin transaction since things can go wrong
675
db.start_transaction()
677
dbquery = db.return_insert(
680
'projectsetid': projectsetid,
682
'createdby': createdby,
685
"project_group", # table
686
frozenset(["groupnm", "projectsetid", "nick", "createdby",
688
["groupid"], # returns
691
singlerow = dbquery.dictresult()[0]
692
groupid = singlerow['groupid']
673
group = ivle.database.ProjectGroup(name=groupnm,
674
project_set_id=projectsetid,
677
epoch=datetime.datetime.now())
694
# Create the groups repository
695
# Get the arguments for usermgt.activate_user from the session
696
# (The user must have already logged in to use this app)
698
# Find the rest of the parameters we need
699
offeringinfo = db.get_offering_info(projectsetid)
701
subj_short_name = offeringinfo['subj_short_name']
702
year = offeringinfo['year']
703
semester = offeringinfo['semester']
680
# Create the group repository
681
# Yes, this is ugly, and it would be nice to just pass in the groupid,
682
# but the object isn't visible to the extra transaction in
683
# usrmgt-server until we commit, which we only do once the repo is
685
offering = group.project_set.offering
706
"subj_short_name": subj_short_name,
708
"semester": semester,
688
"subj_short_name": offering.subject.short_name,
689
"year": offering.semester.year,
690
"semester": offering.semester.semester,
691
"groupnm": group.name,
711
693
msg = {'create_group_repository': args}
722
704
"Failure creating repository: %s"%str(usrmgt))
724
706
# Everything went OK. Lock it in
727
709
except Exception, e:
729
710
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, repr(e))
733
response = cjson.encode(singlerow)
735
712
req.content_type = "text/plain"
738
715
def handle_get_group_membership(req, fields):
739
716
""" Required cap: None