Skip to content
Commits on Source (2)
<?php
namespace Minds\Common;
use ReflectionClass;
abstract class ChannelMode
{
const OPEN = 0;
const MODERATED = 1;
const CLOSED = 2;
final public static function toArray() : array
{
return (new ReflectionClass(static::class))->getConstants();
}
final public static function isValid($value) : bool
{
return in_array($value, static::toArray());
}
}
......@@ -12,6 +12,7 @@ use Minds\Helpers;
use Minds\Interfaces;
use Minds\Entities;
use Minds\Api\Factory;
use Minds\Common\ChannelMode;
use ElggFile;
class channel implements Interfaces\Api
......@@ -242,6 +243,10 @@ class channel implements Interfaces\Api
}
}
if (isset($_POST['mode']) && ChannelMode::isValid($_POST['mode'])) {
$update['mode'] = $_POST['mode'];
}
if (isset($_POST['social_profiles']) && is_array($_POST['social_profiles'])) {
$profiles = [];
......
......@@ -4,6 +4,7 @@ namespace Minds\Core\Permissions;
use Minds\Core\Di\Di;
use Minds\Core\Permissions\Permissions;
use Minds\Core\EntitiesBuilder;
/*
* Manager for managing role based permissions
......@@ -46,7 +47,7 @@ class Manager
}
/** @var Permissions */
$permissions = new Permissions($user);
$permissions = new Permissions($user, null, $entitiesBuilder);
if (is_array($entities)) {
$permissions->calculate($entities);
}
......
......@@ -39,6 +39,7 @@ class Permissions implements \JsonSerializable
public function __construct(User $user, Roles $roles = null, EntitiesBuilder $entitiesBuilder = null)
{
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->roles = $roles ?: new Roles();
$this->user = $user;
$this->isAdmin = $user->isAdmin();
......
......@@ -3,6 +3,7 @@ namespace Minds\Entities;
use Minds\Core;
use Minds\Helpers;
use Minds\Common\ChannelMode;
/**
* User Entity
......@@ -10,7 +11,6 @@ use Minds\Helpers;
*/
class User extends \ElggUser
{
public $fullExport = true;
public $exportCounts = false;
......@@ -53,6 +53,7 @@ class User extends \ElggUser
$this->attributes['canary'] = 0;
$this->attributes['onchain_booster'] = null;
$this->attributes['toaster_notifications'] = 1;
$this->attributes['mode'] = ChannelMode::OPEN;
parent::initializeAttributes();
}
......@@ -741,6 +742,7 @@ class User extends \ElggUser
$export['theme'] = $this->getTheme();
$export['onchain_booster'] = $this->getOnchainBooster();
$export['toaster_notifications'] = $this->getToasterNotifications();
$export['mode'] = $this->getMode();
if (is_string($export['social_profiles'])) {
$export['social_profiles'] = json_decode($export['social_profiles']);
......@@ -990,7 +992,8 @@ class User extends \ElggUser
'canary',
'theme',
'onchain_booster',
'toaster_notifications'
'toaster_notifications',
'mode'
));
}
......@@ -1090,9 +1093,30 @@ class User extends \ElggUser
/**
* Set on/off toaster notifications
* @return User
*/
public function setToasterNotifications($enabled = true)
{
$this->toaster_notifications = $enabled ? 1 : 0;
return $this;
}
/**
* Returns channel mode value
* @return integer channel mode
*/
public function getMode()
{
return (int) $this->mode;
}
/**
* Sets the channel mode
* @return User
*/
public function setMode(int $mode) {
$this->mode = $mode;
return $this;
}
}
......@@ -6,6 +6,7 @@ use Minds\Entities\User;
use Minds\Core\Di\Di;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Minds\Common\ChannelMode;
class UserSpec extends ObjectBehavior
{
......@@ -49,4 +50,20 @@ class UserSpec extends ObjectBehavior
$this->setOnchainBooster(1560192357);
$this->isOnchainBooster()->shouldReturn(false);
}
function it_should_have_a_default_mode_of_open() {
$this->getMode()->shouldEqual(ChannelMode::OPEN);
}
function it_should_assign_channel_modes() {
$this->setMode(ChannelMode::CLOSED);
$this->getMode()->shouldEqual(ChannelMode::CLOSED);
$this->setMode(ChannelMode::MODERATED);
$this->getMode()->shouldEqual(ChannelMode::MODERATED);
}
function it_should_export_values() {
$export = $this->export()->getWrappedObject();
expect($export['mode'])->shouldEqual(ChannelMode::OPEN);
}
}
......@@ -472,7 +472,8 @@ $CONFIG->set('features', [
'top-feeds' => true,
'cassandra-notifications' => true,
'dark-mode' => true,
'allow-comments-toggle' => false
'allow-comments-toggle' => false,
'permissions' => false
]);
$CONFIG->set('email', [
......