Fix team pending owner issues

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

@ -986,47 +986,60 @@ define([
var state = team.roster.getState() || {}; var state = team.roster.getState() || {};
var members = state.members || {}; var members = state.members || {};
// Get pending owners var md;
var md = team.listmap.metadata || {}; nThen(function (waitFor) {
if (Array.isArray(md.pending_owners)) { // Get pending owners
// Get the members associated to the pending_owners' edPublic and mark them as such ctx.Store.getPadMetadata(null, {
md.pending_owners.forEach(function (ed) { channel: teamData.channel
var member; }, waitFor(function (obj) {
Object.keys(members).some(function (curve) { if (obj && obj.error) {
if (members[curve].edPublic === ed) { md = team.listmap.metadata || {};
member = members[curve];
return true;
}
});
if (!member && teamData.owner) {
var removeOwnership = function (chan) {
ctx.Store.setPadMetadata(null, {
channel: chan,
command: 'RM_PENDING_OWNERS',
value: [ed],
}, function () {});
};
removeOwnership(teamData.channel);
removeOwnership(Util.find(teamData, ['keys', 'roster', 'channel']));
removeOwnership(Util.find(teamData, ['keys', 'chat', 'channel']));
return; return;
} }
member.pendingOwner = true; 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) {
var member;
Object.keys(members).some(function (curve) {
if (members[curve].edPublic === ed) {
member = members[curve];
return true;
}
});
if (!member && teamData.owner) {
var removeOwnership = function (chan) {
ctx.Store.setPadMetadata(null, {
channel: chan,
command: 'RM_PENDING_OWNERS',
value: [ed],
}, function () {});
};
removeOwnership(teamData.channel);
removeOwnership(Util.find(teamData, ['keys', 'roster', 'channel']));
removeOwnership(Util.find(teamData, ['keys', 'chat', 'channel']));
return;
}
member.pendingOwner = true;
});
}
// Add online status (using messenger data) // Add online status (using messenger data)
if (ctx.store.messenger) { if (ctx.store.messenger) {
var chatData = team.getChatData(); var chatData = team.getChatData();
var online = ctx.store.messenger.getOnlineList(chatData.channel) || []; var online = ctx.store.messenger.getOnlineList(chatData.channel) || [];
online.forEach(function (curve) { online.forEach(function (curve) {
if (members[curve]) { if (members[curve]) {
members[curve].online = true; members[curve].online = true;
} }
}); });
} }
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,42 +1376,60 @@ 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];
// It it is an ownership revocation, we have to set it in pad metadata first var md;
if (user.role === "OWNER" && data.data.role !== "OWNER") { nThen(function (waitFor) {
revokeOwnership(ctx, teamId, user, function (err) { // Get pending owners
if (!err) { return void cb(); } ctx.Store.getPadMetadata(null, {
console.error(err); channel: teamData.channel
return void cb({error: err}); }, waitFor(function (obj) {
}); if (obj && obj.error) {
return; md = team.listmap.metadata || {};
} return;
}
md = obj;
}));
}).nThen(function () {
user.pendingOwner = Array.isArray(md.pending_owners) &&
md.pending_owners.indexOf(user.edPublic) !== -1;
// Viewer to editor // It it is an ownership revocation, we have to set it in pad metadata first
if (user.role === "VIEWER" && data.data.role !== "VIEWER") { if (user.role === "OWNER" && data.data.role !== "OWNER") {
changeEditRights(ctx, teamId, user, true, function (obj) { revokeOwnership(ctx, teamId, user, function (err) {
return void cb(obj); if (!err) { return void cb(); }
}); console.error(err);
} return void cb({error: err});
});
return;
}
// Editor to viewer // Viewer to editor
if (user.role !== "VIEWER" && data.data.role === "VIEWER") { if (user.role === "VIEWER" && data.data.role !== "VIEWER") {
changeEditRights(ctx, teamId, user, false, function (obj) { changeEditRights(ctx, teamId, user, true, function (obj) {
return void cb(obj); return void cb(obj);
}); });
} }
var obj = {}; // Editor to viewer
obj[data.curvePublic] = data.data; if (user.role !== "VIEWER" && data.data.role === "VIEWER") {
team.roster.describe(obj, function (err) { changeEditRights(ctx, teamId, user, false, function (obj) {
if (err) { return void cb({error: err}); } return void cb(obj);
cb(); });
}
var obj = {};
obj[data.curvePublic] = data.data;
team.roster.describe(obj, function (err) {
if (err) { return void cb({error: err}); }
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,22 +901,24 @@ 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') {
UI.confirm(Messages.team_leaveConfirm, function (yes) { Messages.team_leaveOwner = "Owners can't leave the team. You can demote yourself if there is at least one other owner."; // XXX
if (!yes) { return; } return void UI.alert(Messages.team_leaveOwner);
APP.module.execCommand('LEAVE_TEAM', { }
teamId: APP.team UI.confirm(Messages.team_leaveConfirm, function (yes) {
}, function (obj) { if (!yes) { return; }
if (obj && obj.error) { APP.module.execCommand('LEAVE_TEAM', {
return void UI.warn(Messages.error); teamId: APP.team
} }, function (obj) {
}); if (obj && obj.error) {
return void UI.warn(Messages.error);
}
}); });
}); });
$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