use of org.bimserver.models.log.UserRemovedFromProject in project BIMserver by opensourceBIM.
the class RemoveUserFromProjectDatabaseAction method execute.
@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
User user = getUserByUoid(uoid);
Project project = getProjectByPoid(poid);
User actingUser = getUserByUoid(authorization.getUoid());
if (authorization.hasRightsOnProject(actingUser, project)) {
if (user.getUserType() == UserType.ADMIN) {
int nrAdmins = 0;
for (User authUser : project.getHasAuthorizedUsers()) {
if (authUser.getUserType() == UserType.ADMIN) {
nrAdmins++;
}
}
if (nrAdmins == 1) {
throw new UserException("User cannot be removed from this project because it is the only admin user with authorization on this project");
}
}
project.getHasAuthorizedUsers().remove(user);
user.getHasRightsOn().remove(project);
final UserRemovedFromProject userRemovedFromProject = getDatabaseSession().create(UserRemovedFromProject.class);
userRemovedFromProject.setDate(new Date());
userRemovedFromProject.setExecutor(actingUser);
userRemovedFromProject.setAccessMethod(getAccessMethod());
userRemovedFromProject.setProject(project);
userRemovedFromProject.setUser(user);
getDatabaseSession().addPostCommitAction(new PostCommitAction() {
@Override
public void execute() throws UserException {
bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userRemovedFromProject));
}
});
getDatabaseSession().store(user);
getDatabaseSession().store(project);
return true;
} else {
throw new UserException("Insufficient rights to remove user from project");
}
}
Aggregations