GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AdminDelegationPlugin::widgets()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.2
cc 4
eloc 9
nc 5
nop 1
1
<?php
2
/**
3
 * Copyright (c) STMicroelectronics, 2009. All Rights Reserved.
4
 *
5
 * Originally written by Manuel Vacelet, 2009
6
 *
7
 * This file is a part of Codendi.
8
 *
9
 * Codendi is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Codendi 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 Codendi; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23
24
/**
25
 * AdminDelegationPlugin
26
 * 
27
 * This plugin is made of two parts:
28
 * - The admin one, that allows to delegate some rights (called services to 
29
 *   selected users).
30
 * - The user one, made of widget in personal page, for the granted (selected)
31
 *   user to access to the information.
32
 * 
33
 * Each admin action (grant/revoke) is logged but as of today, the log is only in
34
 * the database.
35
 * 
36
 * There is no table dedicated to store services, the services are identified by
37
 * their id and a label. The id is a constant in the AdminDelegation_Service class.
38
 * 
39
 * @see AdminDelegation_Service
40
 * 
41
 */
42
class AdminDelegationPlugin extends Plugin {
43
44
    public function __construct($id) {
45
        parent::__construct($id);
46
        $this->_addHook('cssfile',                'cssFile',                false);
47
        $this->_addHook('site_admin_option_hook', 'site_admin_option_hook', false);
48
        $this->_addHook('widget_instance',        'widget_instance',        false);
49
        $this->_addHook('widgets',                'widgets',                false);
50
    }
51
52
    public function getPluginInfo() {
53
        if (!is_a($this->pluginInfo, 'AdminDelegationPluginInfo')) {
54
            include_once 'AdminDelegationPluginInfo.class.php';
55
            $this->pluginInfo = new AdminDelegationPluginInfo($this);
56
        }
57
        return $this->pluginInfo;
58
    }
59
60
    /**
61
     * Check if current user is allowed to use given widget
62
     * 
63
     * @param String  $widget
64
     * 
65
     * @return Boolean
66
     */
67
    protected function _userCanViewWidget($widget) {
68
        $um      = UserManager::instance();
69
        $user    = $um->getCurrentUser();
70
        if ($user) {
71
            $service = AdminDelegation_Service::getServiceFromWidget($widget);
72
            if ($service) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $service of type integer|false is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
73
                $usm = new AdminDelegation_UserServiceManager();
74
                return $usm->isUserGrantedForService($user, $service);
75
            }
76
        }
77
        return false;
78
    }
79
80
    public function cssFile($params) {
81
        // Only show the stylesheet if we're actually in the Docman pages.
82
        // This stops styles inadvertently clashing with the main site.
83
        if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0 ||
84
            strpos($_SERVER['REQUEST_URI'], '/widgets/') === 0
85
        ) {
86
            echo '<link rel="stylesheet" type="text/css" href="'.$this->getThemePath().'/css/style.css" />'."\n";
87
        }
88
    }
89
    
90
    /**
91
     * Hook: admin link to plugin
92
     *
93
     * @param Array $params
94
     */
95
    public function site_admin_option_hook($params) {
96
        echo '<li><a href="'.$this->getPluginPath().'/">Admin delegation</a></li>';
97
    }
98
99
    /**
100
     * Hook: event raised when widget are instanciated
101
     * 
102
     * @param Array $params
103
     */
104
    public function widget_instance($params) {
105
        if ($params['widget'] == 'admindelegation' && $this->_userCanViewWidget('admindelegation')) {
106
            include_once 'AdminDelegation_UserWidget.class.php';
107
            $params['instance'] = new AdminDelegation_UserWidget($this);
108
        }
109
        if ($params['widget'] == 'admindelegation_projects' && $this->_userCanViewWidget('admindelegation_projects')) {
110
            include_once 'AdminDelegation_ShowProjectWidget.class.php';
111
            $params['instance'] = new AdminDelegation_ShowProjectWidget($this);
112
        }
113
         
114
    }
115
116
    /**
117
     * Hook: event raised when user lists all available widget
118
     *
119
     * @param Array $params
120
     */
121
    public function widgets($params) {
122
        include_once 'common/widget/WidgetLayoutManager.class.php';
123
        if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) {
124
            if ($this->_userCanViewWidget('admindelegation')) {
125
                include_once 'AdminDelegation_UserWidget.class.php';
126
                $params['codendi_widgets'][] = 'admindelegation';
127
            }
128
            if ($this->_userCanViewWidget('admindelegation_projects')) {
129
                include_once 'AdminDelegation_ShowProjectWidget.class.php';
130
                $params['codendi_widgets'][] = 'admindelegation_projects';
131
            }
132
        }
133
    }
134
}
135
136
?>