Added optional redirect value for siteClone (#2032)

* Added optional redirect value; see #1891

* Return address of the newly cloned site
This commit is contained in:
Lola Dam 2019-05-28 18:05:52 +02:00 committed by ZeroNet
parent 9c0e8ee833
commit 7262fbfb4e

View file

@ -968,15 +968,17 @@ class UiWebsocket(object):
else:
self.response(to, {"error": "Unknown site: %s" % address})
def cbSiteClone(self, to, address, root_inner_path="", target_address=None):
def cbSiteClone(self, to, address, root_inner_path="", target_address=None, redirect=True):
self.cmd("notification", ["info", _["Cloning site..."]])
site = self.server.sites.get(address)
response = {}
if target_address:
target_site = self.server.sites.get(target_address)
privatekey = self.user.getSiteData(target_site.address).get("privatekey")
site.clone(target_address, privatekey, root_inner_path=root_inner_path)
self.cmd("notification", ["done", _["Site source code upgraded!"]])
site.publish()
response = {"address": target_address}
else:
# Generate a new site from user's bip32 seed
new_address, new_address_index, new_site_data = self.user.getNewSiteData()
@ -984,11 +986,14 @@ class UiWebsocket(object):
new_site.settings["own"] = True
new_site.saveSettings()
self.cmd("notification", ["done", _["Site cloned"]])
self.cmd("redirect", "/%s" % new_address)
if redirect :
self.cmd("redirect", "/%s" % new_address)
gevent.spawn(new_site.announce)
response = {"address": new_address}
self.response(to, response)
return "ok"
def actionSiteClone(self, to, address, root_inner_path="", target_address=None):
def actionSiteClone(self, to, address, root_inner_path="", target_address=None, redirect=True):
if not SiteManager.site_manager.isAddress(address):
self.response(to, {"error": "Not a site: %s" % address})
return
@ -1006,12 +1011,12 @@ class UiWebsocket(object):
return {"error": "Site still in sync"}
if "ADMIN" in self.getPermissions(to):
self.cbSiteClone(to, address, root_inner_path, target_address)
self.cbSiteClone(to, address, root_inner_path, target_address, redirect)
else:
self.cmd(
"confirm",
[_["Clone site <b>%s</b>?"] % address, _["Clone"]],
lambda res: self.cbSiteClone(to, address, root_inner_path, target_address)
lambda res: self.cbSiteClone(to, address, root_inner_path, target_address, redirect)
)
def actionSiteSetLimit(self, to, size_limit):