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

test

parent 9f722af6
Loading
Loading
Loading
Loading
+22 −6
Changes for plugins/content/content.cpp: 22 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -954,25 +954,44 @@ namespace blogi {

                if(sub.find("delete") == 0){
                    int cid = -1;
                    bool confirmed = false;
                    libhttppp::HttpForm delform;
                    delform.parse(req);
                    for(const auto &cur : delform.urlData()){
                        if(cur.key == "id") { cid = atoi(cur.value.c_str()); break; }
                        if(cur.key == "id") cid = atoi(cur.value.c_str());
                        if(cur.key == "confirm" && cur.value == "yes") confirmed = true;
                    }

                    if(cid > 0){
                        // Check permission
                        dbpp::SQL psql; dbpp::DBResult pres;
                        psql << "SELECT author FROM content WHERE id='" << cid << "' LIMIT 1;";
                        psql << "SELECT author,title FROM content WHERE id='" << cid << "' LIMIT 1;";
                        bool allowed = false;
                        std::string postTitle;
                        if(Args->database[tid]->exec(psql,pres) >= 1){
                            int postAuthor = atoi(pres[0][0]);
                            if(pres[0][1]) postTitle = pres[0][1];
                            if(currentAuthor == postAuthor && canDelOwn) allowed = true;
                            else if(canDelOthers) allowed = true;
                        }
                        json_object *jroot = json_object_new_object();
                        json_object_object_add(jroot, "title", json_object_new_string(tr(_lang,"Content").c_str()));
                        if(allowed){

                        if(!allowed){
                            json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Permission denied").c_str()));
                            json_object_object_add(jroot, "message_type", json_object_new_string("error"));
                        } else if(!confirmed){
                            // Show confirmation dialog
                            json_object *jconfirm = json_object_new_object();
                            std::string msg = tr(_lang,"Are you sure you want to delete") + " \"" + postTitle + "\"?";
                            json_object_object_add(jconfirm, "message", json_object_new_string(msg.c_str()));
                            std::string yesUrl = Args->config->buildurl("settings/content/delete?id=")
                                + std::to_string(cid) + "&confirm=yes";
                            json_object_object_add(jconfirm, "yes_url", json_object_new_string(yesUrl.c_str()));
                            json_object_object_add(jconfirm, "no_url",
                                json_object_new_string(Args->config->buildurl("settings/content").c_str()));
                            json_object_object_add(jroot, "confirm", jconfirm);
                        } else {
                            dbpp::SQL dsql; dbpp::DBResult dres;
                            dsql << "DELETE FROM tags_content WHERE content_id='" << cid << "';";
                            try { Args->database[tid]->exec(dsql,dres); } catch(...) {}
@@ -982,9 +1001,6 @@ namespace blogi {
                            cleartags(tid);
                            json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Post deleted").c_str()));
                            json_object_object_add(jroot, "message_type", json_object_new_string("success"));
                        } else {
                            json_object_object_add(jroot, "message", json_object_new_string(tr(_lang,"Permission denied").c_str()));
                            json_object_object_add(jroot, "message_type", json_object_new_string("error"));
                        }
                        json_object *jnav = json_object_new_array();
                        json_object *jback = json_object_new_object();