Show policy, grading policy, and top-level errors

* Save errors for courses that failed to load in modulestore
* global staff can see course errors on their dashboard
* put policy loading errors into the error trackers
* add has_access(user, 'global', 'staff'), which is equiv to user.is_staff for now
This commit is contained in:
Victor Shnayder
2012-08-21 11:09:58 -04:00
parent f866854411
commit b97a2af2a2
7 changed files with 104 additions and 18 deletions

View File

@@ -63,6 +63,9 @@ def has_access(user, obj, action):
if isinstance(obj, Location):
return _has_access_location(user, obj, action)
if isinstance(obj, basestring):
return _has_access_string(user, obj, action)
# Passing an unknown object here is a coding error, so rather than
# returning a default, complain.
raise TypeError("Unknown object type in has_access(): '{0}'"
@@ -238,6 +241,30 @@ def _has_access_location(user, location, action):
return _dispatch(checkers, action, user, location)
def _has_access_string(user, perm, action):
"""
Check if user has certain special access, specified as string. Valid strings:
'global'
Valid actions:
'staff' -- global staff access.
"""
def check_staff():
if perm != 'global':
debug("Deny: invalid permission '%s'", perm)
return False
return _has_global_staff_access(user)
checkers = {
'staff': check_staff
}
return _dispatch(checkers, action, user, perm)
##### Internal helper methods below
def _dispatch(table, action, user, obj):
@@ -266,6 +293,15 @@ def _course_staff_group_name(location):
"""
return 'staff_%s' % Location(location).course
def _has_global_staff_access(user):
if user.is_staff:
debug("Allow: user.is_staff")
return True
else:
debug("Deny: not user.is_staff")
return False
def _has_staff_access_to_location(user, location):
'''
Returns True if the given user has staff access to a location. For now this

View File

@@ -30,7 +30,6 @@ def get_course_by_id(course_id):
raise Http404("Course not found.")
def get_course_with_access(user, course_id, action):
"""
Given a course_id, look up the corresponding course descriptor,