webui: options / rights (only defaults)

This commit is contained in:
zeners 2016-03-21 17:04:21 +01:00
parent 1c94ff743b
commit 51e0d83c47
6 changed files with 156 additions and 2 deletions

View File

@ -4,6 +4,8 @@
#include "Operators.h"
#include <stdlib.h>
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<uint32_t>(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)

View File

@ -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", {

View File

@ -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",

View File

@ -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")
]);
}
}

View File

@ -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

View File

@ -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"
}
}),
]);
})
)
]);
}
}