Added tag relationship management to backend
This commit is contained in:
parent
1b82504f08
commit
5815f156a8
8 changed files with 61 additions and 8 deletions
5
TODO
5
TODO
|
@ -33,11 +33,6 @@ everything related to tags:
|
|||
- privileges
|
||||
- template
|
||||
- ajax
|
||||
- handle tag relations editing in backend
|
||||
- tagservice::update
|
||||
- tageditformdata
|
||||
- tagcontroller
|
||||
- privileges
|
||||
- handle relations in autocomplete
|
||||
|
||||
refactors:
|
||||
|
|
|
@ -60,6 +60,8 @@ changePostFlags = regularUser, powerUser, moderator, administrator
|
|||
listTags = regularUser, powerUser, moderator, administrator
|
||||
massTag = powerUser, moderator, administrator
|
||||
changeTagName = moderator, administrator
|
||||
changeTagImplications = moderator, administrator
|
||||
changeTagSuggestions = moderator, administrator
|
||||
banTags = moderator, administrator
|
||||
|
||||
listComments = regularUser, powerUser, moderator, administrator
|
||||
|
|
|
@ -45,6 +45,8 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
|||
listTags: 'listTags',
|
||||
massTag: 'massTag',
|
||||
changeTagName: 'changeTagName',
|
||||
changeTagImplications: 'changeTagImplications',
|
||||
changeTagSuggestions: 'changeTagSuggestions',
|
||||
banTags: 'banTags',
|
||||
|
||||
viewHistory: 'viewHistory',
|
||||
|
|
|
@ -44,7 +44,7 @@ final class TagController extends AbstractController
|
|||
$this->privilegeService->assertPrivilege(Privilege::LIST_TAGS);
|
||||
|
||||
$tag = $this->tagService->getByName($tagName);
|
||||
return $this->tagViewProxy->fromEntity($tag);
|
||||
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
|
@ -84,7 +84,22 @@ final class TagController extends AbstractController
|
|||
if ($formData->banned !== null)
|
||||
$this->privilegeService->assertPrivilege(Privilege::BAN_TAGS);
|
||||
|
||||
if ($formData->implications !== null)
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_IMPLICATIONS);
|
||||
|
||||
if ($formData->suggestions !== null)
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_SUGGESTIONS);
|
||||
|
||||
$tag = $this->tagService->updateTag($tag, $formData);
|
||||
return $this->tagViewProxy->fromEntity($tag);
|
||||
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||
}
|
||||
|
||||
private function getFullFetchConfig()
|
||||
{
|
||||
return
|
||||
[
|
||||
TagViewProxy::FETCH_IMPLICATIONS => true,
|
||||
TagViewProxy::FETCH_SUGGESTIONS => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ namespace Szurubooru\Controllers\ViewProxies;
|
|||
|
||||
class TagViewProxy extends AbstractViewProxy
|
||||
{
|
||||
const FETCH_IMPLICATIONS = 'fetchImplications';
|
||||
const FETCH_SUGGESTIONS = 'fetchSuggestions';
|
||||
|
||||
public function fromEntity($tag, $config = [])
|
||||
{
|
||||
$result = new \StdClass;
|
||||
|
@ -11,6 +14,12 @@ class TagViewProxy extends AbstractViewProxy
|
|||
$result->name = $tag->getName();
|
||||
$result->usages = $tag->getUsages();
|
||||
$result->banned = $tag->isBanned();
|
||||
|
||||
if (!empty($config[self::FETCH_IMPLICATIONS]))
|
||||
$result->implications = $this->fromArray($tag->getImpliedTags());
|
||||
|
||||
if (!empty($config[self::FETCH_SUGGESTIONS]))
|
||||
$result->suggestions = $this->fromArray($tag->getSuggestedTags());
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -7,14 +7,20 @@ class TagEditFormData implements IValidatable
|
|||
{
|
||||
public $name;
|
||||
public $banned;
|
||||
public $implications;
|
||||
public $suggestions;
|
||||
|
||||
public function __construct($inputReader = null)
|
||||
{
|
||||
if ($inputReader !== null)
|
||||
{
|
||||
$this->name = $inputReader->name;
|
||||
|
||||
if ($inputReader->banned !== null)
|
||||
$this->banned = boolval($inputReader->banned);
|
||||
|
||||
$this->implications = array_filter(array_unique(preg_split('/[\s+]/', $inputReader->implications)));
|
||||
$this->suggestions = array_filter(array_unique(preg_split('/[\s+]/', $inputReader->suggestions)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +28,12 @@ class TagEditFormData implements IValidatable
|
|||
{
|
||||
if ($this->name !== null)
|
||||
$validator->validatePostTags([$this->name]);
|
||||
|
||||
if (!empty($this->implications))
|
||||
$validator->validatePostTags($this->implications);
|
||||
|
||||
if (!empty($this->suggestions))
|
||||
$validator->validatePostTags($this->suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ class Privilege
|
|||
const LIST_TAGS = 'listTags';
|
||||
const MASS_TAG = 'massTag';
|
||||
const CHANGE_TAG_NAME = 'changeTagName';
|
||||
const CHANGE_TAG_IMPLICATIONS = 'changeTagImplications';
|
||||
const CHANGE_TAG_SUGGESTIONS = 'changeTagSuggestions';
|
||||
const BAN_TAGS = 'banTags';
|
||||
|
||||
const LIST_COMMENTS = 'listComments';
|
||||
|
|
|
@ -90,7 +90,7 @@ class TagService
|
|||
{
|
||||
$tagNameGetter = function($tag)
|
||||
{
|
||||
return strtolower($tag->getName());
|
||||
return strtolower(is_string($tag) ? $tag : $tag->getName());
|
||||
};
|
||||
|
||||
$tagsNotToCreate = [];
|
||||
|
@ -105,6 +105,12 @@ class TagService
|
|||
if (isset($tagsNotToCreate[$tagNameGetter($tag)]))
|
||||
continue;
|
||||
|
||||
if (is_string($tag))
|
||||
{
|
||||
$tagName = $tag;
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
}
|
||||
$tag->setCreationTime($this->timeService->getCurrentTime());
|
||||
$tagsToCreate[$tagNameGetter($tag)] = $tag;
|
||||
}
|
||||
|
@ -169,4 +175,14 @@ class TagService
|
|||
{
|
||||
$tag->setName($newName);
|
||||
}
|
||||
|
||||
private function updateImplications(Tag $tag, array $relatedNames)
|
||||
{
|
||||
$tag->setImpliedTags($this->createTags($relatedNames));
|
||||
}
|
||||
|
||||
private function updateSuggestions(Tag $tag, array $relatedNames)
|
||||
{
|
||||
$tag->setSuggestedTags($this->createTags($relatedNames));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue