mirror of
https://github.com/sismics/docs.git
synced 2026-01-23 13:37:19 +00:00
Closes #237: prevent tag circular reference
This commit is contained in:
@@ -192,7 +192,7 @@ public class TagResource extends BaseResource {
|
||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
Tag tag = new Tag();
|
||||
@@ -239,6 +239,7 @@ public class TagResource extends BaseResource {
|
||||
* @apiError (client) ValidationError Validation error
|
||||
* @apiError (client) SpacesNotAllowed Spaces are not allowed in tag name
|
||||
* @apiError (client) ParentNotFound Parent not found
|
||||
* @apiError (client) CircularReference Circular reference in parent tag
|
||||
* @apiError (client) NotFound Tag not found
|
||||
* @apiPermission user
|
||||
* @apiVersion 1.5.0
|
||||
@@ -275,16 +276,25 @@ public class TagResource extends BaseResource {
|
||||
}
|
||||
|
||||
// Check the parent
|
||||
TagDao tagDao = new TagDao();
|
||||
if (StringUtils.isEmpty(parentId)) {
|
||||
parentId = null;
|
||||
} else {
|
||||
if (!aclDao.checkPermission(parentId, PermType.READ, getTargetIdList(null))) {
|
||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||
}
|
||||
|
||||
String parentTagId = parentId;
|
||||
do {
|
||||
Tag parentTag = tagDao.getById(parentTagId);
|
||||
parentTagId = parentTag.getParentId();
|
||||
if (parentTag.getId().equals(id)) {
|
||||
throw new ClientException("CircularReference", "Circular reference in parent tag");
|
||||
}
|
||||
} while (parentTagId != null);
|
||||
}
|
||||
|
||||
|
||||
// Update the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
Tag tag = tagDao.getById(id);
|
||||
if (!StringUtils.isEmpty(name)) {
|
||||
tag.setName(name);
|
||||
|
||||
@@ -21,7 +21,15 @@ angular.module('docs').controller('TagEdit', function($scope, $stateParams, Rest
|
||||
*/
|
||||
$scope.edit = function() {
|
||||
// Update the server
|
||||
Restangular.one('tag', $scope.tag.id).post('', $scope.tag);
|
||||
Restangular.one('tag', $scope.tag.id).post('', $scope.tag).then(function () {
|
||||
}, function (e) {
|
||||
if (e.data.type === 'CircularReference') {
|
||||
var title = $translate.instant('tag.edit.circular_reference_title');
|
||||
var msg = $translate.instant('tag.edit.circular_reference_message');
|
||||
var btns = [{result: 'ok', label: $translate.instant('ok'), cssClass: 'btn-primary'}];
|
||||
$dialog.messageBox(title, msg, btns);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -219,7 +219,9 @@
|
||||
"name": "Name",
|
||||
"color": "Color",
|
||||
"parent": "Parent",
|
||||
"info": "Permissions on this tag will also be applied to documents tagged <span class=\"label label-info\" ng-style=\"{ 'background': color }\">{{ name }}</span>"
|
||||
"info": "Permissions on this tag will also be applied to documents tagged <span class=\"label label-info\" ng-style=\"{ 'background': color }\">{{ name }}</span>",
|
||||
"circular_reference_title": "Circular reference",
|
||||
"circular_reference_message": "The hierarchy of parent tags makes a loop, please choose another parent."
|
||||
}
|
||||
},
|
||||
"group": {
|
||||
|
||||
Reference in New Issue
Block a user