Transfer ownership from or to a team

pull/1/head
yflory 5 years ago
parent 98800a34cc
commit aaed0b939e

@ -104,6 +104,8 @@ define([
var channel = data.channel; var channel = data.channel;
var owners = data.owners || []; var owners = data.owners || [];
var pending_owners = data.pending_owners || []; var pending_owners = data.pending_owners || [];
var teams = priv.teams;
var teamOwner = data.teamId;
var redrawAll = function () {}; var redrawAll = function () {};
@ -124,6 +126,12 @@ define([
return true; return true;
} }
}); });
Object.keys(teams).some(function (id) {
if (teams[id].edPublic === ed) {
f = teams[id];
f.teamId = id;
}
});
if (ed === edPublic) { if (ed === edPublic) {
f = f || user; f = f || user;
if (f.name) { f.edPublic = edPublic; } if (f.name) { f.edPublic = edPublic; }
@ -155,6 +163,7 @@ define([
var toRemove = sel.map(function (el) { var toRemove = sel.map(function (el) {
var ed = $(el).attr('data-ed'); var ed = $(el).attr('data-ed');
if (!ed) { return; } if (!ed) { return; }
if (teamOwner && teams[teamOwner] && teams[teamOwner].edPublic === ed) { me = true; }
if (ed === edPublic) { me = true; } if (ed === edPublic) { me = true; }
return ed; return ed;
}).filter(function (x) { return x; }); }).filter(function (x) { return x; });
@ -171,7 +180,8 @@ define([
sframeChan.query('Q_SET_PAD_METADATA', { sframeChan.query('Q_SET_PAD_METADATA', {
channel: channel, channel: channel,
command: pending ? 'RM_PENDING_OWNERS' : 'RM_OWNERS', command: pending ? 'RM_PENDING_OWNERS' : 'RM_OWNERS',
value: toRemove value: toRemove,
teamId: teamOwner
}, waitFor(function (err, res) { }, waitFor(function (err, res) {
err = err || (res && res.error); err = err || (res && res.error);
if (err) { if (err) {
@ -214,6 +224,7 @@ define([
// Add owners column // Add owners column
var drawAdd = function () { var drawAdd = function () {
var $div = $(h('div.cp-share-column'));
var _friends = JSON.parse(JSON.stringify(friends)); var _friends = JSON.parse(JSON.stringify(friends));
Object.keys(_friends).forEach(function (curve) { Object.keys(_friends).forEach(function (curve) {
if (owners.indexOf(_friends[curve].edPublic) !== -1 || if (owners.indexOf(_friends[curve].edPublic) !== -1 ||
@ -228,16 +239,44 @@ define([
}, function () { }, function () {
//console.log(arguments); //console.log(arguments);
}); });
$div2 = $(addCol.div); $div.append(addCol.div);
if (priv.enableTeams) {
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('Or a team?', { // XXX
common: common,
noFilter: true,
data: teamsData
}, function () {});
$div.append(teamsList.div);
}
// When clicking on the add button, we get the selected users. // When clicking on the add button, we get the selected users.
var addButton = h('button.no-margin', Messages.owner_addButton); var addButton = h('button.no-margin', Messages.owner_addButton);
$(addButton).click(function () { $(addButton).click(function () {
// Check selection // Check selection
var $sel = $div2.find('.cp-usergrid-user.cp-selected'); var $sel = $div.find('.cp-usergrid-user.cp-selected');
var sel = $sel.toArray(); var sel = $sel.toArray();
if (!sel.length) { return; } if (!sel.length) { return; }
var toAdd = sel.map(function (el) { var toAdd = sel.map(function (el) {
return friends[$(el).attr('data-curve')].edPublic; var friend = friends[$(el).attr('data-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; }); }).filter(function (x) { return x; });
NThen(function (waitFor) { NThen(function (waitFor) {
@ -249,21 +288,57 @@ define([
} }
})); }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
// Send the command if (toAddTeams.length) {
sframeChan.query('Q_SET_PAD_METADATA', { // Send the command
channel: channel, sframeChan.query('Q_SET_PAD_METADATA', {
command: 'ADD_PENDING_OWNERS', channel: channel,
value: toAdd command: 'ADD_OWNERS',
}, waitFor(function (err, res) { value: toAddTeams.map(function (obj) { return obj.edPublic; }),
err = err || (res && res.error); teamId: teamOwner
if (err) { }, waitFor(function (err, res) {
waitFor.abort(); err = err || (res && res.error);
redrawAll(); if (err) {
var text = err === "INSUFFICIENT_PERMISSIONS" ? Messages.fm_forbidden waitFor.abort();
: Messages.error; redrawAll();
return void UI.warn(text); var text = err === "INSUFFICIENT_PERMISSIONS" ?
} Messages.fm_forbidden : Messages.error;
})); return void UI.warn(text);
}
// XXX add the pad to the team drive
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); }
console.warn(obj.id);
}));
});
}));
}
}).nThen(function (waitFor) {
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) { }).nThen(function (waitFor) {
sel.forEach(function (el) { sel.forEach(function (el) {
var friend = friends[$(el).attr('data-curve')]; var friend = friends[$(el).attr('data-curve')];
@ -291,8 +366,8 @@ define([
UI.log(Messages.saved); UI.log(Messages.saved);
}); });
}); });
$div2.append(h('p', addButton)); $div.append(h('p', addButton));
return $div2; return $div;
}; };
redrawAll = function (md) { redrawAll = function (md) {
@ -434,6 +509,7 @@ define([
if (owned && data.roHref && parsed.type !== 'drive' && parsed.hashData.type === 'pad') { if (owned && data.roHref && parsed.type !== 'drive' && parsed.hashData.type === 'pad') {
var manageOwners = h('button.no-margin', Messages.owner_openModalButton); var manageOwners = h('button.no-margin', Messages.owner_openModalButton);
$(manageOwners).click(function () { $(manageOwners).click(function () {
data.teamId = typeof(owned) !== "boolean" ? owned : undefined;
var modal = createOwnerModal(common, data); var modal = createOwnerModal(common, data);
UI.openCustomModal(modal, { UI.openCustomModal(modal, {
wide: true, wide: true,
@ -665,6 +741,7 @@ define([
UIElements.displayAvatar(common, $(avatar), data.avatar, name); UIElements.displayAvatar(common, $(avatar), data.avatar, name);
return h('div.cp-usergrid-user'+(data.selected?'.cp-selected':'')+(config.large?'.large':''), { return h('div.cp-usergrid-user'+(data.selected?'.cp-selected':'')+(config.large?'.large':''), {
'data-ed': data.edPublic, 'data-ed': data.edPublic,
'data-teamid': data.teamId,
'data-curve': data.curvePublic || '', 'data-curve': data.curvePublic || '',
'data-name': name.toLowerCase(), 'data-name': name.toLowerCase(),
'data-order': i, 'data-order': i,

@ -3729,6 +3729,10 @@ define([
data.roHref = base + data.roHref; data.roHref = base + data.roHref;
} }
if (currentPath[0] === TEMPLATE) {
data.isTemplate = true;
}
if (manager.isSharedFolder(el)) { if (manager.isSharedFolder(el)) {
delete data.roHref; delete data.roHref;
//data.noPassword = true; //data.noPassword = true;

@ -1552,7 +1552,6 @@ define([
var href, title; var href, title;
// XXX TEAMOWNER
if (!res.some(function (obj) { if (!res.some(function (obj) {
if (obj.data && if (obj.data &&
Array.isArray(obj.data.owners) && obj.data.owners.indexOf(edPublic) !== -1 && Array.isArray(obj.data.owners) && obj.data.owners.indexOf(edPublic) !== -1 &&
@ -1612,11 +1611,8 @@ define([
Store.setPadMetadata = function (clientId, data, cb) { Store.setPadMetadata = function (clientId, data, cb) {
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); } if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
if (!data.command) { return void cb({ error: 'EINVAL' }); } if (!data.command) { return void cb({ error: 'EINVAL' }); }
// XXX TEAMOWNER var s = getStore(data.teamId);
// If owned by a team, we should use the team rpc here s.rpc.setMetadata(data, function (err, res) {
// We'll need common-ui-elements to tell us the "owners" value or we can
// call getPadMetadata first
store.rpc.setMetadata(data, function (err, res) {
if (err) { return void cb({ error: err }); } if (err) { return void cb({ error: err }); }
if (!Array.isArray(res) || !res.length) { return void cb({}); } if (!Array.isArray(res) || !res.length) { return void cb({}); }
cb(res[0]); cb(res[0]);

Loading…
Cancel
Save