Rev3114, Add details to permission requests

This commit is contained in:
shortcutme 2017-10-17 17:02:56 +02:00
parent e3931e8892
commit d50603f722
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
5 changed files with 40 additions and 11 deletions

View File

@ -199,6 +199,26 @@ class UiWebsocketPlugin(object):
if permission.startswith("Merger"):
self.site.storage.rebuildDb()
def actionPermissionDetails(self, to, permission):
if not permission.startswith("Merger"):
return super(UiWebsocketPlugin, self).actionPermissionDetails(to, permission)
merger_type = permission.replace("Merger:", "")
merged_sites = []
for address, merged_type in merged_db.iteritems():
if merged_type != merger_type:
continue
site = self.server.sites.get(address)
try:
merged_sites.append(site.content_manager.contents.get("content.json").get("title", address))
except Exception as err:
merged_sites.append(address)
details = _["Read and write permissions to sites with merged type of <b>%s</b> "] % merger_type
details += _["(%s sites)"] % len(merged_sites)
details += "<div style='white-space: normal; max-width: 400px'>%s</div>" % ", ".join(merged_sites)
self.response(to, details)
@PluginManager.registerTo("UiRequest")
class UiRequestPlugin(object):

View File

@ -10,7 +10,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.6.0"
self.rev = 3112
self.rev = 3114
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"

View File

@ -734,6 +734,12 @@ class UiWebsocket(object):
self.site.updateWebsocket(permission_removed=permission)
self.response(to, "ok")
def actionPermissionDetails(self, to, permission):
if permission == "ADMIN":
self.response(to, _["Modify your client's configuration and access all site"] + " <span style='color: red'>" + _["(Dangerous!)"] + "</span>")
else:
self.response(to, "")
# Set certificate that used for authenticate user for site
def actionCertSet(self, to, domain):
self.user.setCert(self.site.address, domain)

View File

@ -197,9 +197,10 @@ class Wrapper
actionPermissionAdd: (message) ->
permission = message.params
@displayConfirm "This site requests permission:" + " <b>#{@toHtmlSafe(permission)}</b>", "Grant", =>
@ws.cmd "permissionAdd", permission, =>
@sendInner {"cmd": "response", "to": message.id, "result": "Granted"}
@ws.cmd "permissionDetails", permission, (permission_details) =>
@displayConfirm "This site requests permission:" + " <b>#{@toHtmlSafe(permission)}</b>" + "<br><small style='color: #4F4F4F'>#{permission_details}</small>", "Grant", =>
@ws.cmd "permissionAdd", permission, =>
@sendInner {"cmd": "response", "to": message.id, "result": "Granted"}
actionNotification: (message) ->
message.params = @toHtmlSafe(message.params) # Escape html

View File

@ -1076,13 +1076,15 @@ jQuery.extend( jQuery.easing,
Wrapper.prototype.actionPermissionAdd = function(message) {
var permission;
permission = message.params;
return this.displayConfirm("This site requests permission:" + (" <b>" + (this.toHtmlSafe(permission)) + "</b>"), "Grant", (function(_this) {
return function() {
return _this.ws.cmd("permissionAdd", permission, function() {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": "Granted"
return this.ws.cmd("permissionDetails", permission, (function(_this) {
return function(permission_details) {
return _this.displayConfirm("This site requests permission:" + (" <b>" + (_this.toHtmlSafe(permission)) + "</b>") + ("<br><small style='color: #4F4F4F'>" + permission_details + "</small>"), "Grant", function() {
return _this.ws.cmd("permissionAdd", permission, function() {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": "Granted"
});
});
});
};