def get_user_permissions(user, course_key, org=None):
 if (org is None):
  org = course_key.org
  course_key = course_key.for_branch(None)
 else:
  assert (course_key is None)
 if is_ccx_course(course_key):
  return STUDIO_NO_PERMISSIONS
 all_perms = (((STUDIO_EDIT_ROLES | STUDIO_VIEW_USERS) | STUDIO_EDIT_CONTENT) | STUDIO_VIEW_CONTENT)
 if (GlobalStaff().has_user(user) or OrgInstructorRole(org=org).has_user(user)):
  return all_perms
 if (course_key and user_has_role(user, CourseInstructorRole(course_key))):
  return all_perms
 if (OrgStaffRole(org=org).has_user(user) or (course_key and user_has_role(user, CourseStaffRole(course_key)))):
  return ((STUDIO_VIEW_USERS | STUDIO_EDIT_CONTENT) | STUDIO_VIEW_CONTENT)
 if (course_key and isinstance(course_key, LibraryLocator)):
  if (OrgLibraryUserRole(org=org).has_user(user) or user_has_role(user, LibraryUserRole(course_key))):
   return (STUDIO_VIEW_USERS | STUDIO_VIEW_CONTENT)
 return STUDIO_NO_PERMISSIONS

def get_user_permissions ( user , course_key , org = None ) : if ( org is None ) : org = course_key . org course_key = course_key . for_branch ( None ) else : assert ( course_key is None ) if is_ccx_course ( course_key ) : return STUDIO_NO_PERMISSIONS all_perms = ( ( ( STUDIO_EDIT_ROLES | STUDIO_VIEW_USERS ) | STUDIO_EDIT_CONTENT ) | STUDIO_VIEW_CONTENT ) if ( GlobalStaff ( ) . has_user ( user ) or OrgInstructorRole ( org = org ) . has_user ( user ) ) : return all_perms if ( course_key and user_has_role ( user , CourseInstructorRole ( course_key ) ) ) : return all_perms if ( OrgStaffRole ( org = org ) . has_user ( user ) or ( course_key and user_has_role ( user , CourseStaffRole ( course_key ) ) ) ) : return ( ( STUDIO_VIEW_USERS | STUDIO_EDIT_CONTENT ) | STUDIO_VIEW_CONTENT ) if ( course_key and isinstance ( course_key , LibraryLocator ) ) : if ( OrgLibraryUserRole ( org = org ) . has_user ( user ) or user_has_role ( user , LibraryUserRole ( course_key ) ) ) : return ( STUDIO_VIEW_USERS | STUDIO_VIEW_CONTENT ) return STUDIO_NO_PERMISSIONS
get the bitmask of permissions that this user has in the given course context .