From 2df65ed446e5cc3dbd7f65d2d0ef1966ae92aef1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 13 Feb 2020 17:51:02 -0500 Subject: [PATCH 01/37] implement 'mkTimeout' method in common-util --- www/common/common-util.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/www/common/common-util.js b/www/common/common-util.js index 1af32103f..da373f1ad 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -68,6 +68,19 @@ }; }; + Util.mkTimeout = function (_f, ms) { + ms = ms || 0; + var f = Util.once(_f); + + var timeout = setTimeout(function () { + f('TIMEOUT'); + }, ms); + + return Util.both(f, function () { + clearTimeout(timeout); + }); + }; + Util.response = function () { var pending = {}; var timeouts = {}; From ff895bbc82537f9f316e3b589174d8c4bcddbfdd Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 17 Feb 2020 10:53:04 +0100 Subject: [PATCH 02/37] Move inner files --- www/common/common-ui-elements.js | 58 ++++++++++++++-------------- www/common/{ => inner}/invitation.js | 0 www/teams/inner.js | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) rename www/common/{ => inner}/invitation.js (100%) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index fca273e4f..8aba07c18 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -14,7 +14,7 @@ define([ '/customize/application_config.js', '/customize/pages.js', '/bower_components/nthen/index.js', - '/common/invitation.js', + '/common/inner/invitation.js', 'css!/customize/fonts/cptools/style.css', '/bower_components/croppie/croppie.min.js', @@ -100,33 +100,6 @@ define([ }; }; - var getPropertiesData = function (common, cb) { - var data = {}; - NThen(function (waitFor) { - var base = common.getMetadataMgr().getPrivateData().origin; - common.getPadAttribute('', waitFor(function (err, val) { - if (err || !val) { - waitFor.abort(); - return void cb(err || 'EEMPTY'); - } - if (!val.fileType) { - delete val.owners; - delete val.expire; - } - Util.extend(data, val); - if (data.href) { data.href = base + data.href; } - if (data.roHref) { data.roHref = base + data.roHref; } - })); - common.getPadMetadata(null, waitFor(function (obj) { - if (obj && obj.error) { return; } - data.owners = obj.owners; - data.expire = obj.expire; - data.pending_owners = obj.pending_owners; - })); - }).nThen(function () { - cb(void 0, data); - }); - }; var createOwnerModal = function (common, data) { var friends = common.getFriends(true); var sframeChan = common.getSframeChannel(); @@ -436,6 +409,7 @@ define([ }]; return UI.dialog.customModal(link, {buttons: linkButtons}); }; + var getRightsProperties = function (common, data, cb) { var $div = $('
'); if (!data) { return void cb(void 0, $div); } @@ -864,6 +838,34 @@ define([ }; + + var getPropertiesData = function (common, cb) { + var data = {}; + NThen(function (waitFor) { + var base = common.getMetadataMgr().getPrivateData().origin; + common.getPadAttribute('', waitFor(function (err, val) { + if (err || !val) { + waitFor.abort(); + return void cb(err || 'EEMPTY'); + } + if (!val.fileType) { + delete val.owners; + delete val.expire; + } + Util.extend(data, val); + if (data.href) { data.href = base + data.href; } + if (data.roHref) { data.roHref = base + data.roHref; } + })); + common.getPadMetadata(null, waitFor(function (obj) { + if (obj && obj.error) { return; } + data.owners = obj.owners; + data.expire = obj.expire; + data.pending_owners = obj.pending_owners; + })); + }).nThen(function () { + cb(void 0, data); + }); + }; UIElements.getProperties = function (common, data, cb) { var c1; var c2; diff --git a/www/common/invitation.js b/www/common/inner/invitation.js similarity index 100% rename from www/common/invitation.js rename to www/common/inner/invitation.js diff --git a/www/teams/inner.js b/www/teams/inner.js index 4dea3e80d..c42e05489 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -15,7 +15,7 @@ define([ '/common/hyperscript.js', '/customize/application_config.js', '/common/messenger-ui.js', - '/common/invitation.js', + '/common/inner/invitation.js', '/customize/messages.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', From de820dc0d19c7179d59a14ed8d253f9aa03fbbc8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 17 Feb 2020 14:07:29 +0100 Subject: [PATCH 03/37] Split properties modal into 2 modals --- www/common/common-ui-elements.js | 646 ++---------------------------- www/common/drive-ui.js | 93 +++-- www/common/inner/access.js | 658 +++++++++++++++++++++++++++++++ 3 files changed, 738 insertions(+), 659 deletions(-) create mode 100644 www/common/inner/access.js diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 8aba07c18..67c4518fa 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -100,588 +100,8 @@ define([ }; }; - var createOwnerModal = function (common, data) { - var friends = common.getFriends(true); - var sframeChan = common.getSframeChannel(); - var priv = common.getMetadataMgr().getPrivateData(); - var user = common.getMetadataMgr().getUserData(); - var edPublic = priv.edPublic; - var channel = data.channel; - var owners = data.owners || []; - var pending_owners = data.pending_owners || []; - var teams = priv.teams; - var teamOwner = data.teamId; - - var redrawAll = function () {}; - - var div1 = h('div.cp-usergrid-user.cp-share-column.cp-ownership'); - var div2 = h('div.cp-usergrid-user.cp-share-column.cp-ownership'); - var $div1 = $(div1); - var $div2 = $(div2); - - // Remove owner column - var drawRemove = function (pending) { - var _owners = {}; - var o = (pending ? pending_owners : owners) || []; - o.forEach(function (ed) { - var f; - Object.keys(friends).some(function (c) { - if (friends[c].edPublic === ed) { - f = friends[c]; - return true; - } - }); - Object.keys(teams).some(function (id) { - if (teams[id].edPublic === ed) { - f = teams[id]; - f.teamId = id; - } - }); - if (ed === edPublic) { - f = f || user; - if (f.name) { f.edPublic = edPublic; } - } - _owners[ed] = f || { - displayName: Messages._getKey('owner_unknownUser', [ed]), - edPublic: ed, - }; - }); - var msg = pending ? Messages.owner_removePendingText - : Messages.owner_removeText; - var removeCol = UIElements.getUserGrid(msg, { - common: common, - large: true, - data: _owners, - noFilter: true - }, function () { - }); - var $div = $(removeCol.div); - // When clicking on the remove button, we check the selected users. - // If you try to remove yourself, we'll display an additional warning message - var btnMsg = pending ? Messages.owner_removePendingButton : Messages.owner_removeButton; - var removeButton = h('button.no-margin', btnMsg); - $(removeButton).click(function () { - // Check selection - var $sel = $div.find('.cp-usergrid-user.cp-selected'); - var sel = $sel.toArray(); - if (!sel.length) { return; } - var me = false; - var toRemove = sel.map(function (el) { - var ed = $(el).attr('data-ed'); - if (!ed) { return; } - if (teamOwner && teams[teamOwner] && teams[teamOwner].edPublic === ed) { me = true; } - if (ed === edPublic && !teamOwner) { me = true; } - return ed; - }).filter(function (x) { return x; }); - NThen(function (waitFor) { - var msg = me ? Messages.owner_removeMeConfirm : Messages.owner_removeConfirm; - UI.confirm(msg, waitFor(function (yes) { - if (!yes) { - waitFor.abort(); - return; - } - })); - }).nThen(function (waitFor) { - // Send the command - sframeChan.query('Q_SET_PAD_METADATA', { - channel: channel, - command: pending ? 'RM_PENDING_OWNERS' : 'RM_OWNERS', - value: toRemove, - teamId: teamOwner - }, waitFor(function (err, res) { - err = err || (res && res.error); - if (err) { - waitFor.abort(); - redrawAll(); - var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden - : Messages.error; - return void UI.warn(text); - } - UI.log(Messages.saved); - })); - }).nThen(function (waitFor) { - sel.forEach(function (el) { - var curve = $(el).attr('data-curve'); - var friend = curve === user.curvePublic ? user : friends[curve]; - if (!friend) { return; } - common.mailbox.sendTo("RM_OWNER", { - channel: channel, - title: data.title, - pending: pending - }, { - channel: friend.notifications, - curvePublic: friend.curvePublic - }, waitFor()); - }); - }).nThen(function () { - redrawAll(); - }); - }); - $div.append(h('p', removeButton)); - return $div; - }; - - // Add owners column - var drawAdd = function () { - var $div = $(h('div.cp-share-column')); - var _friends = JSON.parse(JSON.stringify(friends)); - Object.keys(_friends).forEach(function (curve) { - if (owners.indexOf(_friends[curve].edPublic) !== -1 || - pending_owners.indexOf(_friends[curve].edPublic) !== -1 || - !_friends[curve].notifications) { - delete _friends[curve]; - } - }); - var addCol = UIElements.getUserGrid(Messages.owner_addText, { - common: common, - large: true, - data: _friends - }, function () { - //console.log(arguments); - }); - $div.append(addCol.div); - - var teamsData = Util.tryParse(JSON.stringify(priv.teams)) || {}; - Object.keys(teamsData).forEach(function (id) { - var t = teamsData[id]; - t.teamId = id; - if (owners.indexOf(t.edPublic) !== -1 || pending_owners.indexOf(t.edPublic) !== -1) { - delete teamsData[id]; - } - }); - var teamsList = UIElements.getUserGrid(Messages.owner_addTeamText, { - common: common, - large: true, - noFilter: true, - data: teamsData - }, function () {}); - $div.append(teamsList.div); - - // When clicking on the add button, we get the selected users. - var addButton = h('button.no-margin', Messages.owner_addButton); - $(addButton).click(function () { - // Check selection - var $sel = $div.find('.cp-usergrid-user.cp-selected'); - var sel = $sel.toArray(); - if (!sel.length) { return; } - var toAdd = sel.map(function (el) { - var curve = $(el).attr('data-curve'); - // If the pad is woned by a team, we can transfer ownership to ourselves - if (curve === user.curvePublic && teamOwner) { return priv.edPublic; } - var friend = friends[curve]; - if (!friend) { return; } - return friend.edPublic; - }).filter(function (x) { return x; }); - var toAddTeams = sel.map(function (el) { - var team = teamsData[$(el).attr('data-teamid')]; - if (!team || !team.edPublic) { return; } - return { - edPublic: team.edPublic, - id: $(el).attr('data-teamid') - }; - }).filter(function (x) { return x; }); - - NThen(function (waitFor) { - var msg = Messages.owner_addConfirm; - UI.confirm(msg, waitFor(function (yes) { - if (!yes) { - waitFor.abort(); - return; - } - })); - }).nThen(function (waitFor) { - // Add one of our teams as an owner - if (toAddTeams.length) { - // Send the command - sframeChan.query('Q_SET_PAD_METADATA', { - channel: channel, - command: 'ADD_OWNERS', - value: toAddTeams.map(function (obj) { return obj.edPublic; }), - teamId: teamOwner - }, waitFor(function (err, res) { - err = err || (res && res.error); - if (err) { - waitFor.abort(); - redrawAll(); - var text = err === "INSUFFICIENT_PERMISSIONS" ? - Messages.fm_forbidden : Messages.error; - return void UI.warn(text); - } - var isTemplate = priv.isTemplate || data.isTemplate; - toAddTeams.forEach(function (obj) { - sframeChan.query('Q_STORE_IN_TEAM', { - href: data.href || data.rohref, - password: data.password, - path: isTemplate ? ['template'] : undefined, - title: data.title || '', - teamId: obj.id - }, waitFor(function (err) { - if (err) { return void console.error(err); } - })); - }); - })); - } - }).nThen(function (waitFor) { - // Offer ownership to a friend - if (toAdd.length) { - // Send the command - sframeChan.query('Q_SET_PAD_METADATA', { - channel: channel, - command: 'ADD_PENDING_OWNERS', - value: toAdd, - teamId: teamOwner - }, waitFor(function (err, res) { - err = err || (res && res.error); - if (err) { - waitFor.abort(); - redrawAll(); - var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden - : Messages.error; - return void UI.warn(text); - } - })); - } - }).nThen(function (waitFor) { - sel.forEach(function (el) { - var curve = $(el).attr('data-curve'); - var friend = curve === user.curvePublic ? user : friends[curve]; - if (!friend) { return; } - common.mailbox.sendTo("ADD_OWNER", { - channel: channel, - href: data.href, - password: data.password, - title: data.title - }, { - channel: friend.notifications, - curvePublic: friend.curvePublic - }, waitFor()); - }); - }).nThen(function () { - redrawAll(); - UI.log(Messages.saved); - }); - }); - $div.append(h('p', addButton)); - return $div; - }; - - redrawAll = function (md) { - var todo = function (obj) { - if (obj && obj.error) { return; } - owners = obj.owners || []; - pending_owners = obj.pending_owners || []; - $div1.empty(); - $div2.empty(); - $div1.append(drawRemove(false)).append(drawRemove(true)); - $div2.append(drawAdd()); - }; - - if (md) { return void todo(md); } - common.getPadMetadata({ - channel: data.channel - }, todo); - }; - - $div1.append(drawRemove(false)).append(drawRemove(true)); - $div2.append(drawAdd()); - - var handler = sframeChan.on('EV_RT_METADATA', function (md) { - if (!$div1.length) { - return void handler.stop(); - } - owners = md.owners || []; - pending_owners = md.pending_owners || []; - redrawAll(md); - }); - - // Create modal - var link = h('div.cp-share-columns', [ - div1, - div2 - /*drawRemove()[0], - drawAdd()[0]*/ - ]); - var linkButtons = [{ - className: 'cancel', - name: Messages.filePicker_close, - onClick: function () {}, - keys: [27] - }]; - return UI.dialog.customModal(link, {buttons: linkButtons}); - }; - - var getRightsProperties = function (common, data, cb) { - var $div = $('
'); - if (!data) { return void cb(void 0, $div); } - - var draw = function () { - var $d = $('
'); - var priv = common.getMetadataMgr().getPrivateData(); - var user = common.getMetadataMgr().getUserData(); - var edPublic = priv.edPublic; - var owned = false; - var _owners = {}; - if (data.owners && data.owners.length) { - if (data.owners.indexOf(edPublic) !== -1) { - owned = true; - } else { - Object.keys(priv.teams || {}).some(function (id) { - var team = priv.teams[id] || {}; - if (team.viewer) { return; } - if (data.owners.indexOf(team.edPublic) === -1) { return; } - owned = id; - return true; - }); - } - var strangers = 0; - data.owners.forEach(function (ed) { - // If a friend is an owner, add their name to the list - // otherwise, increment the list of strangers - - // Our edPublic? print "Yourself" - if (ed === edPublic) { - _owners[ed] = { - selected: true, - name: user.name, - avatar: user.avatar - }; - return; - } - // One of our teams? print the team name - if (Object.keys(priv.teams || {}).some(function (id) { - var team = priv.teams[id] || {}; - if (team.edPublic !== ed) { return; } - _owners[ed] = { - name: team.name, - avatar: team.avatar - }; - return true; - })) { - return; - } - // One of our friends? print the friend name - if (Object.keys(priv.friends || {}).some(function (c) { - var friend = priv.friends[c] || {}; - if (friend.edPublic !== ed || c === 'me') { return; } - _owners[friend.edPublic] = { - name: friend.displayName, - avatar: friend.avatar - }; - return true; - })) { - return; - } - // Otherwise it's a stranger - strangers++; - }); - if (strangers) { - _owners['stangers'] = { - name: Messages._getKey('properties_unknownUser', [strangers]), - }; - } - } - var _ownersGrid = UIElements.getUserGrid(Messages.creation_owners, { - common: common, - noSelect: true, - data: _owners, - large: true - }, function () {}); - if (_ownersGrid && Object.keys(_owners).length) { - $d.append(_ownersGrid.div); - } else { - $d.append([ - h('label', Messages.creation_owners), - ]); - $d.append(UI.dialog.selectable(Messages.creation_noOwner, { - id: 'cp-app-prop-owners', - })); - - } - - var parsed; - if (data.href || data.roHref) { - parsed = Hash.parsePadUrl(data.href || data.roHref); - } - if (owned && parsed.hashData.type === 'pad') { - var manageOwners = h('button.no-margin', Messages.owner_openModalButton); - $(manageOwners).click(function () { - data.teamId = typeof(owned) !== "boolean" ? owned : undefined; - var modal = createOwnerModal(common, data); - UI.openCustomModal(modal, { - wide: true, - }); - }); - $d.append(h('p', manageOwners)); - } - - if (!data.noExpiration) { - var expire = Messages.creation_expireFalse; - if (data.expire && typeof (data.expire) === "number") { - expire = new Date(data.expire).toLocaleString(); - } - $('