SPARK-1013 moving admin data functions into its own util class
This commit is contained in:
1 parent
e4b155b270
commit
799f06247d
5 files changed
+121
-98
No files matched your search
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "server/sparkd/persistence/SqliteStore.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/api/services/AccountService.pb.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "AdminServiceUtils.h"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <fmt/format.h>
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <utility>
|
||||
|
||||
namespace bts {
|
||||
namespace account{
|
||||
namespace admin{
|
||||
|
||||
AdminServiceServer::AdminServiceServer(bts::api::ServiceContext& context)
|
||||
:
|
||||
@@ -24,39 +24,37 @@ AdminServiceServer::AdminServiceServer(bts::api::ServiceContext& context)
|
||||
{
|
||||
LOG(Gen, Info, "AdminServiceServer created");
|
||||
std::map<std::string,std::map<std::string,std::string>> all_data = _store->retrieve_all();
|
||||
if (all_data.size()==0)
|
||||
// write the first row
|
||||
_update_and_publish();
|
||||
else
|
||||
auto table = all_data.find(_table_name);
|
||||
bool data_found = false;
|
||||
if (table != all_data.end())
|
||||
{
|
||||
auto table = all_data.find(_table_name);
|
||||
bool data_found = false;
|
||||
if (table != all_data.end())
|
||||
auto row = table->second.find(_unique_key);
|
||||
if (row != table->second.end())
|
||||
{
|
||||
auto row = table->second.find(_unique_key);
|
||||
if (row != table->second.end())
|
||||
std::string& ser_data = row->second;
|
||||
if (_state.ParseFromString(ser_data))
|
||||
{
|
||||
std::string& ser_data = row->second;
|
||||
if (_state.ParseFromString(ser_data))
|
||||
{
|
||||
data_found = true;
|
||||
_update_and_publish();
|
||||
}
|
||||
data_found = true;
|
||||
_update_and_publish();
|
||||
}
|
||||
}
|
||||
if (!data_found)
|
||||
LOG(Gen, Error, "Could not locate user data");
|
||||
}
|
||||
if (!data_found)
|
||||
{
|
||||
// first time
|
||||
// TODO add default group
|
||||
_update_and_publish();
|
||||
}
|
||||
}
|
||||
|
||||
AdminServiceServer::~AdminServiceServer() {}
|
||||
|
||||
void AdminServiceServer::create_account(const api::admin::AccountCreateAPIArgument& acct_create_arg,
|
||||
const api::Response<::bts::api::VoidMessage>&)
|
||||
const api::Response<::bts::api::VoidMessage>&)
|
||||
{
|
||||
if (_find_account(acct_create_arg.account_name())==nullptr){
|
||||
if (AdminServiceUtils::find_account(_state, acct_create_arg.account_name())==nullptr){
|
||||
bts::api::admin::BTSAccount* new_account = _state.add_accounts();
|
||||
new_account->set_id(_find_curr_acct_id()+1);
|
||||
new_account->set_id(AdminServiceUtils::find_curr_acct_id(_state)+1);
|
||||
new_account->set_name(acct_create_arg.account_name());
|
||||
new_account->set_description(acct_create_arg.description());
|
||||
new_account->set_is_active(false);
|
||||
@@ -67,7 +65,7 @@ void AdminServiceServer::create_account(const api::admin::AccountCreateAPIArgume
|
||||
void AdminServiceServer::set_account_clip_limits(const api::admin::AccountSecurityClipLimitsAPIArgument& acct_clips_arg,
|
||||
const api::Response<::bts::api::VoidMessage>&)
|
||||
{
|
||||
bts::api::admin::BTSAccount* account = _find_account(acct_clips_arg.account_id());
|
||||
bts::api::admin::BTSAccount* account = AdminServiceUtils::find_account(_state, acct_clips_arg.account_id());
|
||||
if (account != nullptr)
|
||||
{
|
||||
// if(!account->has_account_data())
|
||||
@@ -121,13 +119,24 @@ void AdminServiceServer::set_user_cme_md_entitlement_data(const api::admin::CMEU
|
||||
{
|
||||
}
|
||||
|
||||
void AdminServiceServer::set_user_cme_routing_data(const api::admin::CMEUserDataAPIArgument&,
|
||||
const api::Response<::bts::api::VoidMessage>&)
|
||||
{
|
||||
void AdminServiceServer::set_user_cme_routing_data(const api::admin::CMEUserDataAPIArgument& cme_user_data,
|
||||
const api::Response<::bts::api::VoidMessage>&)
|
||||
{
|
||||
bts::api::admin::BTSUser* user = AdminServiceUtils::find_user(_state, cme_user_data.user_id());
|
||||
if (user != nullptr){
|
||||
if (cme_user_data.has_complete_data())
|
||||
AdminServiceUtils::set_user_cme_data(user, cme_user_data.complete_data());
|
||||
else
|
||||
AdminServiceUtils::clear_user_cme_data(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
// report back
|
||||
}
|
||||
}
|
||||
|
||||
void AdminServiceServer::get_user_model(const bts::api::VoidMessage&,
|
||||
const api::Response<::bts::api::admin::AdminData>&)
|
||||
const api::Response<::bts::api::admin::AdminData>&)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -144,60 +153,4 @@ void AdminServiceServer::_update_and_publish()
|
||||
LOG(Gen, Error, "Could not save user data");
|
||||
}
|
||||
|
||||
bts::api::admin::BTSAccount* AdminServiceServer::_find_account (const std::string& acct_name){
|
||||
for(int i=0; i<_state.accounts_size(); i++){
|
||||
bts::api::admin::BTSAccount* acct = _state.mutable_accounts(i);
|
||||
if(acct_name==acct->name())
|
||||
return acct;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bts::api::admin::BTSAccount* AdminServiceServer::_find_account (int id){
|
||||
for(int i=0; i<_state.accounts_size(); i++){
|
||||
bts::api::admin::BTSAccount* acct = _state.mutable_accounts(i);
|
||||
if(id == acct->id())
|
||||
return acct;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bts::api::admin::BTSUser* AdminServiceServer::_find_user (const std::string& user_name){
|
||||
for(int i=0; i<_state.users_size(); i++){
|
||||
bts::api::admin::BTSUser* user = _state.mutable_users(i);
|
||||
if(user_name==user->name())
|
||||
return user;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bts::api::admin::BTSUser* AdminServiceServer::_find_user (const int id){
|
||||
for(int i=0; i<_state.users_size(); i++){
|
||||
bts::api::admin::BTSUser* user = _state.mutable_users(i);
|
||||
if(id == user->id())
|
||||
return user;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int AdminServiceServer::_find_curr_acct_id (){
|
||||
int rv = 0;
|
||||
for(int i=0; i<_state.accounts_size(); i++){
|
||||
bts::api::admin::BTSAccount* acct = _state.mutable_accounts(i);
|
||||
if (acct->id() > rv)
|
||||
rv = acct->id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int AdminServiceServer::_find_curr_user_id (){
|
||||
int rv = 0;
|
||||
for(int i=0; i<_state.users_size(); i++){
|
||||
bts::api::admin::BTSUser* user = _state.mutable_users(i);
|
||||
if (user->id() > rv)
|
||||
rv = user->id();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}}
|
||||
Reference in new issue
Block a user