Added manual tag removal
This commit is contained in:
parent
78ccff843c
commit
005d857cfb
7 changed files with 42 additions and 3 deletions
|
@ -68,6 +68,7 @@ changeTagCategory = moderator, administrator
|
|||
changeTagImplications = moderator, administrator
|
||||
changeTagSuggestions = moderator, administrator
|
||||
banTags = moderator, administrator
|
||||
deleteTags = moderator, administrator
|
||||
|
||||
listComments = regularUser, powerUser, moderator, administrator
|
||||
addComments = regularUser, powerUser, moderator, administrator
|
||||
|
|
|
@ -45,6 +45,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
|||
editAllComments: 'editAllComments',
|
||||
deleteOwnComments: 'deleteOwnComments',
|
||||
deleteAllComments: 'deleteAllComments',
|
||||
deleteTags: 'deleteTags',
|
||||
|
||||
listTags: 'listTags',
|
||||
massTag: 'massTag',
|
||||
|
|
|
@ -83,12 +83,14 @@ App.Presenters.TagPresenter = function(
|
|||
tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')),
|
||||
}));
|
||||
$el.find('.post-list').hide();
|
||||
$el.find('form').submit(editFormSubmitted);
|
||||
$el.find('form').submit(function(e) { e.preventDefault(); });
|
||||
$el.find('form button[name=update]').click(updateButtonClicked);
|
||||
$el.find('form button[name=delete]').click(deleteButtonClicked);
|
||||
implicationsTagInput = App.Controls.TagInput($el.find('[name=implications]'));
|
||||
suggestionsTagInput = App.Controls.TagInput($el.find('[name=suggestions]'));
|
||||
}
|
||||
|
||||
function editFormSubmitted(e) {
|
||||
function updateButtonClicked(e) {
|
||||
e.preventDefault();
|
||||
var $form = $el.find('form');
|
||||
var formData = {};
|
||||
|
@ -121,6 +123,18 @@ App.Presenters.TagPresenter = function(
|
|||
});
|
||||
}
|
||||
|
||||
function deleteButtonClicked(e) {
|
||||
if (!window.confirm('Are you sure you want to delete this tag?')) {
|
||||
return;
|
||||
}
|
||||
promise.wait(api.delete('/tags/' + tag.name))
|
||||
.then(function(response) {
|
||||
router.navigate('#/tags');
|
||||
}).fail(function(response) {
|
||||
window.alert(response.json && response.json.error || 'An error occured.');
|
||||
});
|
||||
}
|
||||
|
||||
function renderPosts(posts) {
|
||||
var $target = $el.find('.post-list ul');
|
||||
_.each(posts, function(post) {
|
||||
|
|
|
@ -70,7 +70,8 @@
|
|||
<div class="form-row">
|
||||
<label class="form-label"></label>
|
||||
<div class="form-input">
|
||||
<button type="submit">Update</button>
|
||||
<button type="submit" name="update">Update</button>
|
||||
<button type="submit" name="delete">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
|
|
@ -37,6 +37,7 @@ final class TagController extends AbstractController
|
|||
$router->get('/api/tags/:tagName', [$this, 'getTag']);
|
||||
$router->get('/api/tags/:tagName/siblings', [$this, 'getTagSiblings']);
|
||||
$router->put('/api/tags/:tagName', [$this, 'updateTag']);
|
||||
$router->delete('/api/tags/:tagName', [$this, 'deleteTag']);
|
||||
}
|
||||
|
||||
public function getTag($tagName)
|
||||
|
@ -97,6 +98,13 @@ final class TagController extends AbstractController
|
|||
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||
}
|
||||
|
||||
public function deleteTag($tagName)
|
||||
{
|
||||
$tag = $this->tagService->getByName($tagName);
|
||||
$this->privilegeService->assertPrivilege(Privilege::DELETE_TAGS);
|
||||
return $this->tagService->deleteTag($tag);
|
||||
}
|
||||
|
||||
private function getFullFetchConfig()
|
||||
{
|
||||
return
|
||||
|
|
|
@ -46,6 +46,7 @@ class Privilege
|
|||
const CHANGE_TAG_IMPLICATIONS = 'changeTagImplications';
|
||||
const CHANGE_TAG_SUGGESTIONS = 'changeTagSuggestions';
|
||||
const BAN_TAGS = 'banTags';
|
||||
const DELETE_TAGS = 'deleteTags';
|
||||
|
||||
const LIST_COMMENTS = 'listComments';
|
||||
const ADD_COMMENTS = 'addComments';
|
||||
|
|
|
@ -165,6 +165,19 @@ class TagService
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public function deleteTag(Tag $tag)
|
||||
{
|
||||
if ($tag->getUsages() !== 0)
|
||||
throw new \DomainException('Only tags with no usages can be deleted.');
|
||||
|
||||
$transactionFunc = function() use ($tag)
|
||||
{
|
||||
$this->tagDao->deleteById($tag->getId());
|
||||
};
|
||||
|
||||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
private function updateTagName(Tag $tag, $newName)
|
||||
{
|
||||
$otherTag = $this->tagDao->findByName($newName);
|
||||
|
|
Loading…
Reference in a new issue