From 3d9790c31942cc860a0f708a251abb2b4d6fb9f9 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 15 Feb 2012 10:34:48 -0800 Subject: [PATCH] bug 13742: check only for Pending invitations while inviting the same account to the project again status 13742: resolved fixed Reviewed-by: Frank --- .../cloud/projects/ProjectManagerImpl.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index 7ddcadb5c72..c4eebf2e1db 100755 --- a/server/src/com/cloud/projects/ProjectManagerImpl.java +++ b/server/src/com/cloud/projects/ProjectManagerImpl.java @@ -444,10 +444,27 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ return _projectAccountDao.persist(new ProjectAccountVO(project, accountId, accountRole)); } - @Override + @Override @DB public boolean deleteAccountFromProject(long projectId, long accountId) { + boolean success = true; + Transaction txn = Transaction.currentTxn(); + txn.start(); + + //remove account ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId); - return _projectAccountDao.remove(projectAccount.getId()); + success = _projectAccountDao.remove(projectAccount.getId()); + + //remove all invitations for account + if (success) { + s_logger.debug("Removed account " + accountId + " from project " + projectId + " , cleaning up old invitations for account/project..."); + ProjectInvitation invite = _projectInvitationDao.findByAccountIdProjectId(accountId, projectId); + if (invite != null) { + success = success && _projectInvitationDao.remove(invite.getId()); + } + } + + txn.commit(); + return success; } @Override @@ -730,7 +747,8 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ } if (invite != null) { - if (invite.getState() == ProjectInvitation.State.Completed || _projectInvitationDao.isActive(invite.getId(), _invitationTimeOut)) { + if (invite.getState() == ProjectInvitation.State.Completed || + (invite.getState() == ProjectInvitation.State.Pending && _projectInvitationDao.isActive(invite.getId(), _invitationTimeOut))) { return true; } else { if (invite.getState() == ProjectInvitation.State.Pending) {