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 members = state.members || {};
var md;
nThen(function (waitFor) {
// 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)) {
// Get the members associated to the pending_owners' edPublic and mark them as such
md.pending_owners.forEach(function (ed) {
@ -1027,6 +1039,7 @@ define([
}
cb(members);
});
};
// Return folders with edit rights available to everybody (decrypted pad href)
@ -1144,8 +1157,7 @@ define([
if (!teamData) { return void cb ({error: 'ENOENT'}); }
var team = ctx.teams[teamId];
if (!team) { return void cb ({error: 'ENOENT'}); }
var md = team.listmap.metadata || {};
var isPendingOwner = (md.pending_owners || []).indexOf(user.edPublic) !== -1;
var isPendingOwner = user.pendingOwner;
nThen(function (waitFor) {
var cmd = isPendingOwner ? 'RM_PENDING_OWNERS' : 'RM_OWNERS';
@ -1364,13 +1376,30 @@ define([
var describeUser = function (ctx, data, cId, cb) {
var teamId = data.teamId;
if (!teamId) { return void cb({error: 'EINVAL'}); }
var teamData = Util.find(ctx, ['store', 'proxy', '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 (!data.curvePublic || !data.data) { return void cb({error: 'MISSING_DATA'}); }
var state = team.roster.getState();
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
if (user.role === "OWNER" && data.data.role !== "OWNER") {
revokeOwnership(ctx, teamId, user, function (err) {
@ -1401,6 +1430,7 @@ define([
if (err) { return void cb({error: err}); }
cb();
});
});
};
var inviteToTeam = function (ctx, data, cId, cb) {

@ -768,7 +768,7 @@ define([
$(demote).hide();
describeUser(common, data.curvePublic, {
role: role
}, promote);
}, demote);
};
if (isMe) {
return void UI.confirm(Messages.team_demoteMeConfirm, function (yes) {
@ -901,9 +901,12 @@ define([
$header.append(invite);
}
if (me && (me.role !== 'OWNER')) {
var leave = h('button.cp-online.btn.btn-danger', Messages.team_leaveButton);
$(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) {
if (!yes) { return; }
APP.module.execCommand('LEAVE_TEAM', {
@ -916,7 +919,6 @@ define([
});
});
$header.append(leave);
}
var table = h('button.btn.btn-primary', Messages.teams_table);
$(table).click(function (e) {

Loading…
Cancel
Save