Passed
Push — master ( 1e383c...00d1a5 )
by Roeland
57:56 queued 13:14
created
apps/provisioning_api/lib/Controller/AppsController.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -40,84 +40,84 @@
 block discarded – undo
40 40
 use OCP\IRequest;
41 41
 
42 42
 class AppsController extends OCSController {
43
-	/** @var IAppManager */
44
-	private $appManager;
43
+    /** @var IAppManager */
44
+    private $appManager;
45 45
 
46
-	public function __construct(
47
-		string $appName,
48
-		IRequest $request,
49
-		IAppManager $appManager
50
-	) {
51
-		parent::__construct($appName, $request);
46
+    public function __construct(
47
+        string $appName,
48
+        IRequest $request,
49
+        IAppManager $appManager
50
+    ) {
51
+        parent::__construct($appName, $request);
52 52
 
53
-		$this->appManager = $appManager;
54
-	}
53
+        $this->appManager = $appManager;
54
+    }
55 55
 
56
-	/**
57
-	 * @param string|null $filter
58
-	 * @return DataResponse
59
-	 * @throws OCSException
60
-	 */
61
-	public function getApps(string $filter = null): DataResponse {
62
-		$apps = (new OC_App())->listAllApps();
63
-		$list = [];
64
-		foreach ($apps as $app) {
65
-			$list[] = $app['id'];
66
-		}
67
-		if ($filter) {
68
-			switch ($filter) {
69
-				case 'enabled':
70
-					return new DataResponse(['apps' => \OC_App::getEnabledApps()]);
71
-					break;
72
-				case 'disabled':
73
-					$enabled = OC_App::getEnabledApps();
74
-					return new DataResponse(['apps' => array_diff($list, $enabled)]);
75
-					break;
76
-				default:
77
-					// Invalid filter variable
78
-					throw new OCSException('', 101);
79
-			}
80
-		} else {
81
-			return new DataResponse(['apps' => $list]);
82
-		}
83
-	}
56
+    /**
57
+     * @param string|null $filter
58
+     * @return DataResponse
59
+     * @throws OCSException
60
+     */
61
+    public function getApps(string $filter = null): DataResponse {
62
+        $apps = (new OC_App())->listAllApps();
63
+        $list = [];
64
+        foreach ($apps as $app) {
65
+            $list[] = $app['id'];
66
+        }
67
+        if ($filter) {
68
+            switch ($filter) {
69
+                case 'enabled':
70
+                    return new DataResponse(['apps' => \OC_App::getEnabledApps()]);
71
+                    break;
72
+                case 'disabled':
73
+                    $enabled = OC_App::getEnabledApps();
74
+                    return new DataResponse(['apps' => array_diff($list, $enabled)]);
75
+                    break;
76
+                default:
77
+                    // Invalid filter variable
78
+                    throw new OCSException('', 101);
79
+            }
80
+        } else {
81
+            return new DataResponse(['apps' => $list]);
82
+        }
83
+    }
84 84
 
85
-	/**
86
-	 * @param string $app
87
-	 * @return DataResponse
88
-	 * @throws OCSException
89
-	 */
90
-	public function getAppInfo(string $app): DataResponse {
91
-		$info = $this->appManager->getAppInfo($app);
92
-		if (!is_null($info)) {
93
-			return new DataResponse($info);
94
-		}
85
+    /**
86
+     * @param string $app
87
+     * @return DataResponse
88
+     * @throws OCSException
89
+     */
90
+    public function getAppInfo(string $app): DataResponse {
91
+        $info = $this->appManager->getAppInfo($app);
92
+        if (!is_null($info)) {
93
+            return new DataResponse($info);
94
+        }
95 95
 
96
-		throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND);
97
-	}
96
+        throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND);
97
+    }
98 98
 
99
-	/**
100
-	 * @PasswordConfirmationRequired
101
-	 * @param string $app
102
-	 * @return DataResponse
103
-	 * @throws OCSException
104
-	 */
105
-	public function enable(string $app): DataResponse {
106
-		try {
107
-			$this->appManager->enableApp($app);
108
-		} catch (AppPathNotFoundException $e) {
109
-			throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND);
110
-		}
111
-		return new DataResponse();
112
-	}
99
+    /**
100
+     * @PasswordConfirmationRequired
101
+     * @param string $app
102
+     * @return DataResponse
103
+     * @throws OCSException
104
+     */
105
+    public function enable(string $app): DataResponse {
106
+        try {
107
+            $this->appManager->enableApp($app);
108
+        } catch (AppPathNotFoundException $e) {
109
+            throw new OCSException('The request app was not found', API::RESPOND_NOT_FOUND);
110
+        }
111
+        return new DataResponse();
112
+    }
113 113
 
114
-	/**
115
-	 * @PasswordConfirmationRequired
116
-	 * @param string $app
117
-	 * @return DataResponse
118
-	 */
119
-	public function disable(string $app): DataResponse {
120
-		$this->appManager->disableApp($app);
121
-		return new DataResponse();
122
-	}
114
+    /**
115
+     * @PasswordConfirmationRequired
116
+     * @param string $app
117
+     * @return DataResponse
118
+     */
119
+    public function disable(string $app): DataResponse {
120
+        $this->appManager->disableApp($app);
121
+        return new DataResponse();
122
+    }
123 123
 }
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/AUserData.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -52,166 +52,166 @@
 block discarded – undo
52 52
 
53 53
 abstract class AUserData extends OCSController {
54 54
 
55
-	/** @var IUserManager */
56
-	protected $userManager;
57
-	/** @var IConfig */
58
-	protected $config;
59
-	/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
60
-	protected $groupManager;
61
-	/** @var IUserSession */
62
-	protected $userSession;
63
-	/** @var AccountManager */
64
-	protected $accountManager;
65
-	/** @var IFactory */
66
-	protected $l10nFactory;
67
-
68
-	public function __construct(string $appName,
69
-								IRequest $request,
70
-								IUserManager $userManager,
71
-								IConfig $config,
72
-								IGroupManager $groupManager,
73
-								IUserSession $userSession,
74
-								AccountManager $accountManager,
75
-								IFactory $l10nFactory) {
76
-		parent::__construct($appName, $request);
77
-
78
-		$this->userManager = $userManager;
79
-		$this->config = $config;
80
-		$this->groupManager = $groupManager;
81
-		$this->userSession = $userSession;
82
-		$this->accountManager = $accountManager;
83
-		$this->l10nFactory = $l10nFactory;
84
-	}
85
-
86
-	/**
87
-	 * creates a array with all user data
88
-	 *
89
-	 * @param string $userId
90
-	 * @return array
91
-	 * @throws NotFoundException
92
-	 * @throws OCSException
93
-	 * @throws OCSNotFoundException
94
-	 */
95
-	protected function getUserData(string $userId): array {
96
-		$currentLoggedInUser = $this->userSession->getUser();
97
-
98
-		$data = [];
99
-
100
-		// Check if the target user exists
101
-		$targetUserObject = $this->userManager->get($userId);
102
-		if ($targetUserObject === null) {
103
-			throw new OCSNotFoundException('User does not exist');
104
-		}
105
-
106
-		// Should be at least Admin Or SubAdmin!
107
-		if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
108
-			|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
109
-			$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
110
-		} else {
111
-			// Check they are looking up themselves
112
-			if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
113
-				return $data;
114
-			}
115
-		}
116
-
117
-		// Get groups data
118
-		$userAccount = $this->accountManager->getUser($targetUserObject);
119
-		$groups = $this->groupManager->getUserGroups($targetUserObject);
120
-		$gids = [];
121
-		foreach ($groups as $group) {
122
-			$gids[] = $group->getGID();
123
-		}
124
-
125
-		try {
126
-			# might be thrown by LDAP due to handling of users disappears
127
-			# from the external source (reasons unknown to us)
128
-			# cf. https://github.com/nextcloud/server/issues/12991
129
-			$data['storageLocation'] = $targetUserObject->getHome();
130
-		} catch (NoUserException $e) {
131
-			throw new OCSNotFoundException($e->getMessage(), $e);
132
-		}
133
-
134
-		// Find the data
135
-		$data['id'] = $targetUserObject->getUID();
136
-		$data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
137
-		$data['backend'] = $targetUserObject->getBackendClassName();
138
-		$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
139
-		$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
140
-		$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
141
-		$data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
142
-		$data[IAccountManager::PROPERTY_PHONE] = $userAccount[IAccountManager::PROPERTY_PHONE]['value'];
143
-		$data[IAccountManager::PROPERTY_ADDRESS] = $userAccount[IAccountManager::PROPERTY_ADDRESS]['value'];
144
-		$data[IAccountManager::PROPERTY_WEBSITE] = $userAccount[IAccountManager::PROPERTY_WEBSITE]['value'];
145
-		$data[IAccountManager::PROPERTY_TWITTER] = $userAccount[IAccountManager::PROPERTY_TWITTER]['value'];
146
-		$data['groups'] = $gids;
147
-		$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
148
-		$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
149
-
150
-		$backend = $targetUserObject->getBackend();
151
-		$data['backendCapabilities'] = [
152
-			'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
153
-			'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
154
-		];
155
-
156
-		return $data;
157
-	}
158
-
159
-	/**
160
-	 * Get the groups a user is a subadmin of
161
-	 *
162
-	 * @param string $userId
163
-	 * @return array
164
-	 * @throws OCSException
165
-	 */
166
-	protected function getUserSubAdminGroupsData(string $userId): array {
167
-		$user = $this->userManager->get($userId);
168
-		// Check if the user exists
169
-		if ($user === null) {
170
-			throw new OCSNotFoundException('User does not exist');
171
-		}
172
-
173
-		// Get the subadmin groups
174
-		$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
175
-		$groups = [];
176
-		foreach ($subAdminGroups as $key => $group) {
177
-			$groups[] = $group->getGID();
178
-		}
179
-
180
-		return $groups;
181
-	}
182
-
183
-	/**
184
-	 * @param string $userId
185
-	 * @return array
186
-	 * @throws OCSException
187
-	 */
188
-	protected function fillStorageInfo(string $userId): array {
189
-		try {
190
-			\OC_Util::tearDownFS();
191
-			\OC_Util::setupFS($userId);
192
-			$storage = OC_Helper::getStorageInfo('/');
193
-			$data = [
194
-				'free' => $storage['free'],
195
-				'used' => $storage['used'],
196
-				'total' => $storage['total'],
197
-				'relative' => $storage['relative'],
198
-				'quota' => $storage['quota'],
199
-			];
200
-		} catch (NotFoundException $ex) {
201
-			// User fs is not setup yet
202
-			$user = $this->userManager->get($userId);
203
-			if ($user === null) {
204
-				throw new OCSException('User does not exist', 101);
205
-			}
206
-			$quota = $user->getQuota();
207
-			if ($quota !== 'none') {
208
-				$quota = OC_Helper::computerFileSize($quota);
209
-			}
210
-			$data = [
211
-				'quota' => $quota !== false ? $quota : 'none',
212
-				'used' => 0
213
-			];
214
-		}
215
-		return $data;
216
-	}
55
+    /** @var IUserManager */
56
+    protected $userManager;
57
+    /** @var IConfig */
58
+    protected $config;
59
+    /** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
60
+    protected $groupManager;
61
+    /** @var IUserSession */
62
+    protected $userSession;
63
+    /** @var AccountManager */
64
+    protected $accountManager;
65
+    /** @var IFactory */
66
+    protected $l10nFactory;
67
+
68
+    public function __construct(string $appName,
69
+                                IRequest $request,
70
+                                IUserManager $userManager,
71
+                                IConfig $config,
72
+                                IGroupManager $groupManager,
73
+                                IUserSession $userSession,
74
+                                AccountManager $accountManager,
75
+                                IFactory $l10nFactory) {
76
+        parent::__construct($appName, $request);
77
+
78
+        $this->userManager = $userManager;
79
+        $this->config = $config;
80
+        $this->groupManager = $groupManager;
81
+        $this->userSession = $userSession;
82
+        $this->accountManager = $accountManager;
83
+        $this->l10nFactory = $l10nFactory;
84
+    }
85
+
86
+    /**
87
+     * creates a array with all user data
88
+     *
89
+     * @param string $userId
90
+     * @return array
91
+     * @throws NotFoundException
92
+     * @throws OCSException
93
+     * @throws OCSNotFoundException
94
+     */
95
+    protected function getUserData(string $userId): array {
96
+        $currentLoggedInUser = $this->userSession->getUser();
97
+
98
+        $data = [];
99
+
100
+        // Check if the target user exists
101
+        $targetUserObject = $this->userManager->get($userId);
102
+        if ($targetUserObject === null) {
103
+            throw new OCSNotFoundException('User does not exist');
104
+        }
105
+
106
+        // Should be at least Admin Or SubAdmin!
107
+        if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
108
+            || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
109
+            $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
110
+        } else {
111
+            // Check they are looking up themselves
112
+            if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
113
+                return $data;
114
+            }
115
+        }
116
+
117
+        // Get groups data
118
+        $userAccount = $this->accountManager->getUser($targetUserObject);
119
+        $groups = $this->groupManager->getUserGroups($targetUserObject);
120
+        $gids = [];
121
+        foreach ($groups as $group) {
122
+            $gids[] = $group->getGID();
123
+        }
124
+
125
+        try {
126
+            # might be thrown by LDAP due to handling of users disappears
127
+            # from the external source (reasons unknown to us)
128
+            # cf. https://github.com/nextcloud/server/issues/12991
129
+            $data['storageLocation'] = $targetUserObject->getHome();
130
+        } catch (NoUserException $e) {
131
+            throw new OCSNotFoundException($e->getMessage(), $e);
132
+        }
133
+
134
+        // Find the data
135
+        $data['id'] = $targetUserObject->getUID();
136
+        $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
137
+        $data['backend'] = $targetUserObject->getBackendClassName();
138
+        $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
139
+        $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
140
+        $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
141
+        $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
142
+        $data[IAccountManager::PROPERTY_PHONE] = $userAccount[IAccountManager::PROPERTY_PHONE]['value'];
143
+        $data[IAccountManager::PROPERTY_ADDRESS] = $userAccount[IAccountManager::PROPERTY_ADDRESS]['value'];
144
+        $data[IAccountManager::PROPERTY_WEBSITE] = $userAccount[IAccountManager::PROPERTY_WEBSITE]['value'];
145
+        $data[IAccountManager::PROPERTY_TWITTER] = $userAccount[IAccountManager::PROPERTY_TWITTER]['value'];
146
+        $data['groups'] = $gids;
147
+        $data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
148
+        $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
149
+
150
+        $backend = $targetUserObject->getBackend();
151
+        $data['backendCapabilities'] = [
152
+            'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
153
+            'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
154
+        ];
155
+
156
+        return $data;
157
+    }
158
+
159
+    /**
160
+     * Get the groups a user is a subadmin of
161
+     *
162
+     * @param string $userId
163
+     * @return array
164
+     * @throws OCSException
165
+     */
166
+    protected function getUserSubAdminGroupsData(string $userId): array {
167
+        $user = $this->userManager->get($userId);
168
+        // Check if the user exists
169
+        if ($user === null) {
170
+            throw new OCSNotFoundException('User does not exist');
171
+        }
172
+
173
+        // Get the subadmin groups
174
+        $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
175
+        $groups = [];
176
+        foreach ($subAdminGroups as $key => $group) {
177
+            $groups[] = $group->getGID();
178
+        }
179
+
180
+        return $groups;
181
+    }
182
+
183
+    /**
184
+     * @param string $userId
185
+     * @return array
186
+     * @throws OCSException
187
+     */
188
+    protected function fillStorageInfo(string $userId): array {
189
+        try {
190
+            \OC_Util::tearDownFS();
191
+            \OC_Util::setupFS($userId);
192
+            $storage = OC_Helper::getStorageInfo('/');
193
+            $data = [
194
+                'free' => $storage['free'],
195
+                'used' => $storage['used'],
196
+                'total' => $storage['total'],
197
+                'relative' => $storage['relative'],
198
+                'quota' => $storage['quota'],
199
+            ];
200
+        } catch (NotFoundException $ex) {
201
+            // User fs is not setup yet
202
+            $user = $this->userManager->get($userId);
203
+            if ($user === null) {
204
+                throw new OCSException('User does not exist', 101);
205
+            }
206
+            $quota = $user->getQuota();
207
+            if ($quota !== 'none') {
208
+                $quota = OC_Helper::computerFileSize($quota);
209
+            }
210
+            $data = [
211
+                'quota' => $quota !== false ? $quota : 'none',
212
+                'used' => 0
213
+            ];
214
+        }
215
+        return $data;
216
+    }
217 217
 }
Please login to merge, or discard this patch.