Added option to disallow anonymous uploads
This commit is contained in:
parent
e551a619f1
commit
8b48ba727e
5 changed files with 39 additions and 8 deletions
|
@ -57,7 +57,8 @@ needEmailForCommenting = 0
|
||||||
|
|
||||||
[uploads]
|
[uploads]
|
||||||
needEmailForUploading = 1
|
needEmailForUploading = 1
|
||||||
logAnonymousUploads=1
|
logAnonymousUploadsNicknames = 1
|
||||||
|
allowAnonymousUploads = 1
|
||||||
|
|
||||||
[registration]
|
[registration]
|
||||||
staffActivation = 0
|
staffActivation = 0
|
||||||
|
|
|
@ -18,6 +18,8 @@ class AddPostJob extends AbstractJob
|
||||||
$anonymous = false;
|
$anonymous = false;
|
||||||
if ($this->hasArgument(JobArgs::ARG_ANONYMOUS))
|
if ($this->hasArgument(JobArgs::ARG_ANONYMOUS))
|
||||||
$anonymous = TextHelper::toBoolean($this->getArgument(JobArgs::ARG_ANONYMOUS));
|
$anonymous = TextHelper::toBoolean($this->getArgument(JobArgs::ARG_ANONYMOUS));
|
||||||
|
if ($anonymous and !Core::getConfig()->uploads->allowAnonymousUploads)
|
||||||
|
throw new SimpleException('Anonymous uploads are not allowed');
|
||||||
|
|
||||||
if (Auth::isLoggedIn() and !$anonymous)
|
if (Auth::isLoggedIn() and !$anonymous)
|
||||||
$post->setUploader(Auth::getCurrentUser());
|
$post->setUploader(Auth::getCurrentUser());
|
||||||
|
@ -48,7 +50,7 @@ class AddPostJob extends AbstractJob
|
||||||
PostModel::save($post);
|
PostModel::save($post);
|
||||||
|
|
||||||
Logger::log('{user} added {post} (tags: {tags}, safety: {safety}, source: {source})', [
|
Logger::log('{user} added {post} (tags: {tags}, safety: {safety}, source: {source})', [
|
||||||
'user' => ($anonymous and !Core::getConfig()->uploads->logAnonymousUploads)
|
'user' => ($anonymous and !Core::getConfig()->uploads->logAnonymousUploadsNicknames)
|
||||||
? TextHelper::reprUser(UserModel::getAnonymousName())
|
? TextHelper::reprUser(UserModel::getAnonymousName())
|
||||||
: TextHelper::reprUser(Auth::getCurrentUser()),
|
: TextHelper::reprUser(Auth::getCurrentUser()),
|
||||||
'post' => TextHelper::reprPost($post),
|
'post' => TextHelper::reprPost($post),
|
||||||
|
|
|
@ -95,11 +95,13 @@ $this->assets->addScript('../lib/tagit/jquery.tagit.js');
|
||||||
<?php $checked = true ?>
|
<?php $checked = true ?>
|
||||||
</label>
|
</label>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
<?php if (Core::getConfig()->uploads->allowAnonymousUploads): ?>
|
||||||
<input type="hidden" name="anonymous" value="0"/>
|
<input type="hidden" name="anonymous" value="0"/>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="anonymous" value="1"/>
|
<input type="checkbox" name="anonymous" value="1"/>
|
||||||
Upload anonymously
|
Upload anonymously
|
||||||
</label>
|
</label>
|
||||||
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,31 @@ class AddPostJobTest extends AbstractTest
|
||||||
$this->assert->isNull($post->getUploaderId());
|
$this->assert->isNull($post->getUploaderId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAnonymousUploadsPrivilegeFail()
|
||||||
|
{
|
||||||
|
$this->prepare();
|
||||||
|
|
||||||
|
$this->grantAccess('addPost');
|
||||||
|
$this->grantAccess('addPostTags');
|
||||||
|
$this->grantAccess('addPostContent');
|
||||||
|
|
||||||
|
Core::getConfig()->uploads->allowAnonymousUploads = false;
|
||||||
|
|
||||||
|
$this->login($this->userMocker->mockSingle());
|
||||||
|
|
||||||
|
$this->assert->throws(function()
|
||||||
|
{
|
||||||
|
return Api::run(
|
||||||
|
new AddPostJob(),
|
||||||
|
[
|
||||||
|
JobArgs::ARG_ANONYMOUS => '1',
|
||||||
|
JobArgs::ARG_NEW_TAG_NAMES => ['kamen', 'raider'],
|
||||||
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
||||||
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
||||||
|
]);
|
||||||
|
}, 'Anonymous uploads are not allowed');
|
||||||
|
}
|
||||||
|
|
||||||
public function testPartialPrivilegeFail()
|
public function testPartialPrivilegeFail()
|
||||||
{
|
{
|
||||||
$this->prepare();
|
$this->prepare();
|
||||||
|
|
|
@ -50,7 +50,8 @@ commentsPerPage = 10
|
||||||
maxCommentsInList = 5
|
maxCommentsInList = 5
|
||||||
|
|
||||||
[uploads]
|
[uploads]
|
||||||
logAnonymousUploads=1
|
logAnonymousUploadsNicknames = 1
|
||||||
|
allowAnonymousUploads = 1
|
||||||
|
|
||||||
[registration]
|
[registration]
|
||||||
staffActivation = 0
|
staffActivation = 0
|
||||||
|
|
Loading…
Reference in a new issue