From 51e0d83c47940b5ecd86276312033e272fca566e Mon Sep 17 00:00:00 2001 From: zeners Date: Mon, 21 Mar 2016 17:04:21 +0100 Subject: [PATCH] webui: options / rights (only defaults) --- libresapi/src/api/ServiceControlHandler.cpp | 37 +++++++++ libresapi/src/webui-src/app/forums.js | 1 + libresapi/src/webui-src/app/menudef.js | 10 +++ libresapi/src/webui-src/app/options.js | 19 +++++ libresapi/src/webui-src/app/retroshare.js | 8 +- libresapi/src/webui-src/app/servicecontrol.js | 83 +++++++++++++++++++ 6 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 libresapi/src/webui-src/app/options.js create mode 100644 libresapi/src/webui-src/app/servicecontrol.js diff --git a/libresapi/src/api/ServiceControlHandler.cpp b/libresapi/src/api/ServiceControlHandler.cpp index dc7a07093..84497f5e5 100644 --- a/libresapi/src/api/ServiceControlHandler.cpp +++ b/libresapi/src/api/ServiceControlHandler.cpp @@ -4,6 +4,8 @@ #include "Operators.h" +#include + namespace resource_api { // maybe move to another place later @@ -73,7 +75,42 @@ void ServiceControlHandler::handleWildcard(Request &req, Response &resp) } else if(req.isPut()) { + // change service default + std::string serviceidtext; + bool enabled; + + req.mStream << makeKeyValueReference("service_id", serviceidtext) + << makeKeyValueReference("default_allowed", enabled); + + RsServicePermissions serv_perms ; + //uint32_t serviceid = fromString(serviceidtext); + uint32_t serviceid = atoi(serviceidtext.c_str()); + if (serviceid == 0) { + resp.setFail("serviceid missed"); + return; + } + + if(!rsServiceControl->getServicePermissions(serviceid, serv_perms)){ + resp.setFail("service_id " + serviceidtext + " is invalid"); + return; + } + + serv_perms.mDefaultAllowed = enabled; + if(serv_perms.mDefaultAllowed) + { + serv_perms.mPeersDenied.clear() ; + } + else + { + serv_perms.mPeersAllowed.clear() ; + } + + ok = rsServiceControl->updateServicePermissions(serviceid,serv_perms); + if (!ok) { + resp.setFail("updateServicePermissions failed"); + return; + } } } if(ok) diff --git a/libresapi/src/webui-src/app/forums.js b/libresapi/src/webui-src/app/forums.js index 289c87b22..423c99262 100644 --- a/libresapi/src/webui-src/app/forums.js +++ b/libresapi/src/webui-src/app/forums.js @@ -6,6 +6,7 @@ var rs = require("retroshare"); module.exports = {view: function(){ return m("div",[ m("h2","forums"), + m("p","(work in progress, currently only listing)"), m("hr"), /* m("div.btn2", { diff --git a/libresapi/src/webui-src/app/menudef.js b/libresapi/src/webui-src/app/menudef.js index 5a4f41640..dd1d63bd4 100644 --- a/libresapi/src/webui-src/app/menudef.js +++ b/libresapi/src/webui-src/app/menudef.js @@ -83,6 +83,16 @@ module.exports = { nodes: [ } }) }, + { + name:"options", + runstate: "running_ok.*", + }, + { + name:"servicecontrol", + runstate: "running_ok.*", + path:"/options/servicecontrol", + show: false, + }, { name: "shutdown", runstate: "running_ok|waiting_account_select", diff --git a/libresapi/src/webui-src/app/options.js b/libresapi/src/webui-src/app/options.js new file mode 100644 index 000000000..2bb8e74c7 --- /dev/null +++ b/libresapi/src/webui-src/app/options.js @@ -0,0 +1,19 @@ +"use strict"; + +var m = require("mithril"); +var rs = require("retroshare"); + +module.exports = { + view: function(){ + return m("div", [ + m("h2","Options"), + m("hr"), + m("div.btn2",{ + onclick: function(){ + m.route("/options/servicecontrol"); + }, + }, "rights") + ]); + } +} + diff --git a/libresapi/src/webui-src/app/retroshare.js b/libresapi/src/webui-src/app/retroshare.js index 2c7f8e500..be1213412 100644 --- a/libresapi/src/webui-src/app/retroshare.js +++ b/libresapi/src/webui-src/app/retroshare.js @@ -253,8 +253,12 @@ function optionsPrep(options, path) { } // force reload for path -rs.forceUpdate = function(path){ - cache[path].requested=false; +rs.forceUpdate = function(path, removeCache){ + if (removeCache === undefined || !removeCache) { + cache[path].requested=false; + } else { + delete cache[path]; + } } //return api-path diff --git a/libresapi/src/webui-src/app/servicecontrol.js b/libresapi/src/webui-src/app/servicecontrol.js new file mode 100644 index 000000000..9d4b36321 --- /dev/null +++ b/libresapi/src/webui-src/app/servicecontrol.js @@ -0,0 +1,83 @@ +"use strict"; + +var m = require("mithril"); +var rs = require("retroshare"); + +function setOption(id,value) { + return function(){ + rs.request("servicecontrol", { + service_id: id, + default_allowed: value, + }); + rs.forceUpdate("servicecontrol", true); + } +} + +module.exports = { + view: function(){ + return m("div", [ + m("h2","Options / Rights"), + m("div.btn2",{ + onclick: function(){ + m.route("/options") + }, + },"back to options"), + m("hr"), + m("ul", rs.list("servicecontrol", function(item){ + //return m("li",item.service_name) + if (item.service_name.match("banlist")) { + console.log("banlist:" + item.default_allowed); + } + return m("li", { + style: { + margin: "2px", + color: item.default_allowed ? "lime" :"red", + } + }, [ + m("div", { + onclick: setOption( + item.service_id, + !item.default_allowed + ), + }, [ + m("div.menu", { + style: { + float:"left", + width:"30px", + color: "#303030", + textAlign: "center", + backgroundColor: !item.default_allowed + ? "black" + : "lime", + } + }, "ON"), + m("div.menu",{ + style: { + float:"left", + width:"30px", + textAlign: "center", + marginRight:"5px", + color: "#303030", + backgroundColor: item.default_allowed + ? "black" + : "lime", + } + }, "OFF"), + ]), + m("div", { + style: { + color: "lime", + } + }, item.service_name), + m("div", { + style: { + clear: "left" + } + }), + ]); + }) + ) + ]); + } +} +