Merge pull request #1410 from sharmapankaj2512/MIFOSX-1935

MIFOSX-1935: role with no active user attached will get deleted
This commit is contained in:
Vishwas Babu A J
2015-06-16 07:22:12 -07:00
4 changed files with 80 additions and 2 deletions
@@ -296,6 +296,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
this.accountNonExpired = false;
this.firstTimeLoginRemaining = true;
this.username = getId() + "_DELETED_" + this.username;
this.roles.clear();
}
public boolean isDeleted() {
@@ -11,8 +11,8 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {
@Query("SELECT COUNT(*) FROM AppUser a JOIN a.roles r WHERE r.id = :roleId")
@Query("SELECT COUNT(*) FROM AppUser a JOIN a.roles r WHERE r.id = :roleId AND a.deleted = false")
Integer getCountOfRolesAssociatedWithUsers(@Param("roleId") Long roleId);
}