Added tag banning
This commit is contained in:
parent
1e745fa648
commit
250ffb209f
17 changed files with 90 additions and 13 deletions
10
TODO
10
TODO
|
@ -28,16 +28,6 @@ everything related to tags:
|
|||
- tag editing
|
||||
- category (from config.ini)
|
||||
- description
|
||||
- aliases
|
||||
- take care of recursion
|
||||
- listing
|
||||
- sort alphabetically
|
||||
- sort by time of addition
|
||||
- adding
|
||||
- removing
|
||||
- editing
|
||||
- from
|
||||
- to (allow multiple)
|
||||
- implications - when entering child tag, add parent tag
|
||||
- take care of recursion
|
||||
- listing
|
||||
|
|
|
@ -60,6 +60,7 @@ changePostFlags = regularUser, powerUser, moderator, administrator
|
|||
listTags = regularUser, powerUser, moderator, administrator
|
||||
massTag = powerUser, moderator, administrator
|
||||
changeTagName = moderator, administrator
|
||||
banTags = moderator, administrator
|
||||
|
||||
listComments = regularUser, powerUser, moderator, administrator
|
||||
addComments = regularUser, powerUser, moderator, administrator
|
||||
|
|
|
@ -45,6 +45,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
|||
listTags: 'listTags',
|
||||
massTag: 'massTag',
|
||||
changeTagName: 'changeTagName',
|
||||
banTags: 'banTags',
|
||||
|
||||
viewHistory: 'viewHistory',
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@ App.Presenters.TagPresenter = function(
|
|||
topNavigationPresenter.changeTitle('Tags');
|
||||
|
||||
privileges.canChangeName = auth.hasPrivilege(auth.privileges.changeTagName);
|
||||
privileges.canBan = auth.hasPrivilege(auth.privileges.banTags);
|
||||
|
||||
promise.wait(
|
||||
util.promiseTemplate('tag'),
|
||||
|
@ -81,6 +82,10 @@ App.Presenters.TagPresenter = function(
|
|||
formData.name = $form.find('[name=name]').val();
|
||||
}
|
||||
|
||||
if (privileges.canBan) {
|
||||
formData.banned = $form.find('[name=ban]').is(':checked') ? 1 : 0;
|
||||
}
|
||||
|
||||
promise.wait(api.put('/tags/' + tag.name, formData))
|
||||
.then(function(response) {
|
||||
tag = response.json;
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (privileges.canBan) { %>
|
||||
<div class="form-row">
|
||||
<label class="form-label" for="tag-ban">Ban:</label>
|
||||
<div class="form-input">
|
||||
<input name="ban" type="checkbox" id="ban" <% print(tag.banned ? 'checked="checked"' : '') %>>
|
||||
<label for="ban">
|
||||
Prevent tag from being used
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<div class="form-row">
|
||||
<label class="form-label"></label>
|
||||
<div class="form-input">
|
||||
|
|
|
@ -81,6 +81,9 @@ final class TagController extends AbstractController
|
|||
if ($formData->name !== null)
|
||||
$this->privilegeService->assertPrivilege(Privilege::CHANGE_TAG_NAME);
|
||||
|
||||
if ($formData->banned !== null)
|
||||
$this->privilegeService->assertPrivilege(Privilege::BAN_TAGS);
|
||||
|
||||
$tag = $this->tagService->updateTag($tag, $formData);
|
||||
return $this->tagViewProxy->fromEntity($tag);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ class TagViewProxy extends AbstractViewProxy
|
|||
{
|
||||
$result->name = $tag->getName();
|
||||
$result->usages = $tag->getUsages();
|
||||
$result->banned = $tag->isBanned();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
|
|||
'id' => $entity->getId(),
|
||||
'name' => $entity->getName(),
|
||||
'creationTime' => $this->entityTimeToDbTime($entity->getCreationTime()),
|
||||
'banned' => $entity->isBanned(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -21,6 +22,7 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
|
|||
$entity->setName($array['name']);
|
||||
$entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime']));
|
||||
$entity->setMeta(Tag::META_USAGES, intval($array['usages']));
|
||||
$entity->setBanned($array['banned']);
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ final class Tag extends Entity
|
|||
{
|
||||
private $name;
|
||||
private $creationTime;
|
||||
private $banned = false;
|
||||
|
||||
const META_USAGES = 'usages';
|
||||
|
||||
|
@ -23,6 +24,16 @@ final class Tag extends Entity
|
|||
return $this->creationTime;
|
||||
}
|
||||
|
||||
public function isBanned()
|
||||
{
|
||||
return $this->banned;
|
||||
}
|
||||
|
||||
public function setBanned($banned)
|
||||
{
|
||||
$this->banned = boolval($banned);
|
||||
}
|
||||
|
||||
public function setCreationTime($creationTime)
|
||||
{
|
||||
$this->creationTime = $creationTime;
|
||||
|
|
|
@ -6,12 +6,15 @@ use Szurubooru\Validator;
|
|||
class TagEditFormData implements IValidatable
|
||||
{
|
||||
public $name;
|
||||
public $banned;
|
||||
|
||||
public function __construct($inputReader = null)
|
||||
{
|
||||
if ($inputReader !== null)
|
||||
{
|
||||
$this->name = $inputReader->name;
|
||||
if ($inputReader->banned !== null)
|
||||
$this->banned = boolval($inputReader->banned);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class Privilege
|
|||
const LIST_TAGS = 'listTags';
|
||||
const MASS_TAG = 'massTag';
|
||||
const CHANGE_TAG_NAME = 'changeTagName';
|
||||
const BAN_TAGS = 'banTags';
|
||||
|
||||
const LIST_COMMENTS = 'listComments';
|
||||
const ADD_COMMENTS = 'addComments';
|
||||
|
|
|
@ -303,6 +303,11 @@ class PostService
|
|||
$tags[] = $tag;
|
||||
}
|
||||
$tags = $this->tagService->createTags($tags);
|
||||
foreach ($tags as $tag)
|
||||
{
|
||||
if ($tag->isBanned())
|
||||
throw new \DomainException('Cannot use banned tag "' . $tag->getName() . '"');
|
||||
}
|
||||
$post->setTags($tags);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,8 @@ class TagService
|
|||
{
|
||||
$tags[$tag->getId()] = [
|
||||
'name' => $tag->getName(),
|
||||
'usages' => $tag->getUsages()];
|
||||
'usages' => $tag->getUsages(),
|
||||
'banned' => $tag->isBanned()];
|
||||
}
|
||||
$json = json_encode($tags);
|
||||
$this->fileDao->save('tags.json', $json);
|
||||
|
@ -141,6 +142,9 @@ class TagService
|
|||
if ($formData->name !== null)
|
||||
$this->updateTagName($tag, $formData->name);
|
||||
|
||||
if ($formData->banned !== $tag->isBanned())
|
||||
$tag->setBanned(boolval($formData->banned));
|
||||
|
||||
return $this->tagDao->save($tag);
|
||||
};
|
||||
$ret = $this->transactionManager->commit($transactionFunc);
|
||||
|
|
22
src/Upgrades/Upgrade23.php
Normal file
22
src/Upgrades/Upgrade23.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
namespace Szurubooru\Upgrades;
|
||||
use Szurubooru\DatabaseConnection;
|
||||
use Szurubooru\Services\TagService;
|
||||
|
||||
class Upgrade23 implements IUpgrade
|
||||
{
|
||||
private $tagService;
|
||||
|
||||
public function __construct(TagService $tagService)
|
||||
{
|
||||
$this->tagService = $tagService;
|
||||
}
|
||||
|
||||
public function run(DatabaseConnection $databaseConnection)
|
||||
{
|
||||
$pdo = $databaseConnection->getPDO();
|
||||
$pdo->exec('ALTER TABLE tags ADD COLUMN banned BOOLEAN NOT NULL DEFAULT 0');
|
||||
|
||||
$this->tagService->exportJson();
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ return [
|
|||
$container->get(\Szurubooru\Upgrades\Upgrade20::class),
|
||||
$container->get(\Szurubooru\Upgrades\Upgrade21::class),
|
||||
$container->get(\Szurubooru\Upgrades\Upgrade22::class),
|
||||
$container->get(\Szurubooru\Upgrades\Upgrade23::class),
|
||||
];
|
||||
}),
|
||||
|
||||
|
|
|
@ -11,6 +11,20 @@ final class TagDaoTest extends AbstractDatabaseTestCase
|
|||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testSaving()
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->setName('test1');
|
||||
$tag->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||
$this->assertFalse($tag->isBanned());
|
||||
$tag->setBanned(true);
|
||||
|
||||
$tagDao = $this->getTagDao();
|
||||
$tagDao->save($tag);
|
||||
$actualTag = $tagDao->findById($tag->getId());
|
||||
$this->assertEntitiesEqual($tag, $actualTag);
|
||||
}
|
||||
|
||||
public function testFindByPostIds()
|
||||
{
|
||||
$pdo = $this->databaseConnection->getPDO();
|
||||
|
|
|
@ -78,7 +78,7 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
|||
$tagService = $this->getTagService();
|
||||
$tagService->createTags([$tag1]);
|
||||
$tagService->exportJson();
|
||||
$this->assertEquals('{"1":{"name":"test","usages":0}}', $fileDao->load('tags.json'));
|
||||
$this->assertEquals('{"1":{"name":"test","usages":0,"banned":false}}', $fileDao->load('tags.json'));
|
||||
}
|
||||
|
||||
public function testExportMultiple()
|
||||
|
@ -89,11 +89,12 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
|||
$tag2 = new Tag();
|
||||
$tag2->setName('test2');
|
||||
$tag2->setCreationTime(date('c'));
|
||||
$tag2->setBanned(true);
|
||||
$fileDao = $this->getPublicFileDao();
|
||||
$tagService = $this->getTagService();
|
||||
$tagService->createTags([$tag1, $tag2]);
|
||||
$tagService->exportJson();
|
||||
$this->assertEquals('{"1":{"name":"test1","usages":0},"2":{"name":"test2","usages":0}}', $fileDao->load('tags.json'));
|
||||
$this->assertEquals('{"1":{"name":"test1","usages":0,"banned":false},"2":{"name":"test2","usages":0,"banned":true}}', $fileDao->load('tags.json'));
|
||||
}
|
||||
|
||||
private function getPublicFileDao()
|
||||
|
|
Loading…
Reference in a new issue