Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
14.29% covered (danger)
14.29%
2 / 14
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractAdmin
14.29% covered (danger)
14.29%
2 / 14
33.33% covered (danger)
33.33%
1 / 3
28.67
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 validateAccessPermission
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 disabledAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * VuFind Admin Controller Base
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Controller
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Page
28 */
29
30namespace VuFindAdmin\Controller;
31
32use Laminas\Mvc\MvcEvent;
33use Laminas\ServiceManager\ServiceLocatorInterface;
34
35/**
36 * VuFind Admin Controller Base
37 *
38 * @category VuFind
39 * @package  Controller
40 * @author   Demian Katz <demian.katz@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org Main Page
43 */
44class AbstractAdmin extends \VuFind\Controller\AbstractBase
45{
46    /**
47     * Constructor
48     *
49     * @param ServiceLocatorInterface $sm Service locator
50     */
51    public function __construct(ServiceLocatorInterface $sm)
52    {
53        parent::__construct($sm);
54        $this->accessPermission = 'access.AdminModule';
55    }
56
57    /**
58     * Use preDispatch event to block access when appropriate.
59     *
60     * @param MvcEvent $e Event object
61     *
62     * @return void
63     */
64    public function validateAccessPermission(MvcEvent $e)
65    {
66        // Disable search box in Admin module:
67        $this->layout()->searchbox = false;
68
69        // If we're using the "disabled" action, we don't need to do any further
70        // checking to see if we are disabled!!
71        $routeMatch = $e->getRouteMatch();
72        if (strtolower($routeMatch->getParam('action')) == 'disabled') {
73            return;
74        }
75
76        // Block access to everyone when module is disabled:
77        $config = $this->getConfig();
78        if (!isset($config->Site->admin_enabled) || !$config->Site->admin_enabled) {
79            $pluginManager  = $this->serviceLocator
80                ->get(\Laminas\Mvc\Controller\PluginManager::class);
81            $redirectPlugin = $pluginManager->get('redirect');
82            return $redirectPlugin->toRoute('admin/disabled');
83        }
84
85        // Call parent method to do permission checking:
86        parent::validateAccessPermission($e);
87    }
88
89    /**
90     * Display disabled message.
91     *
92     * @return \Laminas\View\Model\ViewModel
93     */
94    public function disabledAction()
95    {
96        return $this->createViewModel();
97    }
98}