33
33
permission = 'submit_project'
35
def __init__(self, req, rtype, rname, path):
35
def __init__(self, req, name, path):
36
36
# We need to work out which entity owns the repository, so we look
37
37
# at the first two path segments. The first tells us the type.
39
self.context = User.get_by_login(req.store, rname)
40
elif rtype == 'groups':
41
namebits = rname.split('_', 3)
42
if len(namebits) != 4:
44
self.context = req.store.find(ProjectGroup,
45
ProjectGroup.name == namebits[3],
46
ProjectGroup.project_set_id == ProjectSet.id,
47
ProjectSet.offering_id == Offering.id,
48
Offering.subject_id == Subject.id,
49
Subject.short_name == namebits[0],
50
Offering.semester_id == Semester.id,
51
Semester.year == namebits[1],
52
Semester.semester == namebits[2]).one()
38
self.context = self.get_repository_owner(req.store, name)
56
40
if self.context is None:
43
def get_repository_owner(self, store, name):
44
"""Return the owner of the repository given the name and a Store."""
45
raise NotImplementedError()
59
47
def populate(self, req, ctx):
51
class UserSubmitView(SubmitView):
52
def get_repository_owner(self, store, name):
53
'''Resolve the user name into a user.'''
54
return User.get_by_login(store, name)
57
class GroupSubmitView(SubmitView):
58
def get_repository_owner(self, store, name):
59
'''Resolve the subject_year_semester_group name into a group.'''
60
namebits = name.split('_', 3)
61
if len(namebits) != 4:
64
# Find the project group with the given name in any project set in the
65
# offering of the given subject in the semester with the given year
67
return store.find(ProjectGroup,
68
ProjectGroup.name == namebits[3],
69
ProjectGroup.project_set_id == ProjectSet.id,
70
ProjectSet.offering_id == Offering.id,
71
Offering.subject_id == Subject.id,
72
Subject.short_name == namebits[0],
73
Offering.semester_id == Semester.id,
74
Semester.year == namebits[1],
75
Semester.semester == namebits[2]).one()
62
78
class Plugin(ViewPlugin):
64
('+submit/:rtype/:rname/*path', SubmitView),
80
('+submit/users/:name/*path', UserSubmitView),
81
('+submit/groups/:name/*path', GroupSubmitView),