From b04d8c08212b77028a3f0613512729f26a4a1f23 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 28 Oct 2019 17:05:11 +0100 Subject: [PATCH] Add permissions table --- www/common/outer/team.js | 22 +++++++++++++++++ www/teams/app-team.less | 25 +++++++++++++++++++ www/teams/inner.js | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 6ff59d66e..ada4361c5 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -798,6 +798,25 @@ define([ cb(members); }; + // Return folders with edit rights available to everybody (decrypted pad href) + var getEditableFolders = function (ctx, data, cId, cb) { + var teamId = data.teamId; + if (!teamId) { return void cb({error: 'EINVAL'}); } + var team = ctx.teams[teamId]; + if (!team) { return void cb ({error: 'ENOENT'}); } + var folders = team.manager.folders || {}; + var ids = Object.keys(folders).filter(function (id) { + return !folders[id].proxy.version; + }); + cb(ids.map(function (id) { + var uo = Util.find(team, ['user', 'userObject']); + return { + name: Util.find(folders, [id, 'proxy', 'metadata', 'title']), + path: uo ? uo.findFile(id)[0] : [] + }; + })); + }; + var getTeamMetadata = function (ctx, data, cId, cb) { var teamId = data.teamId; if (!teamId) { return void cb({error: 'EINVAL'}); } @@ -1379,6 +1398,9 @@ define([ if (cmd === 'CREATE_TEAM') { return void createTeam(ctx, data, clientId, cb); } + if (cmd === 'GET_EDITABLE_FOLDERS') { + return void getEditableFolders(ctx, data, clientId, cb); + } }; return team; diff --git a/www/teams/app-team.less b/www/teams/app-team.less index 863aec1a9..fefdbb59f 100644 --- a/www/teams/app-team.less +++ b/www/teams/app-team.less @@ -138,6 +138,11 @@ } .cp-team-roster { .avatar_main(50px); + .cp-app-team-roster-header { + button:not(:last-child) { + margin-right: 5px; + } + } .cp-team-roster-member { display: flex; align-items: center; @@ -184,5 +189,25 @@ } } } + + #cp-teams-roster-dialog { + table { + width: 100%; + table-layout: fixed; + &.cp-teams-generic { + margin-bottom: 30px; + } + } + p { + text-align: left; + } + ul { + text-align: left; + padding-left: 30px; + } + li { + font-weight: bold; + } + } } diff --git a/www/teams/inner.js b/www/teams/inner.js index 6a0f87c48..013d3592e 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -727,6 +727,58 @@ define([ $header.append(leave); } + var table = h('button.btn.btn-primary', Messages.teams_table); + $(table).click(function (e) { + e.stopPropagation(); + var $blockContainer = UIElements.createModal({ + id: 'cp-teams-roster-dialog', + }).show(); + + var makeRow = function (arr, first) { + return arr.map(function (val) { + return h(first ? 'th' : 'td', val); + }); + }; + // Global rights + var rows = []; + var firstRow = ['', Messages.share_linkView, Messages.share_linkEdit, + Messages.teams_table_admins, Messages.teams_table_owners]; + rows.push(h('tr', makeRow(firstRow, true))); + rows.push(h('tr', makeRow([Messages.team_viewers, 'x', '', '', '']))); + rows.push(h('tr', makeRow([Messages.team_members, 'x', 'x', '', '']))); + rows.push(h('tr', makeRow([Messages.team_admins, 'x', 'x', 'x', '']))); + rows.push(h('tr', makeRow([Messages.team_owner, 'x', 'x', 'x', 'x']))); + var t = h('table.cp-teams-generic', rows); + + var content = [ + h('h4', Messages.teams_table_generic), + h('p', Messages.teams_table_genericHint), + t + ]; + + APP.module.execCommand('GET_EDITABLE_FOLDERS', { + teamId: APP.team + }, function (arr) { + console.log(arr); + if (!Array.isArray(arr) || !arr.length) { + return void $blockContainer.find('.cp-modal').append(content); + } + content.push(h('h4', Messages.teams_table_specific)); + content.push(h('p', Messages.teams_table_specificHint)); + var paths = arr.map(function (obj) { + obj.path.push(obj.name); + return h('li', obj.path.join('/')); + }); + content.push(h('ul', paths)); + var rows = []; + rows.push(h('tr', makeRow(firstRow, true))); + rows.push(h('tr', makeRow([Messages.team_viewers, 'x', 'x', '', '']))); + content.push(h('table', rows)); + $blockContainer.find('.cp-modal').append(content); + }); + }); + $header.append(table); + var noPending = pending.length ? '' : '.cp-hidden'; return [