def get_valid_perms(doctype=None):
 roles = get_roles()
 perms = get_perms_for(roles)
 custom_perms = get_perms_for(roles, u'Custom DocPerm')
 doctypes_with_custom_perms = list(set([d.parent for d in custom_perms]))
 for p in perms:
  if (not (p.parent in doctypes_with_custom_perms)):
   custom_perms.append(p)
 if doctype:
  return [p for p in custom_perms if (p.parent == doctype)]
 else:
  return custom_perms

def get_valid_perms ( doctype = None ) : roles = get_roles ( ) perms = get_perms_for ( roles ) custom_perms = get_perms_for ( roles , u'Custom DocPerm' ) doctypes_with_custom_perms = list ( set ( [ d . parent for d in custom_perms ] ) ) for p in perms : if ( not ( p . parent in doctypes_with_custom_perms ) ) : custom_perms . append ( p ) if doctype : return [ p for p in custom_perms if ( p . parent == doctype ) ] else : return custom_perms
get valid permissions for the current user from docperm and custom docperm .