Fix team pending owner issues

pull/1/head
yflory 4 years ago
parent 5282603559
commit bca1c08653

@ -986,8 +986,20 @@ define([
var state = team.roster.getState() || {}; var state = team.roster.getState() || {};
var members = state.members || {}; var members = state.members || {};
var md;
nThen(function (waitFor) {
// Get pending owners // Get pending owners
var md = team.listmap.metadata || {}; ctx.Store.getPadMetadata(null, {
channel: teamData.channel
}, waitFor(function (obj) {
if (obj && obj.error) {
md = team.listmap.metadata || {};
return;
}
md = obj;
}));
}).nThen(function () {
ctx.pending_owners = md.pending_owners;
if (Array.isArray(md.pending_owners)) { if (Array.isArray(md.pending_owners)) {
// Get the members associated to the pending_owners' edPublic and mark them as such // Get the members associated to the pending_owners' edPublic and mark them as such
md.pending_owners.forEach(function (ed) { md.pending_owners.forEach(function (ed) {
@ -1027,6 +1039,7 @@ define([
} }
cb(members); cb(members);
});
}; };
// Return folders with edit rights available to everybody (decrypted pad href) // Return folders with edit rights available to everybody (decrypted pad href)
@ -1144,8 +1157,7 @@ define([
if (!teamData) { return void cb ({error: 'ENOENT'}); } if (!teamData) { return void cb ({error: 'ENOENT'}); }
var team = ctx.teams[teamId]; var team = ctx.teams[teamId];
if (!team) { return void cb ({error: 'ENOENT'}); } if (!team) { return void cb ({error: 'ENOENT'}); }
var md = team.listmap.metadata || {}; var isPendingOwner = user.pendingOwner;
var isPendingOwner = (md.pending_owners || []).indexOf(user.edPublic) !== -1;
nThen(function (waitFor) { nThen(function (waitFor) {
var cmd = isPendingOwner ? 'RM_PENDING_OWNERS' : 'RM_OWNERS'; var cmd = isPendingOwner ? 'RM_PENDING_OWNERS' : 'RM_OWNERS';
@ -1364,13 +1376,30 @@ define([
var describeUser = function (ctx, data, cId, cb) { var describeUser = function (ctx, data, cId, cb) {
var teamId = data.teamId; var teamId = data.teamId;
if (!teamId) { return void cb({error: 'EINVAL'}); } if (!teamId) { return void cb({error: 'EINVAL'}); }
var teamData = Util.find(ctx, ['store', 'proxy', 'teams', teamId]);
var team = ctx.teams[teamId]; var team = ctx.teams[teamId];
if (!team) { return void cb ({error: 'ENOENT'}); } if (!teamData || !team) { return void cb ({error: 'ENOENT'}); }
if (!team.roster) { return void cb({error: 'NO_ROSTER'}); } if (!team.roster) { return void cb({error: 'NO_ROSTER'}); }
if (!data.curvePublic || !data.data) { return void cb({error: 'MISSING_DATA'}); } if (!data.curvePublic || !data.data) { return void cb({error: 'MISSING_DATA'}); }
var state = team.roster.getState(); var state = team.roster.getState();
var user = state.members[data.curvePublic]; var user = state.members[data.curvePublic];
var md;
nThen(function (waitFor) {
// Get pending owners
ctx.Store.getPadMetadata(null, {
channel: teamData.channel
}, waitFor(function (obj) {
if (obj && obj.error) {
md = team.listmap.metadata || {};
return;
}
md = obj;
}));
}).nThen(function () {
user.pendingOwner = Array.isArray(md.pending_owners) &&
md.pending_owners.indexOf(user.edPublic) !== -1;
// It it is an ownership revocation, we have to set it in pad metadata first // It it is an ownership revocation, we have to set it in pad metadata first
if (user.role === "OWNER" && data.data.role !== "OWNER") { if (user.role === "OWNER" && data.data.role !== "OWNER") {
revokeOwnership(ctx, teamId, user, function (err) { revokeOwnership(ctx, teamId, user, function (err) {
@ -1401,6 +1430,7 @@ define([
if (err) { return void cb({error: err}); } if (err) { return void cb({error: err}); }
cb(); cb();
}); });
});
}; };
var inviteToTeam = function (ctx, data, cId, cb) { var inviteToTeam = function (ctx, data, cId, cb) {

@ -768,7 +768,7 @@ define([
$(demote).hide(); $(demote).hide();
describeUser(common, data.curvePublic, { describeUser(common, data.curvePublic, {
role: role role: role
}, promote); }, demote);
}; };
if (isMe) { if (isMe) {
return void UI.confirm(Messages.team_demoteMeConfirm, function (yes) { return void UI.confirm(Messages.team_demoteMeConfirm, function (yes) {
@ -901,9 +901,12 @@ define([
$header.append(invite); $header.append(invite);
} }
if (me && (me.role !== 'OWNER')) {
var leave = h('button.cp-online.btn.btn-danger', Messages.team_leaveButton); var leave = h('button.cp-online.btn.btn-danger', Messages.team_leaveButton);
$(leave).click(function () { $(leave).click(function () {
if (me && me.role === 'OWNER') {
Messages.team_leaveOwner = "Owners can't leave the team. You can demote yourself if there is at least one other owner."; // XXX
return void UI.alert(Messages.team_leaveOwner);
}
UI.confirm(Messages.team_leaveConfirm, function (yes) { UI.confirm(Messages.team_leaveConfirm, function (yes) {
if (!yes) { return; } if (!yes) { return; }
APP.module.execCommand('LEAVE_TEAM', { APP.module.execCommand('LEAVE_TEAM', {
@ -916,7 +919,6 @@ define([
}); });
}); });
$header.append(leave); $header.append(leave);
}
var table = h('button.btn.btn-primary', Messages.teams_table); var table = h('button.btn.btn-primary', Messages.teams_table);
$(table).click(function (e) { $(table).click(function (e) {

Loading…
Cancel
Save