Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
c63abbdf3e
8 changed files with 53 additions and 29 deletions
|
@ -120,15 +120,16 @@ module.controller('UserListCtrl', function($scope, realm, User) {
|
|||
$scope.realm = realm;
|
||||
$scope.searchQuery = function() {
|
||||
$scope.searchLoaded = false;
|
||||
$scope.currentSearch = $scope.search;
|
||||
|
||||
var params = { realm: realm.id };
|
||||
if ($scope.search) {
|
||||
$scope.currentSearch = $scope.search;
|
||||
$scope.users = User.query({ realm: realm.id, search : $scope.search }, function() {
|
||||
$scope.searchLoaded = true;
|
||||
});
|
||||
} else {
|
||||
$scope.currentSearch = null;
|
||||
$scope.users = null;
|
||||
params.search = $scope.search;
|
||||
}
|
||||
|
||||
$scope.users = User.query(params, function() {
|
||||
$scope.searchLoaded = true;
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<tr>
|
||||
<th class="rcue-table-actions" colspan="3">
|
||||
<div class="search-comp clearfix">
|
||||
<input type="text" placeholder="Search..." class="search"
|
||||
<input type="text" placeholder="Search..." class="search" data-ng-model="search.name"
|
||||
onkeyup="if(event.keyCode == 13){$(this).next('button').click();}">
|
||||
<button class="icon-search" tooltip-placement="right"
|
||||
tooltip="Search by application name.">
|
||||
|
@ -52,7 +52,7 @@
|
|||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<tr ng-repeat="app in applications">
|
||||
<tr ng-repeat="app in applications | filter:search">
|
||||
<td><a href="#/realms/{{realm.id}}/applications/{{app.id}}">{{app.name}}</a></td>
|
||||
<td>{{app.enabled}}</td>
|
||||
<td ng-class="{'text-muted': !app.baseUrl}">{{app.baseUrl || "Not defined"}}</td>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</ol>
|
||||
<h2><span>{{realm.realm}}</span> Users</h2>
|
||||
<table>
|
||||
<caption data-ng-show="users && search" class="hidden">Table of realm users</caption>
|
||||
<caption data-ng-show="users" class="hidden">Table of realm users</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="rcue-table-actions" colspan="4">
|
||||
|
@ -28,6 +28,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button ng-click="search = null; searchQuery()">View all</button>
|
||||
<a class="button" href="#/create/user/{{realm.id}}">Add User</a>
|
||||
</div>
|
||||
</th>
|
||||
|
@ -66,7 +67,7 @@
|
|||
<div class="feedback warning inline" data-ng-show="searchLoaded && users.length == 0">
|
||||
<p><strong>Your search returned no results.</strong><br>Try modifying the query and try again.</p>
|
||||
</div>
|
||||
<div class="feedback info inline" data-ng-show="!currentSearch">
|
||||
<div class="feedback info inline" data-ng-show="!users">
|
||||
<br/>
|
||||
<p><strong>Search for users.</strong><br>Please enter a search to display users.</p>
|
||||
</div>
|
||||
|
|
|
@ -137,6 +137,8 @@ public interface RealmModel extends RoleContainerModel, RoleMapperModel, ScopeMa
|
|||
|
||||
public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin);
|
||||
|
||||
List<UserModel> getUsers();
|
||||
|
||||
List<UserModel> searchForUser(String search);
|
||||
|
||||
List<UserModel> searchForUserByAttributes(Map<String, String> attributes);
|
||||
|
|
|
@ -670,9 +670,19 @@ public class RealmAdapter implements RealmModel {
|
|||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> getUsers() {
|
||||
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where u.realm = :realm", UserEntity.class);
|
||||
query.setParameter("realm", realm);
|
||||
List<UserEntity> results = query.getResultList();
|
||||
List<UserModel> users = new ArrayList<UserModel>();
|
||||
for (UserEntity entity : results) users.add(new UserAdapter(entity));
|
||||
return users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> searchForUser(String search) {
|
||||
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where u.realm = :realm and lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search", UserEntity.class);
|
||||
TypedQuery<UserEntity> query = em.createQuery("select u from UserEntity u where u.realm = :realm and ( lower(u.loginName) like :search or lower(concat(u.firstName, ' ', u.lastName)) like :search or u.email like :search )", UserEntity.class);
|
||||
query.setParameter("realm", realm);
|
||||
query.setParameter("search", "%" + search.toLowerCase() + "%");
|
||||
List<UserEntity> results = query.getResultList();
|
||||
|
|
|
@ -914,23 +914,28 @@ public class RealmAdapter implements RealmModel {
|
|||
getRelationshipManager().remove(relationship);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> getUsers() {
|
||||
List<UserModel> userModels = new ArrayList<UserModel>();
|
||||
IdentityQuery<User> query = getIdm().createIdentityQuery(User.class);
|
||||
for (User u : query.getResultList()) {
|
||||
userModels.add(new UserAdapter(u, idm));
|
||||
}
|
||||
return userModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserModel> searchForUser(String search) {
|
||||
QueryParameter[] params = new QueryParameter[] { User.LOGIN_NAME, User.FIRST_NAME, User.LAST_NAME, User.EMAIL };
|
||||
|
||||
Map<String, User> users = new HashMap<String, User>();
|
||||
List<UserModel> userModels = new ArrayList<UserModel>();
|
||||
for (QueryParameter p : params) {
|
||||
IdentityQuery<User> query = getIdm().createIdentityQuery(User.class);
|
||||
query.setParameter(p, search.toLowerCase());
|
||||
for (User u : query.getResultList()) {
|
||||
users.put(u.getLoginName(), u);
|
||||
userModels.add(new UserAdapter(u, idm));
|
||||
}
|
||||
}
|
||||
|
||||
List<UserModel> userModels = new ArrayList<UserModel>();
|
||||
for (User user : users.values()) {
|
||||
userModels.add(new UserAdapter(user, idm));
|
||||
}
|
||||
return userModels;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,14 +135,10 @@ public class UsersResource {
|
|||
@QueryParam("username") String username) {
|
||||
RealmManager manager = new RealmManager(session);
|
||||
List<UserRepresentation> results = new ArrayList<UserRepresentation>();
|
||||
List<UserModel> userModels;
|
||||
if (search != null) {
|
||||
List<UserModel> userModels = manager.searchUsers(search, realm);
|
||||
for (UserModel user : userModels) {
|
||||
if (isUser(user)) {
|
||||
results.add(manager.toRepresentation(user));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
userModels = manager.searchUsers(search, realm);
|
||||
} else if (last != null || first != null || email != null || username != null) {
|
||||
Map<String, String> attributes = new HashMap<String, String>();
|
||||
if (last != null) {
|
||||
attributes.put(UserModel.LAST_NAME, last);
|
||||
|
@ -156,11 +152,18 @@ public class UsersResource {
|
|||
if (username != null) {
|
||||
attributes.put(UserModel.LOGIN_NAME, username);
|
||||
}
|
||||
List<UserModel> userModels = realm.searchForUserByAttributes(attributes);
|
||||
userModels = realm.searchForUserByAttributes(attributes);
|
||||
for (UserModel user : userModels) {
|
||||
results.add(manager.toRepresentation(user));
|
||||
}
|
||||
} else {
|
||||
userModels = realm.getUsers();
|
||||
}
|
||||
|
||||
for (UserModel user : userModels) {
|
||||
if (isUser(user)) {
|
||||
results.add(manager.toRepresentation(user));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -303,7 +303,6 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
}
|
||||
|
||||
RealmManager adapter = getRealmManager();
|
||||
adapter.createRealm("other").addUser("bburke");
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("total junk query", realmModel);
|
||||
|
@ -438,8 +437,11 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
}
|
||||
}
|
||||
|
||||
RealmModel otherRealm = adapter.createRealm("other");
|
||||
otherRealm.addUser("bburke");
|
||||
|
||||
|
||||
Assert.assertEquals(1, otherRealm.getUsers().size());
|
||||
Assert.assertEquals(1, otherRealm.searchForUser("u").size());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue