Loading src/auth.cpp +3 −0 Changes for src/auth.cpp: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "conf.h" #include "theme.h" #include "session.h" #include "plugin.h" namespace blogi { const uuid::uuid emptyuuid; Loading Loading @@ -94,6 +95,8 @@ void blogi::Auth::_doLogin(const AuthSource &src, const char *username, const ch ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); if(ret){ PluginApi::registerPendingGPOs(clt); if(ssid){ Session sess(*_dbconn[tid]); sess.addSessionData(*ssid,"authid",authcon.getSessionID().c_str()); Loading src/edit.cpp +5 −26 Changes for src/edit.cpp: 5 added lines, 26 removed lines. Original line number Diff line number Diff line Loading @@ -61,32 +61,11 @@ blogi::webedit::WebEditor::WebEditor(PluginArgs &plgargs) : Args (plgargs){ #define GPO_EDITOR_IMPORTEXPORT "f46a4fd3-a69a-4fb4-a908-c5890a244386" void blogi::webedit::WebEditor::registerEditorGPOs(){ auto reg = [&](const char *gpoid, const char *name, const char *desc){ try { if(Args.config->getAuthSourceCount() < 1) return; const AuthSource &src = Args.config->getAuthSource(0); authdb::client::ClientConnection authcon; authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); if(clt.ClientAuth()){ uuid::uuid gid(gpoid); if(!clt.GPOexits(gid)){ clt.GPOadd(gid, name, desc, false, {}); } } } catch(const std::exception &e) { std::cerr << "Editor GPO registration failed for " << name << ": " << e.what() << std::endl; } catch(...) { std::cerr << "Editor GPO registration failed for " << name << std::endl; } }; reg(GPO_EDITOR_PUBLISH, "Blogi: Publish Content", "Controls access to publishing content from the editor"); reg(GPO_EDITOR_SHARE, "Blogi: Share Posts", "Controls access to sharing posts to social networks"); reg(GPO_EDITOR_TEMPLATES, "Blogi: Manage Templates", "Controls access to saving and loading editor templates"); reg(GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export", "Controls access to importing and exporting editor content"); auto &list = PluginApi::getPendingGPOs(); list.push_back({GPO_EDITOR_PUBLISH, "Blogi: Publish Content", "Controls access to publishing content from the editor", false}); list.push_back({GPO_EDITOR_SHARE, "Blogi: Share Posts", "Controls access to sharing posts to social networks", false}); list.push_back({GPO_EDITOR_TEMPLATES, "Blogi: Manage Templates", "Controls access to saving and loading editor templates", false}); list.push_back({GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export", "Controls access to importing and exporting editor content", false}); } bool blogi::webedit::WebEditor::checkEditorGPO(json_object *request, const char *gpoid){ Loading src/plugin.cpp +27 −14 Changes for src/plugin.cpp: 27 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include <iostream> #include <cstring> #include <filesystem> #include <mutex> #include <atomic> #include <httppp/exception.h> Loading Loading @@ -94,26 +96,37 @@ void blogi::PluginApi::initPlugin(){ return; } static std::vector<blogi::PluginApi::PendingGPO> &pendingGPOs(){ static std::vector<blogi::PluginApi::PendingGPO> list; return list; } std::vector<blogi::PluginApi::PendingGPO> &blogi::PluginApi::getPendingGPOs(){ return pendingGPOs(); } void blogi::PluginApi::registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault){ try { if(Args->config->getAuthSourceCount() < 1) static std::mutex mtx; std::lock_guard<std::mutex> lock(mtx); pendingGPOs().push_back({gpoid, name, desc, gpodefault}); } void blogi::PluginApi::registerPendingGPOs(authdb::client::Client &clt){ static std::atomic<bool> done{false}; if(done.exchange(true)) return; const AuthSource &src = Args->config->getAuthSource(0); authdb::client::ClientConnection authcon; authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); if(clt.ClientAuth()){ uuid::uuid gid(gpoid); auto &list = pendingGPOs(); for(const auto &gpo : list){ try { uuid::uuid gid(gpo.gpoid.c_str()); if(!clt.GPOexits(gid)){ clt.GPOadd(gid, name, desc, gpodefault, {}); } clt.GPOadd(gid, gpo.name, gpo.desc, gpo.gpodefault, {}); } } catch(const std::exception &e) { std::cerr << "GPO registration failed for " << name << ": " << e.what() << std::endl; std::cerr << "GPO registration failed for " << gpo.name << ": " << e.what() << std::endl; } catch(...) { std::cerr << "GPO registration failed for " << name << std::endl; std::cerr << "GPO registration failed for " << gpo.name << std::endl; } } } Loading src/plugin.h +10 −0 Changes for src/plugin.h: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -163,6 +163,16 @@ namespace blogi { /// Share a post to social networks; url is the public link, title/description for text virtual void sharePost(const int tid, SharePostType type, const std::string &url, const std::string &title, const std::string &description); struct PendingGPO { std::string gpoid; std::string name; std::string desc; bool gpodefault; }; static void registerPendingGPOs(authdb::client::Client &clt); static std::vector<PendingGPO> &getPendingGPOs(); protected: void registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault); PluginArgs *Args; Loading Loading
src/auth.cpp +3 −0 Changes for src/auth.cpp: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "conf.h" #include "theme.h" #include "session.h" #include "plugin.h" namespace blogi { const uuid::uuid emptyuuid; Loading Loading @@ -94,6 +95,8 @@ void blogi::Auth::_doLogin(const AuthSource &src, const char *username, const ch ret = clt.GPOcheck("e7d3b8b3-4825-11f0-ae2b-3cecefce9cb6"); if(ret){ PluginApi::registerPendingGPOs(clt); if(ssid){ Session sess(*_dbconn[tid]); sess.addSessionData(*ssid,"authid",authcon.getSessionID().c_str()); Loading
src/edit.cpp +5 −26 Changes for src/edit.cpp: 5 added lines, 26 removed lines. Original line number Diff line number Diff line Loading @@ -61,32 +61,11 @@ blogi::webedit::WebEditor::WebEditor(PluginArgs &plgargs) : Args (plgargs){ #define GPO_EDITOR_IMPORTEXPORT "f46a4fd3-a69a-4fb4-a908-c5890a244386" void blogi::webedit::WebEditor::registerEditorGPOs(){ auto reg = [&](const char *gpoid, const char *name, const char *desc){ try { if(Args.config->getAuthSourceCount() < 1) return; const AuthSource &src = Args.config->getAuthSource(0); authdb::client::ClientConnection authcon; authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); if(clt.ClientAuth()){ uuid::uuid gid(gpoid); if(!clt.GPOexits(gid)){ clt.GPOadd(gid, name, desc, false, {}); } } } catch(const std::exception &e) { std::cerr << "Editor GPO registration failed for " << name << ": " << e.what() << std::endl; } catch(...) { std::cerr << "Editor GPO registration failed for " << name << std::endl; } }; reg(GPO_EDITOR_PUBLISH, "Blogi: Publish Content", "Controls access to publishing content from the editor"); reg(GPO_EDITOR_SHARE, "Blogi: Share Posts", "Controls access to sharing posts to social networks"); reg(GPO_EDITOR_TEMPLATES, "Blogi: Manage Templates", "Controls access to saving and loading editor templates"); reg(GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export", "Controls access to importing and exporting editor content"); auto &list = PluginApi::getPendingGPOs(); list.push_back({GPO_EDITOR_PUBLISH, "Blogi: Publish Content", "Controls access to publishing content from the editor", false}); list.push_back({GPO_EDITOR_SHARE, "Blogi: Share Posts", "Controls access to sharing posts to social networks", false}); list.push_back({GPO_EDITOR_TEMPLATES, "Blogi: Manage Templates", "Controls access to saving and loading editor templates", false}); list.push_back({GPO_EDITOR_IMPORTEXPORT, "Blogi: Import/Export", "Controls access to importing and exporting editor content", false}); } bool blogi::webedit::WebEditor::checkEditorGPO(json_object *request, const char *gpoid){ Loading
src/plugin.cpp +27 −14 Changes for src/plugin.cpp: 27 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include <iostream> #include <cstring> #include <filesystem> #include <mutex> #include <atomic> #include <httppp/exception.h> Loading Loading @@ -94,26 +96,37 @@ void blogi::PluginApi::initPlugin(){ return; } static std::vector<blogi::PluginApi::PendingGPO> &pendingGPOs(){ static std::vector<blogi::PluginApi::PendingGPO> list; return list; } std::vector<blogi::PluginApi::PendingGPO> &blogi::PluginApi::getPendingGPOs(){ return pendingGPOs(); } void blogi::PluginApi::registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault){ try { if(Args->config->getAuthSourceCount() < 1) static std::mutex mtx; std::lock_guard<std::mutex> lock(mtx); pendingGPOs().push_back({gpoid, name, desc, gpodefault}); } void blogi::PluginApi::registerPendingGPOs(authdb::client::Client &clt){ static std::atomic<bool> done{false}; if(done.exchange(true)) return; const AuthSource &src = Args->config->getAuthSource(0); authdb::client::ClientConnection authcon; authcon.setUrl(src.url); authcon.setClientName(src.clientName); authcon.setClientSecret(src.clientSecret); authdb::client::Client clt(authcon); if(clt.ClientAuth()){ uuid::uuid gid(gpoid); auto &list = pendingGPOs(); for(const auto &gpo : list){ try { uuid::uuid gid(gpo.gpoid.c_str()); if(!clt.GPOexits(gid)){ clt.GPOadd(gid, name, desc, gpodefault, {}); } clt.GPOadd(gid, gpo.name, gpo.desc, gpo.gpodefault, {}); } } catch(const std::exception &e) { std::cerr << "GPO registration failed for " << name << ": " << e.what() << std::endl; std::cerr << "GPO registration failed for " << gpo.name << ": " << e.what() << std::endl; } catch(...) { std::cerr << "GPO registration failed for " << name << std::endl; std::cerr << "GPO registration failed for " << gpo.name << std::endl; } } } Loading
src/plugin.h +10 −0 Changes for src/plugin.h: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -163,6 +163,16 @@ namespace blogi { /// Share a post to social networks; url is the public link, title/description for text virtual void sharePost(const int tid, SharePostType type, const std::string &url, const std::string &title, const std::string &description); struct PendingGPO { std::string gpoid; std::string name; std::string desc; bool gpodefault; }; static void registerPendingGPOs(authdb::client::Client &clt); static std::vector<PendingGPO> &getPendingGPOs(); protected: void registerGPO(const char *gpoid, const char *name, const char *desc, bool gpodefault); PluginArgs *Args; Loading