def has_user_permission_for_group_or_org(group_id, user_name, permission):
 if (not group_id):
  return False
 group = model.Group.get(group_id)
 if (not group):
  return False
 group_id = group.id
 if is_sysadmin(user_name):
  return True
 user_id = get_user_id_for_username(user_name, allow_none=True)
 if (not user_id):
  return False
 if _has_user_permission_for_groups(user_id, permission, [group_id]):
  return True
 for capacity in check_config_permission('roles_that_cascade_to_sub_groups'):
  parent_groups = group.get_parent_group_hierarchy(type=group.type)
  group_ids = [group_.id for group_ in parent_groups]
  if _has_user_permission_for_groups(user_id, permission, group_ids, capacity=capacity):
   return True
 return False

def has_user_permission_for_group_or_org ( group_id , user_name , permission ) : if ( not group_id ) : return False group = model . Group . get ( group_id ) if ( not group ) : return False group_id = group . id if is_sysadmin ( user_name ) : return True user_id = get_user_id_for_username ( user_name , allow_none = True ) if ( not user_id ) : return False if _has_user_permission_for_groups ( user_id , permission , [ group_id ] ) : return True for capacity in check_config_permission ( 'roles_that_cascade_to_sub_groups' ) : parent_groups = group . get_parent_group_hierarchy ( type = group . type ) group_ids = [ group_ . id for group_ in parent_groups ] if _has_user_permission_for_groups ( user_id , permission , group_ids , capacity = capacity ) : return True return False
check if the user has the given permissions for the group .