def permitted(func):
 @functools.wraps(func)
 def wrapper(request, *args, **kwargs):
  '\n        Wrapper for the view that only calls the view if the user is authorized.\n        '
  def fetch_content():
   '\n            Extract the forum object from the keyword arguments to the view.\n            '
   if ('thread_id' in kwargs):
    content = cc.Thread.find(kwargs['thread_id']).to_dict()
   elif ('comment_id' in kwargs):
    content = cc.Comment.find(kwargs['comment_id']).to_dict()
   elif ('commentable_id' in kwargs):
    content = cc.Commentable.find(kwargs['commentable_id']).to_dict()
   else:
    content = None
   return content
  course_key = CourseKey.from_string(kwargs['course_id'])
  if check_permissions_by_view(request.user, course_key, fetch_content(), request.view_name):
   return func(request, *args, **kwargs)
  else:
   return JsonError('unauthorized', status=401)
 return wrapper

def permitted ( func ) : @ functools . wraps ( func ) def wrapper ( request , * args , ** kwargs ) : def fetch_content ( ) : if ( 'thread_id' in kwargs ) : content = cc . Thread . find ( kwargs [ 'thread_id' ] ) . to_dict ( ) elif ( 'comment_id' in kwargs ) : content = cc . Comment . find ( kwargs [ 'comment_id' ] ) . to_dict ( ) elif ( 'commentable_id' in kwargs ) : content = cc . Commentable . find ( kwargs [ 'commentable_id' ] ) . to_dict ( ) else : content = None return content course_key = CourseKey . from_string ( kwargs [ 'course_id' ] ) if check_permissions_by_view ( request . user , course_key , fetch_content ( ) , request . view_name ) : return func ( request , * args , ** kwargs ) else : return JsonError ( 'unauthorized' , status = 401 ) return wrapper
view decorator to verify the user is authorized to access this endpoint .