Skip to content

Commit

Permalink
refactor: query account/user/qos
Browse files Browse the repository at this point in the history
  • Loading branch information
huerni committed Feb 10, 2025
1 parent fc941e4 commit e61cd33
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/CraneCtld/AccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ AccountManager::CraneExpected<void> AccountManager::QueryUserInfo(
for (const auto& user_name : user_list) {
const User* user = GetExistedUserInfoNoLock_(user_name);
result = CheckIfUserHasPermOnUserNoLock_(*op_user, user, true);
if (!result) return result;
if (!result) continue;
res_user_map->try_emplace(user->uid, *user);
}
}

return result;
return {};
}

AccountManager::CraneExpected<void> AccountManager::QueryAccountInfo(
Expand All @@ -372,15 +372,7 @@ AccountManager::CraneExpected<void> AccountManager::QueryAccountInfo(
util::read_lock_guard account_guard(m_rw_account_mutex_);
auto user_result = GetUserInfoByUidNoLock_(uid);
if (!user_result) return std::unexpected(user_result.error());
const User* op_user = user_result.value();
if (!account_list.empty()) {
for (const auto& account_name : account_list) {
result =
CheckIfUserHasPermOnAccountNoLock_(*op_user, account_name, true);
if (!result) return result;
}
}
res_user = *op_user;
res_user = *user_result.value();
}

util::read_lock_guard account_guard(m_rw_account_mutex_);
Expand Down Expand Up @@ -422,12 +414,13 @@ AccountManager::CraneExpected<void> AccountManager::QueryAccountInfo(
} else {
for (const auto& account_name : account_list) {
const Account* account = GetAccountInfoNoLock_(account_name);
if (!account) return std::unexpected(CraneErrCode::ERR_INVALID_ACCOUNT);
result = CheckIfUserHasPermOnAccountNoLock_(res_user, account_name, true);
if (!result) continue;
res_account_map->try_emplace(account_name, *account);
}
}

return result;
return {};
}

AccountManager::CraneExpected<void> AccountManager::QueryQosInfo(
Expand Down Expand Up @@ -464,7 +457,7 @@ AccountManager::CraneExpected<void> AccountManager::QueryQosInfo(
} else {
for (const auto& qos_name : qos_list) {
const Qos* qos = GetExistedQosInfoNoLock_(qos_name);
if (!qos) return std::unexpected(CraneErrCode::ERR_INVALID_QOS);
if (!qos) continue;

if (res_user.admin_level < User::Operator) {
bool found = false;
Expand All @@ -476,13 +469,13 @@ AccountManager::CraneExpected<void> AccountManager::QueryQosInfo(
}
}
}
if (!found) return std::unexpected(CraneErrCode::ERR_ALLOWED_QOS);
if (!found) continue;
}
res_qos_map->try_emplace(qos_name, *qos);
}
}

return result;
return {};
}

AccountManager::CraneExpected<void> AccountManager::ModifyAdminLevel(
Expand Down

0 comments on commit e61cd33

Please sign in to comment.