<commit_before><?php
/**
 * Minds Group API
 * Admin Queue Reviews endpoint
 */
namespace Minds\Controllers\api\v1\groups;

use Minds\Core;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class review implements Interfaces\Api
{
    public function get($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $user = Core\Session::getLoggedInUser();

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');
        $feeds->setGroup($group);

        $count = $feeds->count();

        if (isset($pages[1]) && $pages[1] == 'count') {
            return Factory::response([
                'adminqueue:count' => $count
            ]);
        }

        $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 12;
        $offset = isset($_GET['offset']) ? $_GET['offset'] : '';

        $result = $feeds->getAll([ 'limit' => $limit, 'offset' => $offset ]);

        return Factory::response([
            'activity' => Factory::exportable($result['data']),
            'adminqueue:count' => $count,
            'load-next' => $result['next']
        ]);
    }

    public function post($pages)
    {
        return Factory::response([]);
    }

    public function put($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $activity = Entities\Factory::build($pages[1]);
        $user = Core\Session::getLoggedInUser();

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');

        $done = $feeds->setGroup($group)
            ->approve($activity);

        if ($done) {
            return Factory::response([]);
        } else {
            return Factory::response([
                'status' => 'error',
                'message' => 'Cannot approve activity'
            ]);
        }
    }

    public function delete($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $activity = Entities\Factory::build($pages[1]);
        $user = Core\Session::getLoggedInUser();

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');

        $done = $feeds->setGroup($group)
            ->reject($activity);

        if ($done) {
            return Factory::response([]);
        } else {
            return Factory::response([
                'status' => 'error',
                'message' => 'Cannot approve activity'
            ]);
        }
    }
}
<commit_msg>[Sprint/PinkPanther](fix): Return error if the provided group is not found by group report. #874<commit_after><?php
/**
 * Minds Group API
 * Admin Queue Reviews endpoint
 */
namespace Minds\Controllers\api\v1\groups;

use Minds\Core;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class review implements Interfaces\Api
{
    public function get($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $user = Core\Session::getLoggedInUser();

        if (!$group) {
            return Factory::response([
                'status' => 'error',
                'message' => 'Group not found'
            ]);
        }

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');
        $feeds->setGroup($group);

        $count = $feeds->count();

        if (isset($pages[1]) && $pages[1] == 'count') {
            return Factory::response([
                'adminqueue:count' => $count
            ]);
        }

        $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 12;
        $offset = isset($_GET['offset']) ? $_GET['offset'] : '';

        $result = $feeds->getAll([ 'limit' => $limit, 'offset' => $offset ]);

        return Factory::response([
            'activity' => Factory::exportable($result['data']),
            'adminqueue:count' => $count,
            'load-next' => $result['next']
        ]);
    }

    public function post($pages)
    {
        return Factory::response([]);
    }

    public function put($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $activity = Entities\Factory::build($pages[1]);
        $user = Core\Session::getLoggedInUser();

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');

        $done = $feeds->setGroup($group)
            ->approve($activity);

        if ($done) {
            return Factory::response([]);
        } else {
            return Factory::response([
                'status' => 'error',
                'message' => 'Cannot approve activity'
            ]);
        }
    }

    public function delete($pages)
    {
        Factory::isLoggedIn();

        $group = Entities\Factory::build($pages[0]);
        $activity = Entities\Factory::build($pages[1]);
        $user = Core\Session::getLoggedInUser();

        if (!$group->isOwner($user) && !$group->isModerator($user)) {
            return Factory::response([
                'status' => 'error',
                'message' => 'You don\'t have enough permissions'
            ]);
        }

        /** @var Core\Groups\Feeds $feeds */
        $feeds = Core\Di\Di::_()->get('Groups\Feeds');

        $done = $feeds->setGroup($group)
            ->reject($activity);

        if ($done) {
            return Factory::response([]);
        } else {
            return Factory::response([
                'status' => 'error',
                'message' => 'Cannot approve activity'
            ]);
        }
    }
}

{'fraction_non_alphanumeric': 0.17764120573602576, 'fraction_numerical': 0.0033655253146034534, 'mean_word_length': 1.896186440677966, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3206047', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1953, 'n_words': 375}