def has_access(user, action, obj, course_key=None):
 if (not user):
  user = AnonymousUser()
 if in_preview_mode():
  if (not bool(has_staff_access_to_preview_mode(user=user, obj=obj, course_key=course_key))):
   return ACCESS_DENIED
 if isinstance(obj, CourseDescriptor):
  return _has_access_course(user, action, obj)
 if isinstance(obj, CourseOverview):
  return _has_access_course(user, action, obj)
 if isinstance(obj, ErrorDescriptor):
  return _has_access_error_desc(user, action, obj, course_key)
 if isinstance(obj, XModule):
  return _has_access_xmodule(user, action, obj, course_key)
 if isinstance(obj, XBlock):
  return _has_access_descriptor(user, action, obj, course_key)
 if isinstance(obj, CourseKey):
  return _has_access_course_key(user, action, obj)
 if isinstance(obj, UsageKey):
  return _has_access_location(user, action, obj, course_key)
 if isinstance(obj, basestring):
  return _has_access_string(user, action, obj)
 raise TypeError("Unknown object type in has_access(): '{0}'".format(type(obj)))

def has_access ( user , action , obj , course_key = None ) : if ( not user ) : user = AnonymousUser ( ) if in_preview_mode ( ) : if ( not bool ( has_staff_access_to_preview_mode ( user = user , obj = obj , course_key = course_key ) ) ) : return ACCESS_DENIED if isinstance ( obj , CourseDescriptor ) : return _has_access_course ( user , action , obj ) if isinstance ( obj , CourseOverview ) : return _has_access_course ( user , action , obj ) if isinstance ( obj , ErrorDescriptor ) : return _has_access_error_desc ( user , action , obj , course_key ) if isinstance ( obj , XModule ) : return _has_access_xmodule ( user , action , obj , course_key ) if isinstance ( obj , XBlock ) : return _has_access_descriptor ( user , action , obj , course_key ) if isinstance ( obj , CourseKey ) : return _has_access_course_key ( user , action , obj ) if isinstance ( obj , UsageKey ) : return _has_access_location ( user , action , obj , course_key ) if isinstance ( obj , basestring ) : return _has_access_string ( user , action , obj ) raise TypeError ( "Unknown object type in has_access(): '{0}'" . format ( type ( obj ) ) )
use this decorator to enable granular security permissions to your methods .