Skip to content

Commit

Permalink
quickfix: allowing de-assign from a role, even if no invite found
Browse files Browse the repository at this point in the history
  • Loading branch information
nbiton committed Jun 3, 2019
1 parent 3dfd7a6 commit c9d0458
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions imports/api/unit-roles-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export function removeRoleMember (requestorId, unitBzId, email, errorLogParams)

const requestorUser = Meteor.users.findOne({ _id: requestorId })

const { invitationId } = userToRemove.receivedInvites.find(i => i.unitId === unitBzId)
let invitationId
const receivedInvite = userToRemove.receivedInvites.find(i => i.unitId === unitBzId)
if (receivedInvite) {
invitationId = receivedInvite.invitationId
}

const invitationObj = {
invitedBy: requestorUser.bugzillaCreds.id,
Expand Down Expand Up @@ -116,17 +120,19 @@ export function removeRoleMember (requestorId, unitBzId, email, errorLogParams)
throw new Meteor.Error('Invite API Lambda error', e)
}

// Removing the user's received invite
Meteor.users.update({ _id: userToRemove._id }, {
$pull: {
receivedInvites: {
invitationId: invitationId
if (invitationId) {
// Removing the user's received invite
Meteor.users.update({ _id: userToRemove._id }, {
$pull: {
receivedInvites: {
invitationId: invitationId
}
}
}
})
})

// Removing the invitation document
PendingInvitations.remove({ _id: invitationId })
// Removing the invitation document
PendingInvitations.remove({ _id: invitationId })
}

// Removing the user from the unit's owners list if it was included
if (unitMeta.ownerIds.includes(userToRemove._id)) {
Expand Down

0 comments on commit c9d0458

Please sign in to comment.