mirror of
https://github.com/sismics/docs.git
synced 2024-12-22 19:33:47 +01:00
#18: Add/remove users from groups
This commit is contained in:
parent
689a4e6aae
commit
ced64a5d1f
@ -21,7 +21,9 @@ import com.google.common.base.Strings;
|
||||
import com.sismics.docs.core.dao.jpa.GroupDao;
|
||||
import com.sismics.docs.core.dao.jpa.UserDao;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.GroupCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.criteria.UserCriteria;
|
||||
import com.sismics.docs.core.dao.jpa.dto.GroupDto;
|
||||
import com.sismics.docs.core.dao.jpa.dto.UserDto;
|
||||
import com.sismics.docs.core.model.jpa.Group;
|
||||
import com.sismics.docs.core.model.jpa.User;
|
||||
import com.sismics.docs.core.model.jpa.UserGroup;
|
||||
@ -327,7 +329,14 @@ public class GroupResource extends BaseResource {
|
||||
response.add("parent", parentGroup.getName());
|
||||
}
|
||||
|
||||
// TODO Add members
|
||||
// Members
|
||||
JsonArrayBuilder members = Json.createArrayBuilder();
|
||||
UserDao userDao = new UserDao();
|
||||
List<UserDto> userDtoList = userDao.findByCriteria(new UserCriteria().setGroupId(group.getId()), new SortCriteria(1, true));
|
||||
for (UserDto userDto : userDtoList) {
|
||||
members.add(userDto.getUsername());
|
||||
}
|
||||
response.add("members", members);
|
||||
|
||||
return Response.ok().entity(response.build()).build();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog,
|
||||
/**
|
||||
* Delete the current group.
|
||||
*/
|
||||
$scope.remove = function () {
|
||||
$scope.remove = function() {
|
||||
var title = 'Delete group';
|
||||
var msg = 'Do you really want to delete this group?';
|
||||
var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}];
|
||||
@ -61,7 +61,7 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog,
|
||||
Restangular.one('group', $stateParams.name).remove().then(function() {
|
||||
$scope.loadGroups();
|
||||
$state.go('settings.group');
|
||||
}, function () {
|
||||
}, function() {
|
||||
$state.go('settings.group');
|
||||
});
|
||||
}
|
||||
@ -84,4 +84,43 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog,
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a promise for typeahead user.
|
||||
*/
|
||||
$scope.getUserTypeahead = function($viewValue) {
|
||||
var deferred = $q.defer();
|
||||
Restangular.one('user')
|
||||
.getList('list', {
|
||||
search: $viewValue,
|
||||
sort_column: 1,
|
||||
asc: true
|
||||
}).then(function(data) {
|
||||
deferred.resolve(_.pluck(data.users, 'username'));
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a new member.
|
||||
*/
|
||||
$scope.addMember = function(member) {
|
||||
$scope.member = '';
|
||||
Restangular.one('group/' + $stateParams.name).put({
|
||||
username: member
|
||||
}).then(function() {
|
||||
if ($scope.group.members.indexOf(member) === -1) {
|
||||
$scope.group.members.push(member);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a member.
|
||||
*/
|
||||
$scope.removeMember = function(member) {
|
||||
Restangular.one('group/' + $stateParams.name, member).remove().then(function() {
|
||||
$scope.group.members.splice($scope.group.members.indexOf(member), 1);
|
||||
});
|
||||
};
|
||||
});
|
@ -8,7 +8,10 @@ angular.module('docs').controller('SettingsUser', function($scope, $state, Resta
|
||||
* Load users from server.
|
||||
*/
|
||||
$scope.loadUsers = function() {
|
||||
Restangular.one('user/list').get().then(function(data) {
|
||||
Restangular.one('user/list').get({
|
||||
sort_column: 1,
|
||||
asc: true
|
||||
}).then(function(data) {
|
||||
$scope.users = data.users;
|
||||
});
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
|
||||
/**
|
||||
* Delete the current user.
|
||||
*/
|
||||
$scope.remove = function () {
|
||||
$scope.remove = function() {
|
||||
var title = 'Delete user';
|
||||
var msg = 'Do you really want to delete this user? All associated documents, files and tags will be deleted';
|
||||
var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}];
|
||||
@ -58,7 +58,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog,
|
||||
Restangular.one('user', $stateParams.username).remove().then(function() {
|
||||
$scope.loadUsers();
|
||||
$state.go('settings.user');
|
||||
}, function () {
|
||||
}, function() {
|
||||
$state.go('settings.user');
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,10 @@
|
||||
*/
|
||||
angular.module('docs').controller('User', function(Restangular, $scope, $state) {
|
||||
// Load users
|
||||
Restangular.one('user/list').get({ limit: 100 }).then(function(data) {
|
||||
Restangular.one('user/list').get({
|
||||
sort_column: 1,
|
||||
asc: true
|
||||
}).then(function(data) {
|
||||
$scope.users = data.users;
|
||||
});
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
</li>
|
||||
</ul>
|
||||
<input class="form-control" type="text" id="{{ ref }}" placeholder="Type a document title" ng-model="input" ng-disabled="ngDisabled"
|
||||
autocomplete="off"
|
||||
typeahead="document.title for document in getDocumentTypeahead($viewValue) | filter: $viewValue"
|
||||
autocomplete="off" typeahead="document.title for document in getDocumentTypeahead($viewValue)"
|
||||
typeahead-wait-ms="200" typeahead-on-select="addRelation($item)" />
|
||||
</div>
|
@ -9,7 +9,7 @@
|
||||
<div class="col-sm-10">
|
||||
<input required ng-maxlength="100" class="form-control" type="text" id="inputTitle"
|
||||
placeholder="The nature or genre of the resource" name="title" ng-model="document.title" autocomplete="off"
|
||||
typeahead="document for document in getTitleTypeahead($viewValue) | filter: $viewValue"
|
||||
typeahead="document for document in getTitleTypeahead($viewValue)"
|
||||
typeahead-wait-ms="200" ng-disabled="fileIsUploading" />
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
<div class="col-sm-7">
|
||||
<input name="name" type="text" id="inputParent" class="form-control" autocomplete="off"
|
||||
placeholder="Type a group name" ng-model="group.parent"
|
||||
typeahead="group for group in getGroupTypeahead($viewValue) | filter: $viewValue"
|
||||
placeholder="Search a group" ng-model="group.parent"
|
||||
typeahead="group for group in getGroupTypeahead($viewValue)"
|
||||
typeahead-wait-ms="200" typeahead-editable="false" />
|
||||
</div>
|
||||
</div>
|
||||
@ -44,6 +44,30 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h3>Members</h3>
|
||||
|
||||
<div ng-show="isEdit()">
|
||||
<h3>Members</h3>
|
||||
<form class="form-horizontal" novalidate>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="inputMember">New member</label>
|
||||
<div class="col-sm-7">
|
||||
<input name="member" type="text" id="inputMember" class="form-control" ng-model="member" placeholder="Search a user"
|
||||
typeahead="user for user in getUserTypeahead($viewValue)" typeahead-on-select="addMember($item)"
|
||||
typeahead-wait-ms="200" typeahead-editable="false"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Members</label>
|
||||
<div class="col-sm-7">
|
||||
<span ng-repeat="member in group.members">
|
||||
<span class="btn btn-default"
|
||||
ng-click="removeMember(member)">
|
||||
{{ member }}
|
||||
<span class="glyphicon glyphicon-remove"></span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -130,6 +130,9 @@ public class TestGroupResource extends BaseJerseyTest {
|
||||
.get(JsonObject.class);
|
||||
Assert.assertEquals("g12new", json.getString("name"));
|
||||
Assert.assertEquals("g11", json.getString("parent"));
|
||||
JsonArray members = json.getJsonArray("members");
|
||||
Assert.assertEquals(1, members.size());
|
||||
Assert.assertEquals("group1", members.getString(0));
|
||||
|
||||
// Remove group1 from g12new
|
||||
json = target().path("/group/g12new/group1").request()
|
||||
|
Loading…
Reference in New Issue
Block a user