def has_user_permission_for_some_org(user_name, permission):
 user_id = get_user_id_for_username(user_name, allow_none=True)
 if (not user_id):
  return False
 roles = get_roles_with_permission(permission)
 if (not roles):
  return False
 q = model.Session.query(model.Member).filter((model.Member.table_name == 'user')).filter((model.Member.state == 'active')).filter(model.Member.capacity.in_(roles)).filter((model.Member.table_id == user_id))
 group_ids = []
 for row in q.all():
  group_ids.append(row.group_id)
 if (not group_ids):
  return False
 q = model.Session.query(model.Group).filter((model.Group.is_organization == True)).filter((model.Group.state == 'active')).filter(model.Group.id.in_(group_ids))
 return bool(q.count())

def has_user_permission_for_some_org ( user_name , permission ) : user_id = get_user_id_for_username ( user_name , allow_none = True ) if ( not user_id ) : return False roles = get_roles_with_permission ( permission ) if ( not roles ) : return False q = model . Session . query ( model . Member ) . filter ( ( model . Member . table_name == 'user' ) ) . filter ( ( model . Member . state == 'active' ) ) . filter ( model . Member . capacity . in_ ( roles ) ) . filter ( ( model . Member . table_id == user_id ) ) group_ids = [ ] for row in q . all ( ) : group_ids . append ( row . group_id ) if ( not group_ids ) : return False q = model . Session . query ( model . Group ) . filter ( ( model . Group . is_organization == True ) ) . filter ( ( model . Group . state == 'active' ) ) . filter ( model . Group . id . in_ ( group_ids ) ) return bool ( q . count ( ) )
check if the user has the given permission for any organization .