|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author René Gieling <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
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 Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Polls\Controller; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\AppFramework\Controller; |
|
27
|
|
|
use OCP\AppFramework\Http; |
|
28
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
29
|
|
|
|
|
30
|
|
|
use OCP\IGroupManager; |
|
31
|
|
|
use OCP\IUser; |
|
32
|
|
|
use OCP\IUserManager; |
|
33
|
|
|
use OCP\IConfig; |
|
34
|
|
|
use OCP\IRequest; |
|
35
|
|
|
|
|
36
|
|
|
class SystemController extends Controller { |
|
37
|
|
|
|
|
38
|
|
|
private $systemConfig; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* PageController constructor. |
|
42
|
|
|
* @param String $appName |
|
43
|
|
|
* @param IConfig $systemConfig |
|
44
|
|
|
* @param IRequest $request |
|
45
|
|
|
* @param IGroupManager $groupManager |
|
46
|
|
|
* @param IUserManager $userManager |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
$appName, |
|
50
|
|
|
IGroupManager $groupManager, |
|
51
|
|
|
IUserManager $userManager, |
|
52
|
|
|
IConfig $systemConfig, |
|
53
|
|
|
IRequest $request |
|
54
|
|
|
) { |
|
55
|
|
|
parent::__construct($appName, $request); |
|
56
|
|
|
$this->systemConfig = $systemConfig; |
|
57
|
|
|
$this->groupManager = $groupManager; |
|
|
|
|
|
|
58
|
|
|
$this->userManager = $userManager; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the endor name of the installation ('ownCloud' or 'Nextcloud') |
|
63
|
|
|
* @NoAdminRequired |
|
64
|
|
|
* @return String |
|
65
|
|
|
*/ |
|
66
|
|
|
private function getVendor() { |
|
67
|
|
|
require \OC::$SERVERROOT . '/version.php'; |
|
68
|
|
|
|
|
69
|
|
|
/** @var string $vendor */ |
|
70
|
|
|
return (string) $vendor; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get a list of NC users and groups |
|
75
|
|
|
* @NoAdminRequired |
|
76
|
|
|
* @return DataResponse |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $skipGroups = array(), $skipUsers = array()) { |
|
79
|
|
|
$list = array(); |
|
80
|
|
|
$data = array(); |
|
81
|
|
|
if ($getGroups) { |
|
82
|
|
|
$groups = $this->groupManager->search($query); |
|
83
|
|
|
foreach ($groups as $group) { |
|
84
|
|
|
if (!in_array($group->getGID(), $skipGroups)) { |
|
85
|
|
|
$list[] = [ |
|
86
|
|
|
'id' => $group->getGID(), |
|
87
|
|
|
'user' => $group->getGID(), |
|
88
|
|
|
'type' => 'group', |
|
89
|
|
|
'desc' => 'group', |
|
90
|
|
|
'icon' => 'icon-group', |
|
91
|
|
|
'displayName' => $group->getGID(), |
|
92
|
|
|
'avatarURL' => '' |
|
93
|
|
|
]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if ($getUsers) { |
|
99
|
|
|
$users = $this->userManager->searchDisplayName($query); |
|
100
|
|
|
foreach ($users as $user) { |
|
101
|
|
|
if (!in_array($user->getUID(), $skipUsers)) { |
|
102
|
|
|
$list[] = [ |
|
103
|
|
|
'id' => $user->getUID(), |
|
104
|
|
|
'user' => $user->getUID(), |
|
105
|
|
|
'type' => 'user', |
|
106
|
|
|
'desc' => 'user', |
|
107
|
|
|
'icon' => 'icon-user', |
|
108
|
|
|
'displayName' => $user->getDisplayName(), |
|
109
|
|
|
'avatarURL' => '', |
|
110
|
|
|
'lastLogin' => $user->getLastLogin(), |
|
111
|
|
|
'cloudId' => $user->getCloudId() |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$data['siteusers'] = $list; |
|
118
|
|
|
return new DataResponse($data, Http::STATUS_OK); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get some system informations |
|
123
|
|
|
* @NoAdminRequired |
|
124
|
|
|
* @return DataResponse |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getSystem() { |
|
127
|
|
|
$userId = \OC::$server->getUserSession()->getUser()->getUID(); |
|
128
|
|
|
$data['system'] = [ |
|
|
|
|
|
|
129
|
|
|
'versionArray' => \OCP\Util::getVersion(), |
|
130
|
|
|
'version' => implode('.', \OCP\Util::getVersion()), |
|
131
|
|
|
'vendor' => $this->getVendor(), |
|
132
|
|
|
'language' => $this->systemConfig->getUserValue($userId, 'core', 'lang') |
|
133
|
|
|
]; |
|
134
|
|
|
|
|
135
|
|
|
return new DataResponse($data, Http::STATUS_OK); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|