Commit b2ee4f0f authored by jan.koester's avatar jan.koester
Browse files

test

parent baab53a1
Loading
Loading
Loading
Loading
+196 −13
Changes for plugins/content/content.cpp: 196 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,11 @@

#define SITELIMIT 10

#define GPO_CONTENT_EDIT_OWN      "c3eaf8g4-9d5f-6a7c-b123-4f6d8e0g2c34"
#define GPO_CONTENT_EDIT_OTHERS   "d4fba9h5-0e6g-7b8d-c234-5g7e9f1h3d45"
#define GPO_CONTENT_DELETE_OWN    "a1c8f6e2-7b3d-4e5a-9f01-2d4b6c8e0a12"
#define GPO_CONTENT_DELETE_OTHERS "b2d9e7f3-8c4e-5f6b-a012-3e5c7d9f1b23"

namespace blogi {
    class Content : public PluginApi{
    public:
@@ -118,13 +123,7 @@ namespace blogi {

            std::string meta;

            if(Args->auth->isLoggedIn(tid,curreq,sessionid)){
                condat << "<div class=\"blog_adminmenu\">"
                << "<ul>"
                << "<li><a href=\""<< Args->config->buildurl("content/addpost") <<"\">Addpost</a></li>"
                << "</ul>"
                << "</div>";
            }


            if (ncount<1) {
                condat << " </div>";
@@ -234,7 +233,7 @@ namespace blogi {

            dbpp::SQL sql;

            sql << "select content.id,content.title,content.text,users.displayname,content.created from content LEFT JOIN users ON content.author=users.id WHERE content.id='" << cid <<"' LIMIT 1";
            sql << "select content.id,content.title,content.text,users.displayname,content.created,content.author from content LEFT JOIN users ON content.author=users.id WHERE content.id='" << cid <<"' LIMIT 1";

            dbpp::DBResult res;

@@ -244,20 +243,74 @@ namespace blogi {
                throw excep;
            }

            // Admin menu (only when logged in)
            // Admin menu with GPO-based edit/delete visibility
            if (Args->auth->isLoggedIn(tid,curreq,sessionid)) {
                bool canEdit = false;
                bool canDelete = false;
                try {
                    std::string authid;
                    Session sess(*Args->database[tid]);
                    sess.getSessionData(sessionid,"authid",authid);
                    if(!authid.empty()){
                        std::string uid;
                        sess.getSessionData(sessionid,"uid",uid);
                        dbpp::SQL asql;
                        dbpp::DBResult ares;
                        asql << "SELECT id FROM users WHERE sid='" << uid.c_str() << "' LIMIT 1;";
                        int currentAuthor = -1;
                        if(Args->database[tid]->exec(asql,ares) >= 1)
                            currentAuthor = atoi(ares[0][0]);

                        int postAuthor = res[0][5] ? atoi(res[0][5]) : -2;

                        for(size_t si = 0; si < Args->config->getAuthSourceCount(); ++si){
                            const AuthSource &src = Args->config->getAuthSource(si);
                            try {
                                authdb::client::ClientConnection authcon;
                                authcon.setUrl(src.url);
                                authcon.setClientName(src.clientName);
                                authcon.setClientSecret(src.clientSecret);
                                authcon.setSessionID(uuid::uuid(authid.c_str()));
                                authdb::client::Client clt(authcon);
                                if(clt.ClientAuth()){
                                    bool isOwn = (currentAuthor == postAuthor);
                                    if(!canEdit){
                                        if(isOwn && clt.GPOcheck(uuid::uuid(GPO_CONTENT_EDIT_OWN)))
                                            canEdit = true;
                                        else if(clt.GPOcheck(uuid::uuid(GPO_CONTENT_EDIT_OTHERS)))
                                            canEdit = true;
                                    }
                                    if(!canDelete){
                                        if(isOwn && clt.GPOcheck(uuid::uuid(GPO_CONTENT_DELETE_OWN)))
                                            canDelete = true;
                                        else if(clt.GPOcheck(uuid::uuid(GPO_CONTENT_DELETE_OTHERS)))
                                            canDelete = true;
                                    }
                                }
                            } catch(...) { continue; }
                            if(canEdit && canDelete) break;
                        }
                    }
                } catch(...) {}

                if(canEdit || canDelete){
                    libhtmlpp::HtmlString admindat;
                    admindat << "<div id=\"content\"><div class=\"blog_adminmenu\">"
                << "<ul>"
                << "<li><a href=\"" << Args->config->buildurl("content/edit/") << cid << "\">"+tr(_lang,"Edit")+"</a></li>"
                << "<li><a href=\"" << Args->config->buildurl("content/del/") << cid << "\">"+tr(_lang,"Delete")+"</a></li>"
                << "</ul>"
                    << "<ul>";
                    if(canEdit){
                        admindat << "<li><a href=\"" << Args->config->buildurl("content/edit/") << cid << "\">"+tr(_lang,"Edit")+"</a></li>";
                    }
                    if(canDelete){
                        admindat << "<li><a href=\"" << Args->config->buildurl("content/del/") << cid << "\">"+tr(_lang,"Delete")+"</a></li>";
                    }
                    admindat << "</ul>"
                    << "</div></div>";
                    libhtmlpp::HtmlElement *main = page.getElementbyID("main");
                    if (main) {
                        try { main->insertChild(admindat.parse()); } catch (...) {}
                    }
                }
            }

            // Use RenderPublished for the article wrapper
            json_object *params = json_object_new_object();
@@ -485,6 +538,61 @@ namespace blogi {

            sscanf(curreq.getRequestURL().c_str(), Args->config->buildurl("content/del/%d").c_str(), &cid);

            // Get the post's author
            dbpp::SQL psql;
            dbpp::DBResult pres;
            psql << "SELECT author FROM content WHERE id='" << cid << "' LIMIT 1;";
            if(Args->database[tid]->exec(psql,pres) < 1){
                excep[libhttppp::HTTPException::Error] << "Post not found!";
                throw excep;
            }
            int postAuthor = atoi(pres[0][0]);

            // Get current user's author id
            std::string uid;
            Session sess(*Args->database[tid]);
            sess.getSessionData(sessionid,"uid",uid);

            dbpp::SQL asql;
            dbpp::DBResult ares;
            asql << "SELECT id FROM users WHERE sid='" << uid.c_str() << "' LIMIT 1;";
            if(Args->database[tid]->exec(asql,ares) < 1){
                excep[libhttppp::HTTPException::Error] << "User not found!";
                throw excep;
            }
            int currentAuthor = atoi(ares[0][0]);

            // Check GPO permissions via authdb
            bool allowed = false;
            std::string authid;
            sess.getSessionData(sessionid,"authid",authid);
            if(!authid.empty()){
                for(size_t si = 0; si < Args->config->getAuthSourceCount(); ++si){
                    const AuthSource &src = Args->config->getAuthSource(si);
                    try {
                        authdb::client::ClientConnection authcon;
                        authcon.setUrl(src.url);
                        authcon.setClientName(src.clientName);
                        authcon.setClientSecret(src.clientSecret);
                        authcon.setSessionID(uuid::uuid(authid.c_str()));
                        authdb::client::Client clt(authcon);
                        if(clt.ClientAuth()){
                            if(currentAuthor == postAuthor && clt.GPOcheck(uuid::uuid(GPO_CONTENT_DELETE_OWN))){
                                allowed = true;
                            } else if(clt.GPOcheck(uuid::uuid(GPO_CONTENT_DELETE_OTHERS))){
                                allowed = true;
                            }
                        }
                    } catch(...) { continue; }
                    if(allowed) break;
                }
            }

            if(!allowed){
                excep[libhttppp::HTTPException::Error] << "Permission denied: insufficient rights to delete this post!";
                throw excep;
            }

            sql ="DELETE FROM tags_content WHERE content_id='";
            sql << cid << "';" <<" DELETE FROM content WHERE id='"; sql << cid << "';";

@@ -571,6 +679,61 @@ namespace blogi {

            sscanf(curreq.getRequestURL().c_str(), Args->config->buildurl("content/edit/%d").c_str(), &cid);

            // GPO permission check for editing
            {
                dbpp::SQL psql;
                dbpp::DBResult pres;
                psql << "SELECT author FROM content WHERE id='" << cid << "' LIMIT 1;";
                if(Args->database[tid]->exec(psql,pres) < 1){
                    excep[libhttppp::HTTPException::Error] << "Post not found!";
                    throw excep;
                }
                int postAuthor = atoi(pres[0][0]);

                std::string uid;
                Session sess(*Args->database[tid]);
                sess.getSessionData(sessionid,"uid",uid);

                dbpp::SQL asql;
                dbpp::DBResult ares;
                asql << "SELECT id FROM users WHERE sid='" << uid.c_str() << "' LIMIT 1;";
                if(Args->database[tid]->exec(asql,ares) < 1){
                    excep[libhttppp::HTTPException::Error] << "User not found!";
                    throw excep;
                }
                int currentAuthor = atoi(ares[0][0]);

                bool allowed = false;
                std::string authid;
                sess.getSessionData(sessionid,"authid",authid);
                if(!authid.empty()){
                    for(size_t si = 0; si < Args->config->getAuthSourceCount(); ++si){
                        const AuthSource &src = Args->config->getAuthSource(si);
                        try {
                            authdb::client::ClientConnection authcon;
                            authcon.setUrl(src.url);
                            authcon.setClientName(src.clientName);
                            authcon.setClientSecret(src.clientSecret);
                            authcon.setSessionID(uuid::uuid(authid.c_str()));
                            authdb::client::Client clt(authcon);
                            if(clt.ClientAuth()){
                                if(currentAuthor == postAuthor && clt.GPOcheck(uuid::uuid(GPO_CONTENT_EDIT_OWN))){
                                    allowed = true;
                                } else if(clt.GPOcheck(uuid::uuid(GPO_CONTENT_EDIT_OTHERS))){
                                    allowed = true;
                                }
                            }
                        } catch(...) { continue; }
                        if(allowed) break;
                    }
                }

                if(!allowed){
                    excep[libhttppp::HTTPException::Error] << "Permission denied: insufficient rights to edit this post!";
                    throw excep;
                }
            }

            dbpp::SQL sql;
            dbpp::DBResult res;
            std::vector<char> sbuf;
@@ -743,6 +906,26 @@ namespace blogi {
                        "Controls access to content management",
                        true);

            registerGPO(GPO_CONTENT_EDIT_OWN,
                        "Blogi: Edit Own Posts",
                        "Allows users to edit their own content posts",
                        true);

            registerGPO(GPO_CONTENT_EDIT_OTHERS,
                        "Blogi: Edit Others Posts",
                        "Allows users to edit content posts from other authors",
                        false);

            registerGPO(GPO_CONTENT_DELETE_OWN,
                        "Blogi: Delete Own Posts",
                        "Allows users to delete their own content posts",
                        true);

            registerGPO(GPO_CONTENT_DELETE_OTHERS,
                        "Blogi: Delete Others Posts",
                        "Allows users to delete content posts from other authors",
                        false);

            dbpp::SQL sql;
            dbpp::DBResult res;
            sql << "CREATE TABLE IF NOT EXISTS content ("
+9 −18
Changes for src/edit.cpp: 9 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -2911,20 +2911,21 @@ void blogi::webedit::WebEditor::Renderer(
            root->appendChild(globalStyle);
        }

        if (!publishTarget.empty() && plugins) {
            // Render widget tree to HTML string, then pass through target plugin's RenderPublished
            std::string renderedHtml;
        // Render user-created document elements into root
        if (DocRoot) {
                libhtmlpp::HtmlElement wrapper("div");
            const EditPlugin *el = DocRoot;
            while (el) {
                    el->Render(wrapper);
                el->Render(*root);
                el = el->nextElement();
            }
                libhtmlpp::HtmlString htmlOut;
                libhtmlpp::print(wrapper, htmlOut);
                renderedHtml = htmlOut.str();
        }
    }

    // If publish preview requested, wrap the rendered content through the target plugin
    if (!publishTarget.empty() && plugins && root) {
        libhtmlpp::HtmlString rootHtml;
        libhtmlpp::print(*root, rootHtml);
        std::string renderedHtml = rootHtml.str();

        for (const Plugin::PluginData *curplg = plugins->getFirstPlugin(); curplg; curplg = curplg->getNextPlg()) {
            PluginApi *api = curplg->getInstace();
@@ -2933,16 +2934,6 @@ void blogi::webedit::WebEditor::Renderer(
                break;
            }
        }
        } else {
            // Default: render widgets directly into root element
            if (DocRoot) {
                const EditPlugin *el = DocRoot;
                while (el) {
                    el->Render(*root);
                    el = el->nextElement();
                }
            }
        }
    }

    Args.theme->printSite(tid,out,&ridx,curreq.getRequestURL(),false);