...
 
<?php
namespace Minds\Common;
class Access
{
const UNLISTED = 0;
const LOGGED_IN = 1;
const PUBLIC = 2;
const UNKNOWN = 99;
const ACCESS_STRINGS = [
0 => 'Unlisted',
1 => 'LoggedIn',
3 => 'Public'
];
public static function idToString(int $id) : string
{
return self::ACCESS_STRINGS[$id] ?? 'Unknown';
}
}
......@@ -10,8 +10,8 @@ namespace Minds\Controllers\api\v1;
use Minds\Api\Exportable;
use Minds\Api\Factory;
use Minds\Common\Access;
use Minds\Core;
use Minds\Entities\Activity;
use Minds\Helpers;
use Minds\Interfaces;
......@@ -93,7 +93,7 @@ class blog implements Interfaces\Api
$export = [];
foreach ($blogs as $blog) {
if ($blog->getOwnerGuid() != Core\Session::getLoggedInUserGuid() && $blog->getAccessId() != 2) {
if ($blog->getOwnerGuid() != Core\Session::getLoggedInUserGuid() && $blog->getAccessId() != Access::PUBLIC) {
continue;
}
$export[] = $blog;
......@@ -157,13 +157,16 @@ class blog implements Interfaces\Api
$header = new Core\Blogs\Header();
$response = [];
$alreadyPublished = false;
$oldAccessId = Access::UNKNOWN;
$editing = isset($pages[0]) && (is_numeric($pages[0]) || Core\Luid::isValid($pages[0]));
if ($editing) {
$blog = $manager->get($pages[0]);
$originallyPublished = $blog->isPublished();
$alreadyPublished = $blog->isPublished();
$oldAccessId = $alreadyPublished ? $blog->getAccessId() : $blog->getDraftAccessId();
} else {
$blog = new Core\Blogs\Blog();
$blog
......@@ -237,9 +240,9 @@ class blog implements Interfaces\Api
}
}
//draft
/* Draft post overrides access_id to Unlisted and saves target accessId to draftAccessId */
if (!$_POST['published'] || $_POST['published'] === 'false') {
$blog->setAccessId(0);
$blog->setAccessId(Access::UNLISTED);
$blog->setDraftAccessId($_POST['access_id']);
} elseif ($blog->getTimePublished() == '') {
$blog->setTimePublished(time());
......@@ -282,7 +285,6 @@ class blog implements Interfaces\Api
}
}
if (isset($_POST['mature']) && $_POST['mature']) {
$user = Core\Session::getLoggedInUser();
......@@ -333,19 +335,10 @@ class blog implements Interfaces\Api
if ($saved) {
$createActivity = new Core\Blogs\Delegates\CreateActivity();
if (
!$editing &&
$blog->isPublished() &&
$blog->getAccessId() == 2
) {
$createActivity->save($blog);
} elseif (
$editing &&
!$originallyPublished &&
$blog->isPublished() &&
$blog->getAccessId() == 2
) {
$createActivity->save($blog);
if ($blog->isPublished() && $blog->getAccessId() == Access::PUBLIC) {
if (!$editing || ($editing && !$alreadyPublished) || ($editing && $oldAccessId == Access::UNLISTED)) {
$createActivity->save($blog);
}
}
$response['guid'] = (string) $blog->getGuid();
......
<?php
namespace Spec\Minds\Common;
use Minds\Common\Access;
use PhpSpec\ObjectBehavior;
class AccessSpec extends ObjectBehavior
{
public function it_should_return_string_for_an_access_id()
{
$this::idToString(Access::UNLISTED)->shouldBe('Unlisted');
}
public function it_should_return_unknown_for_invalid_access_id()
{
$this::idToString(666)->shouldBe('Unknown');
}
}