Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
tao_actions_Lock
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 3
90
0.00% covered (danger)
0.00%
0 / 1
 locked
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
30
 release
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
 forceRelease
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2013-2018 Open Assessment Technologies S.A.
19 *
20 */
21
22use oat\tao\model\lock\LockManager;
23use oat\tao\helpers\UserHelper;
24use oat\tao\model\accessControl\AclProxy;
25use oat\generis\model\OntologyAwareTrait;
26
27/**
28 * control the lock on a given resource
29 *
30 * @author plichart
31 * @package taoGroups
32 * @license GPLv2  http://www.opensource.org/licenses/gpl-2.0.php
33 */
34class tao_actions_Lock extends tao_actions_CommonModule
35{
36    use OntologyAwareTrait;
37
38    /**
39     * actions that get prevented by a lock are forwareded to this action
40     * parameter view is currently ignored
41     */
42    public function locked()
43    {
44        $this->defaultData();
45        $resource = $this->getResource($this->getRequestParameter('id'));
46        $lockData = LockManager::getImplementation()->getLockData($resource);
47
48        $this->setData(
49            'topclass-label',
50            $this->hasRequestParameter('topclass-label') ? $this->getRequestParameter('topclass-label') : __('Resource')
51        );
52
53        if (
54            AclProxy::hasAccess(
55                $this->getSession()->getUser(),
56                __CLASS__,
57                'forceRelease',
58                ['uri' => $resource->getUri()]
59            )
60        ) {
61            $this->setData('id', $resource->getUri());
62            $this->setData('forceRelease', true);
63        }
64
65        $this->setData('lockDate', $lockData->getCreationTime());
66        $this->setData('ownerHtml', UserHelper::renderHtmlUser($lockData->getOwnerId()));
67
68        if ($this->hasRequestParameter('view') && $this->hasRequestParameter('ext')) {
69            $this->setView($this->getRequestParameter('view'), $this->getRequestParameter('ext'));
70        } else {
71            $this->setView('Lock/locked.tpl', 'tao');
72        }
73    }
74
75    public function release($uri)
76    {
77        $resource = $this->getResource($uri);
78        try {
79            $userId = $this->getSession()->getUser()->getIdentifier();
80            $success = LockManager::getImplementation()->releaseLock($resource, $userId);
81            return $this->returnJson([
82                'success' => $success,
83                'message' => $success
84                    ? __('%s has been released', $resource->getLabel())
85                    : __('%s could not be released', $resource->getLabel())
86            ]);
87
88            //the connected user is not the owner of the lock
89        } catch (common_exception_Unauthorized $e) {
90            return $this->returnJson([
91                'success' => false,
92                'message' => __('You are not authorised to remove this lock')
93            ]);
94        }
95    }
96
97    public function forceRelease($uri)
98    {
99        $success = LockManager::getImplementation()->forceReleaseLock(
100            $this->getResource($uri)
101        );
102        return $this->returnJson([
103            'success' => $success
104        ]);
105    }
106}