Skip to content

Commit 3489d5d

Browse files
authored
Merge pull request #984 from imachug/privatekey
Don't ask user for privatekey if file can be signed with auth_privatekey
2 parents db8c85d + f4a0400 commit 3489d5d

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

plugins/Sidebar/media/Sidebar.coffee

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,18 @@ class Sidebar extends Class
354354
@tag.find("#button-sign").off("click touchend").on "click touchend", =>
355355
inner_path = @tag.find("#input-contents").val()
356356

357-
if wrapper.site_info.privatekey
358-
# Privatekey stored in users.json
359-
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
360-
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
357+
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
358+
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
359+
# Privatekey stored in users.json
360+
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
361+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
361362

362-
else
363-
# Ask the user for privatekey
364-
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
365-
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
366-
if res == "ok"
367-
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
363+
else
364+
# Ask the user for privatekey
365+
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
366+
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
367+
if res == "ok"
368+
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
368369

369370
return false
370371

plugins/Sidebar/media/all.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ window.initScrollable = function () {
189189
var Sidebar,
190190
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
191191
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
192-
hasProp = {}.hasOwnProperty;
192+
hasProp = {}.hasOwnProperty,
193+
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
193194

194195
Sidebar = (function(superClass) {
195196
extend(Sidebar, superClass);
@@ -600,27 +601,32 @@ window.initScrollable = function () {
600601
return function() {
601602
var inner_path;
602603
inner_path = _this.tag.find("#input-contents").val();
603-
if (wrapper.site_info.privatekey) {
604-
wrapper.ws.cmd("siteSign", {
605-
privatekey: "stored",
606-
inner_path: inner_path,
607-
update_changed_files: true
608-
}, function(res) {
609-
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
610-
});
611-
} else {
612-
wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
604+
wrapper.ws.cmd("fileRules", {
605+
inner_path: inner_path
606+
}, function(res) {
607+
var ref;
608+
if (wrapper.site_info.privatekey || (ref = wrapper.site_info.auth_address, indexOf.call(res.signers, ref) >= 0)) {
613609
return wrapper.ws.cmd("siteSign", {
614-
privatekey: privatekey,
610+
privatekey: "stored",
615611
inner_path: inner_path,
616612
update_changed_files: true
617613
}, function(res) {
618-
if (res === "ok") {
619-
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
620-
}
614+
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
621615
});
622-
});
623-
}
616+
} else {
617+
return wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
618+
return wrapper.ws.cmd("siteSign", {
619+
privatekey: privatekey,
620+
inner_path: inner_path,
621+
update_changed_files: true
622+
}, function(res) {
623+
if (res === "ok") {
624+
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
625+
}
626+
});
627+
});
628+
}
629+
});
624630
return false;
625631
};
626632
})(this));
@@ -676,7 +682,7 @@ window.initScrollable = function () {
676682
return img.onload = (function(_this) {
677683
return function() {
678684
return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) {
679-
var e, ref, ref1;
685+
var e, error, ref, ref1;
680686
if (_this.globe) {
681687
_this.globe.scene.remove(_this.globe.points);
682688
_this.globe.addData(globe_data, {

0 commit comments

Comments
 (0)