~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

  • Committer: Matt Giuca
  • Date: 2009-12-08 11:41:44 UTC
  • Revision ID: matt.giuca@gmail.com-20091208114144-bzi17mcl5o5ms65k
database: Added finer-grained enrol permissions on offerings.
    (Separate permissions for students, tutors and lecturers.)
Enrolment page: Added a drop-down box for selecting which role to enrol as.
    The role is checked against the user's permissions, to make sure they have
    the authority to assign such a role.

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
        return value
101
101
 
102
102
 
 
103
class RoleEnrolmentValidator(formencode.FancyValidator):
 
104
    """A FormEncode validator that checks permission to enrol users with a
 
105
    particular role.
 
106
 
 
107
    The state must have an 'offering' attribute.
 
108
    """
 
109
    def _to_python(self, value, state):
 
110
        if ("enrol_" + value) not in state.offering.get_permissions(state.user):
 
111
            raise formencode.Invalid('Not allowed to assign users that role',
 
112
                                     value, state)
 
113
        return value
 
114
 
 
115
 
103
116
class EnrolSchema(formencode.Schema):
104
117
    user = formencode.All(NoEnrolmentValidator(), UserValidator())
 
118
    role = formencode.All(formencode.validators.OneOf(
 
119
                                ["lecturer", "tutor", "student"]),
 
120
                          RoleEnrolmentValidator(),
 
121
                          formencode.validators.UnicodeString())
105
122
 
106
123
 
107
124
class EnrolmentsView(XHTMLView):
128
145
                validator = EnrolSchema()
129
146
                req.offering = self.context # XXX: Getting into state.
130
147
                data = validator.to_python(data, state=req)
131
 
                self.context.enrol(data['user'])
 
148
                self.context.enrol(data['user'], data['role'])
132
149
                req.store.commit()
133
150
                req.throw_redirect(req.uri)
134
151
            except formencode.Invalid, e: