-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keep initial api controller for backward compatibility
Signed-off-by: Julien Veyssier <[email protected]>
- Loading branch information
Showing
3 changed files
with
113 additions
and
5 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
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 <[email protected]> | ||
* | ||
* @author Julien Veyssier <[email protected]> | ||
* | ||
* @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); | ||
} | ||
} |