Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {

void removeAccountFromProjects(long accountId);

void removeUserFromProjects(long userId);
int removeByProjectIdAccountId(long projectId, long accountId);

boolean canUserModifyProject(long projectId, long accountId, long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ public void removeAccountFromProjects(long accountId) {
}

@Override
public void removeUserFromProjects(long userId) {
public int removeByProjectIdAccountId(long projectId, long accountId) {
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
sc.setParameters("userId", userId);
sc.setParameters("projectId", projectId);
sc.setParameters("accountId", accountId);

int removedCount = remove(sc);
if (removedCount > 0) {
logger.debug(String.format("Removed user [%s] from %s project(s).", userId, removedCount));
int rowsRemoved = remove(sc);
if (rowsRemoved > 0) {
logger.debug("Removed {} mappings of account id={} from project id={}", rowsRemoved, accountId, projectId);
}
return rowsRemoved;
}

@Override
Expand Down
13 changes: 3 additions & 10 deletions server/src/main/java/com/cloud/projects/ProjectManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,11 @@ public Boolean doInTransaction(TransactionStatus status) {

@Override
public boolean unassignAccountFromProject(long projectId, long accountId) {
ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId);
if (projectAccount == null) {
int removed = _projectAccountDao.removeByProjectIdAccountId(projectId, accountId);
if (removed == 0) {
logger.debug("Account id=" + accountId + " is not assigned to project id=" + projectId + " so no need to unassign");
return true;
}

if (_projectAccountDao.remove(projectAccount.getId())) {
return true;
} else {
logger.warn("Failed to unassign account id=" + accountId + " from the project id=" + projectId);
return false;
}
return true;
}

@Override
Expand Down
Loading