-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #963 from nextcloud/enh/noid/api-ocs-controller
Make the API controller an OCS controller
- Loading branch information
Showing
18 changed files
with
207 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2022, Julien Veyssier <eneiluj@posteo.net> | ||
* | ||
* @author Julien Veyssier <eneiluj@posteo.net> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\UserOIDC\Controller; | ||
|
||
use OCA\UserOIDC\AppInfo\Application; | ||
use OCA\UserOIDC\Db\UserMapper; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\Files\IRootFolder; | ||
use OCP\Files\NotPermittedException; | ||
use OCP\IRequest; | ||
use OCP\IUserManager; | ||
|
||
class OcsApiController extends OCSController { | ||
|
||
public function __construct( | ||
IRequest $request, | ||
private IRootFolder $root, | ||
private UserMapper $userMapper, | ||
private IUserManager $userManager, | ||
) { | ||
parent::__construct(Application::APP_ID, $request); | ||
} | ||
|
||
/** | ||
* @param int $providerId | ||
* @param string $userId | ||
* @param string|null $displayName | ||
* @param string|null $email | ||
* @param string|null $quota | ||
* @return DataResponse | ||
*/ | ||
public function createUser(int $providerId, string $userId, ?string $displayName = null, | ||
?string $email = null, ?string $quota = null): DataResponse { | ||
$backendUser = $this->userMapper->getOrCreate($providerId, $userId); | ||
$user = $this->userManager->get($backendUser->getUserId()); | ||
|
||
if ($displayName) { | ||
if ($displayName !== $backendUser->getDisplayName()) { | ||
$backendUser->setDisplayName($displayName); | ||
$this->userMapper->update($backendUser); | ||
} | ||
} | ||
|
||
if ($email) { | ||
$user->setSystemEMailAddress($email); | ||
} | ||
|
||
if ($quota) { | ||
$user->setQuota($quota); | ||
} | ||
|
||
$userFolder = $this->root->getUserFolder($user->getUID()); | ||
try { | ||
// copy skeleton | ||
\OC_Util::copySkeleton($user->getUID(), $userFolder); | ||
} catch (NotPermittedException $ex) { | ||
// read only uses | ||
} | ||
|
||
return new DataResponse(['user_id' => $user->getUID()]); | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @return DataResponse | ||
*/ | ||
public function deleteUser(string $userId): DataResponse { | ||
$user = $this->userManager->get($userId); | ||
if (is_null($user) || $user->getBackendClassName() !== 'user_oidc') { | ||
return new DataResponse(['message' => 'User not found'], Http::STATUS_NOT_FOUND); | ||
} | ||
|
||
$user->delete(); | ||
return new DataResponse(['user_id' => $userId], Http::STATUS_OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.