Added option to disallow anonymous uploads

This commit is contained in:
Marcin Kurczewski 2014-05-26 12:40:02 +02:00
parent e551a619f1
commit 8b48ba727e
5 changed files with 39 additions and 8 deletions

View file

@ -57,7 +57,8 @@ needEmailForCommenting = 0
[uploads]
needEmailForUploading = 1
logAnonymousUploads=1
logAnonymousUploadsNicknames = 1
allowAnonymousUploads = 1
[registration]
staffActivation = 0

View file

@ -18,6 +18,8 @@ class AddPostJob extends AbstractJob
$anonymous = false;
if ($this->hasArgument(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)
$post->setUploader(Auth::getCurrentUser());
@ -48,7 +50,7 @@ class AddPostJob extends AbstractJob
PostModel::save($post);
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(Auth::getCurrentUser()),
'post' => TextHelper::reprPost($post),

View file

@ -95,11 +95,13 @@ $this->assets->addScript('../lib/tagit/jquery.tagit.js');
<?php $checked = true ?>
</label>
<?php endforeach ?>
<input type="hidden" name="anonymous" value="0"/>
<label>
<input type="checkbox" name="anonymous" value="1"/>
Upload anonymously
</label>
<?php if (Core::getConfig()->uploads->allowAnonymousUploads): ?>
<input type="hidden" name="anonymous" value="0"/>
<label>
<input type="checkbox" name="anonymous" value="1"/>
Upload anonymously
</label>
<?php endif ?>
</div>
</div>

View file

@ -87,6 +87,31 @@ class AddPostJobTest extends AbstractTest
$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()
{
$this->prepare();

View file

@ -50,7 +50,8 @@ commentsPerPage = 10
maxCommentsInList = 5
[uploads]
logAnonymousUploads=1
logAnonymousUploadsNicknames = 1
allowAnonymousUploads = 1
[registration]
staffActivation = 0