This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
RestipPlugin.class.php
95 lines (84 loc) · 3.2 KB
/
RestipPlugin.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
require_once 'classes/APIPlugin.php';
/**
* RestipPlugin.class.php
*
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @version 0 alpha
*/
class RestipPlugin extends StudIPPlugin implements SystemPlugin, HomepagePlugin
{
/**
*
**/
public function __construct()
{
parent::__construct();
if ($GLOBALS['perm']->have_perm('root')) {
$navigation = new AutoNavigation(_('Rest-API-Plugin'));
$navigation->setURL(PluginEngine::getLink('restipplugin/admin'));
Navigation::addItem('/admin/config/oauth', $navigation);
}
$config = Config::getInstance();
if (!$config['OAUTH_ENABLED']) {
return;
}
if ($GLOBALS['perm']->have_perm('autor')) {
$navigation = new AutoNavigation(_('Apps'));
$navigation->setURL(PluginEngine::getLink('restipplugin/user'));
if (Navigation::hasItem('/links/settings')) {
Navigation::addItem('/links/settings/oauth', $navigation);
} elseif (Navigation::hasItem('/profile/settings')) {
Navigation::addItem('/profile/settings/oauth', $navigation);
}
}
}
/**
*
**/
public function perform ($unconsumed_path)
{
require_once 'config_plugin.inc.php';
require_once 'bootstrap.php';
if (method_exists($this, 'addStylesheet')) {
$this->addStylesheet('assets/form-settings.less');
$this->addStylesheet('assets/oauth.less');
} else {
PageLayout::addStylesheet($this->getPluginURL() . '/assets/form-settings.css');
PageLayout::addStylesheet($this->getPluginURL() . '/assets/oauth.css');
}
PageLayout::addScript($this->getPluginURL() . '/assets/oauth.js');
$dispatcher = new Trails_Dispatcher(
$this->getPluginPath() . DIRECTORY_SEPARATOR . 'app',
rtrim(PluginEngine::getLink($this, array(), null), '/'),
'admin'
);
$dispatcher->plugin = $this;
$dispatcher->dispatch($unconsumed_path);
}
/**
* Fake homepage plugin to ensure plugin gets loaded first
**/
public function getHomepageTemplate($user_id)
{
return null;
}
/**
*
**/
public static function onEnable($pluginId)
{
# TODO performance - use cache on success ?
$role_persistence = new RolePersistence;
$plugin_roles = $role_persistence->getAssignedPluginRoles($pluginId);
$role_names = array_map(function ($role) { return $role->getRolename(); }, $plugin_roles);
if (!in_array('Nobody', $role_names)) {
$message = _('Das OAuth-Plugin ist aktiviert, aber nicht für die Rolle "Nobody" freigegeben.');
$details = array();
$details[] = _('Dies behindert die Kommunikation externer Applikationen mit dem System.');
$details[] = sprintf(_('Klicken Sie <a href="%s">hier</a>, um die Rollenzuweisung zu bearbeiten.'),
URLHelper::getLink('dispatch.php/admin/role/assign_plugin_role/' . $pluginId));
PageLayout::postMessage(MessageBox::info($message, $details));
}
}
}