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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/service.py

Give console and tutorial services security declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import ivle.conf
30
30
import ivle.webapp.tutorial.test
31
31
 
32
 
from ivle.webapp.base.rest import JSONRESTView, named_operation
 
32
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
 
33
                                   require_permission)
33
34
from ivle.webapp.errors import NotFound
34
35
 
35
36
# If True, getattempts or getattempt will allow browsing of inactive/disabled
47
48
        if self.user is None:
48
49
            raise NotFound()
49
50
        self.exercise = exercise
 
51
        self.context = self.user # XXX: Not quite right.
50
52
 
 
53
    @require_permission('edit')
51
54
    def GET(self, req):
52
55
        """Handles a GET Attempts action."""
53
56
        exercise = ivle.database.Exercise.get_by_name(req.store, 
63
66
        return attempts
64
67
 
65
68
 
 
69
    @require_permission('edit')
66
70
    def PUT(self, req, data):
67
71
        ''' Tests the given submission '''
68
72
        exercisefile = ivle.util.open_exercise_file(self.exercise)
132
136
 
133
137
        self.context = attempt
134
138
 
 
139
    @require_permission('view')
135
140
    def GET(self, req):
136
141
        return {'code': self.context.text}
137
142
 
138
143
 
139
144
class ExerciseRESTView(JSONRESTView):
140
145
    '''REST view of an exercise.'''
141
 
    @named_operation
 
146
 
 
147
    def get_permissions(self, user):
 
148
        # XXX: Do it properly.
 
149
        if user is not None:
 
150
            return set(['save'])
 
151
        else:
 
152
            return set()
 
153
 
 
154
    @named_operation('save')
142
155
    def save(self, req, text):
143
156
        # Need to open JUST so we know this is a real exercise.
144
157
        # (This avoids users submitting code for bogus exercises).