diff --git a/src/server/sparkd/user/AdminServiceServer.cpp b/src/server/sparkd/user/AdminServiceServer.cpp index 3800dd5f3..132098b35 100644 --- a/src/server/sparkd/user/AdminServiceServer.cpp +++ b/src/server/sparkd/user/AdminServiceServer.cpp @@ -19,6 +19,7 @@ AdminServiceServer::AdminServiceServer(bts::api::ServiceContext& context) bts::api::admin::AdminServiceBase (context), _table_name("users"), _unique_key("0"), + _default_group_name("DEFAULT"), _state(), _store(new bts::persistence::SqliteStore("user_model")) { @@ -43,6 +44,10 @@ AdminServiceServer::AdminServiceServer(bts::api::ServiceContext& context) { // first time // TODO add default group + bts::api::admin::BTSUserGroup default_group; + default_group.set_id(0); + default_group.set_name(_default_group_name); + AdminServiceUtils::create_group(&_state, default_group); _update_and_publish(); } } @@ -55,6 +60,8 @@ void AdminServiceServer::create_account(const api::admin::AccountCreateAPIArgume if (AdminServiceUtils::find_account(_state, acct_create_arg.account_name())==nullptr){ bts::api::admin::BTSAccount* new_account = _state.add_accounts(); new_account->set_id(AdminServiceUtils::find_curr_acct_id(_state)+1); + if(acct_create_arg.has_parent_account_id()) + new_account->mutable_parent_account_id()->set_id(acct_create_arg.parent_account_id().id()); new_account->set_name(acct_create_arg.account_name()); new_account->set_description(acct_create_arg.description()); new_account->set_is_active(false); @@ -113,9 +120,15 @@ void AdminServiceServer::set_account_exchange_data(const api::admin::AccountExch reply(result); } -void AdminServiceServer::create_user(const api::admin::UserCreateAPIArgument&, +void AdminServiceServer::create_user(const api::admin::UserCreateAPIArgument& new_user, const api::Response<::bts::api::VoidMessage>&) { + bts::api::admin::BTSUser* new_user_ptr = _state.add_users(); + // test for name + new_user_ptr->set_name(new_user.name()); + new_user_ptr->set_password (new_user.password()); + new_user_ptr->mutable_license_entitlements()->CopyFrom(new_user.license_entitlements()); + _update_and_publish(); } void AdminServiceServer::set_user_account_association(const api::admin::UserAccountAssociationAPIArgument&, diff --git a/src/server/sparkd/user/AdminServiceServer.h b/src/server/sparkd/user/AdminServiceServer.h index 52cb543ae..32b773e9a 100644 --- a/src/server/sparkd/user/AdminServiceServer.h +++ b/src/server/sparkd/user/AdminServiceServer.h @@ -14,6 +14,7 @@ class AdminServiceServer : public api::admin::AdminServiceBase private: const std::string _table_name; const std::string _unique_key; + const std::string _default_group_name; bts::api::admin::AdminData _state; std::unique_ptr _store; public: diff --git a/src/server/sparkd/user/AdminServiceUtils.h b/src/server/sparkd/user/AdminServiceUtils.h index 4c3e9d648..10d79d300 100644 --- a/src/server/sparkd/user/AdminServiceUtils.h +++ b/src/server/sparkd/user/AdminServiceUtils.h @@ -52,6 +52,15 @@ public: } // finding max id's (for id generation) ////////////////////////////////////// + static int find_curr_group_id (const bts::api::admin::AdminData& data){ + int rv = 0; + for(int i=0; i rv) + rv = group.id(); + } + return rv; + } static int find_curr_acct_id (bts::api::admin::AdminData& data){ int rv = 0; for(int i=0; ihas_exchange_account_data()) account->mutable_exchange_account_data(); account->mutable_exchange_account_data()->mutable_cme_account_data()->CopyFrom(cme_account_data); - } + } + // creation + /////////////////////////////// + static void create_group (bts::api::admin::AdminData* data, const bts::api::admin::BTSUserGroup& new_group){ + bts::api::admin::BTSUserGroup* new_group_ptr = data->add_user_groups(); + new_group_ptr->CopyFrom(new_group); + } }; }} \ No newline at end of file