From 09b229203c6cc3c807cde5c5bbe63ac8c0ed01fa Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 7 Apr 2021 17:51:58 +0200 Subject: [PATCH] Access modal for calendars --- www/calendar/app-calendar.less | 3 +++ www/calendar/inner.js | 36 ++++++++++++++++++++++++++++++-- www/common/common-ui-elements.js | 36 ++++++++++++++++++++++---------- www/common/inner/access.js | 5 +++-- 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/www/calendar/app-calendar.less b/www/calendar/app-calendar.less index 69be43ab6..ce3487eb2 100644 --- a/www/calendar/app-calendar.less +++ b/www/calendar/app-calendar.less @@ -133,6 +133,9 @@ &:hover { background: fade(@cryptpad_text_col, 10%); } + &.cp-restricted { + color: @cp_drive-header-fg; + } &.cp-active { background: @cp_sidebar-left-active; } diff --git a/www/calendar/inner.js b/www/calendar/inner.js index 6a006ec95..d4aa9ffb6 100644 --- a/www/calendar/inner.js +++ b/www/calendar/inner.js @@ -390,6 +390,36 @@ Messages.calendar_import = "Import to my calendars"; return true; } }); + options.push({ + tag: 'a', + attributes: { + 'class': 'fa fa-lock', + }, + content: h('span', Messages.accessButton), + action: function (e) { + e.stopPropagation(); + var friends = common.getFriends(); + var cal = APP.calendars[id]; + var title = Util.find(cal, ['content', 'metadata', 'title']); + var color = Util.find(cal, ['content', 'metadata', 'color']); + var h = cal.hashes || {}; + var href = Hash.hashToHref(h.editHash || h.viewHash, 'calendar'); + Access.getAccessModal(common, { + title: title, + password: cal.password, // XXX support passwords + calendar: { + title: title, + color: color, + channel: id, + }, + common: common, + noExpiration: true, + channel: id, + href: href + }); + return true; + } + }); } if (!cantRemove) { options.push({ @@ -443,14 +473,16 @@ Messages.calendar_import = "Import to my calendars"; var md = Util.find(data, ['content', 'metadata']); if (!md) { return; } var active = data.hidden ? '' : '.cp-active'; - var calendar = h('div.cp-calendar-entry'+active, { + var restricted = data.restricted ? '.cp-restricted' : ''; + var calendar = h('div.cp-calendar-entry'+active+restricted, { 'data-uid': id }, [ h('span.cp-calendar-color', { style: 'background-color: '+md.color+';' }), h('span.cp-calendar-title', md.title), - isReadOnly(id, teamId) ? h('i.fa.fa-eye', {title: Messages.readonly}) : undefined, + data.restricted ? h('i.fa.fa-ban', {title: Messages.fm_restricted}) : + (isReadOnly(id, teamId) ? h('i.fa.fa-eye', {title: Messages.readonly}) : undefined), edit ]); $(calendar).click(function () { diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 6c6c51c26..680e5425a 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2921,7 +2921,7 @@ define([ var dismiss = function () { common.mailbox.dismiss(data, function (err) { - console.log(err); + if (err) { console.log(err); } }); }; var answer = function (yes) { @@ -2930,6 +2930,7 @@ define([ href: msg.content.href, password: msg.content.password, title: msg.content.title, + calendar: msg.content.calendar, answer: yes }, { channel: msg.content.user.notifications, @@ -2965,16 +2966,29 @@ define([ // Add the pad to your drive // This command will also add your mailbox to the metadata log // The callback is called when the pad is stored, independantly of the metadata command - sframeChan.query('Q_ACCEPT_OWNERSHIP', data, function (err, res) { - if (err || (res && res.error)) { - return void console.error(err | res.error); - } - UI.log(Messages.saved); - if (autoStoreModal[data.channel]) { - autoStoreModal[data.channel].delete(); - delete autoStoreModal[data.channel]; - } - }); + if (data.calendar) { + var calendarModule = common.makeUniversal('calendar'); + var calendarData = data.calendar; + calendarData.href = data.href; + calendarData.teamId = 1; + calendarModule.execCommand('ADD', calendarData, function (obj) { + if (obj && obj.error) { + console.error(obj.error); + return void UI.warn(Messages.error); + } + }); + } else { + sframeChan.query('Q_ACCEPT_OWNERSHIP', data, function (err, res) { + if (err || (res && res.error)) { + return void console.error(err | res.error); + } + UI.log(Messages.saved); + if (autoStoreModal[data.channel]) { + autoStoreModal[data.channel].delete(); + delete autoStoreModal[data.channel]; + } + }); + } // Remove yourself from the pending owners sframeChan.query('Q_SET_PAD_METADATA', { diff --git a/www/common/inner/access.js b/www/common/inner/access.js index cb3fc57c9..2c4df6508 100644 --- a/www/common/inner/access.js +++ b/www/common/inner/access.js @@ -336,6 +336,7 @@ define([ common.mailbox.sendTo("ADD_OWNER", { channel: channel, href: href, + calendar: opts.calendar, password: data.password || priv.password, title: data.title || title }, { @@ -1016,7 +1017,7 @@ define([ var owned = Modal.isOwned(Env, data); // Request edit access - if (common.isLoggedIn() && ((data.roHref && !data.href) || data.fakeHref) && !owned) { + if (common.isLoggedIn() && ((data.roHref && !data.href) || data.fakeHref) && !owned && !opts.calendar) { var requestButton = h('button.btn.btn-secondary.no-margin.cp-access-margin-right', Messages.requestEdit_button); var requestBlock = h('p', requestButton); @@ -1054,7 +1055,7 @@ define([ var canMute = data.mailbox && owned === true && ( (typeof (data.mailbox) === "string" && data.owners[0] === edPublic) || data.mailbox[edPublic]); - if (owned === true) { + if (owned === true && !opts.calendar) { var cbox = UI.createCheckbox('cp-access-mute', Messages.access_muteRequests, !canMute); var $cbox = $(cbox); var spinner = UI.makeSpinner($cbox);