Merge pull request #814 from nextcloud/issue586

Prevent duplicate tag names
This commit is contained in:
Julius Härtl
2019-03-05 10:02:05 +01:00
committed by GitHub
4 changed files with 44 additions and 7 deletions

View File

@@ -323,7 +323,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
// remove from board data
var i = BoardService.getCurrent().labels.indexOf(label);
BoardService.getCurrent().labels.splice(i, 1);
// remove from cards
var cards = CardService.data;
for (var card in cards) {
@@ -346,11 +346,21 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
BoardService.getCurrent().labels.push(data);
$scope.status.createLabel = false;
$scope.newLabel = {};
}).catch((err) => {
OC.Notification.showTemporary(err);
});
};
$scope.labelUpdateBefore = function (label) {
label.renameTitle = label.title;
};
$scope.labelUpdate = function (label) {
label.edit = false;
LabelService.update(label);
LabelService.update(label).catch((err) => {
label.title = label.renameTitle;
OC.Notification.showTemporary(err);
});
// update labels in UI
var cards = CardService.data;

View File

@@ -119,7 +119,7 @@ app.factory('ApiService', function ($http, $q) {
self.add(response.data);
deferred.resolve(response.data);
}, function (error) {
deferred.reject('Fetching' + self.endpoint + ' failed');
deferred.reject(error.data.message);
});
return deferred.promise;
};
@@ -131,7 +131,7 @@ app.factory('ApiService', function ($http, $q) {
self.add(response.data);
deferred.resolve(response.data);
}, function (error) {
deferred.reject('Updating ' + self.endpoint + ' failed');
deferred.reject(error.data.message);
});
return deferred.promise;

View File

@@ -91,6 +91,17 @@ class LabelService {
}
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_MANAGE);
$boardLabels = $this->labelMapper->findAll($boardId);
if (\is_array($boardLabels)) {
foreach($boardLabels as $boardLabel) {
if ($boardLabel->getTitle() === $title) {
throw new BadRequestException('title must be unique');
break;
}
}
}
if ($this->boardService->isArchived(null, $boardId)) {
throw new StatusException('Operation not allowed. This board is archived.');
}
@@ -143,7 +154,7 @@ class LabelService {
throw new BadRequestException('label id must be a number');
}
if ($title === false || $title === null) {
if ($title === false || $title === null || $title === "") {
throw new BadRequestException('title must be provided');
}
@@ -152,10 +163,26 @@ class LabelService {
}
$this->permissionService->checkPermission($this->labelMapper, $id, Acl::PERMISSION_MANAGE);
$label = $this->find($id);
$boardLabels = $this->labelMapper->findAll($label->getBoardId());
if (\is_array($boardLabels)) {
foreach($boardLabels as $boardLabel) {
if ($boardLabel->getId() === $label->getId()) {
continue;
}
if ($boardLabel->getTitle() === $title) {
throw new BadRequestException('title must be unique');
break;
}
}
}
if ($this->boardService->isArchived($this->labelMapper, $id)) {
throw new StatusException('Operation not allowed. This board is archived.');
}
$label = $this->find($id);
$label->setTitle($title);
$label->setColor($color);
$this->changeHelper->boardChanged($label->getBoardId());

View File

@@ -105,7 +105,7 @@
</div>
</div>
<a ng-if="boardservice.canManage() && label.edit" ng-click="labelUpdate(label)" class="icon" title="<?php p($l->t('Update tag')); ?>"><i class="icon icon-checkmark" ></i><span class="hidden-visually"><?php p($l->t('Update tag')); ?></span></a>
<a ng-if="boardservice.canManage() && !label.edit" ng-click="label.edit=true" class="icon" title="<?php p($l->t('Edit tag')); ?>"><i class="icon icon-rename"></i><span class="hidden-visually"><?php p($l->t('Edit tag')); ?></span></a>
<a ng-if="boardservice.canManage() && !label.edit" ng-click="labelUpdateBefore(label); label.edit=true" class="icon" title="<?php p($l->t('Edit tag')); ?>"><i class="icon icon-rename"></i><span class="hidden-visually"><?php p($l->t('Edit tag')); ?></span></a>
<a ng-if="boardservice.canManage()" ng-click="labelDelete(label)" class="icon" title="<?php p($l->t('Delete tag')); ?>"><i class="icon icon-delete" ></i><span class="hidden-visually"><?php p($l->t('Delete tag')); ?></span></a>
</li>
<li ng-if="status.createLabel">