diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 065bdfc..39e3921 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -26,6 +26,7 @@ use OCP\IRequest; use OCP\IUser; use OCP\IUserManager; +use OCP\Mail\IMailer; use OCP\Security\Events\GenerateSecurePasswordEvent; use OCP\Security\ISecureRandom; use Psr\Log\LoggerInterface; @@ -37,6 +38,7 @@ public function __construct( protected LoggerInterface $logger, protected IGroupManager $groupManager, protected IUserManager $userManager, + protected IMailer $mailer, protected ISubAdmin $subAdmin, protected IAppManager $appManager, protected IAppConfig $appConfig, @@ -54,6 +56,7 @@ public function __construct( * * @param string $groupid ID of the group * @param string $displayname Display name of the group + * @param string $email Email of admin * @param string $quota Group quota in "human readable" format. Default value is 1Gb. * @param list $apps List of app ids to enable * @return DataResponse, array{}> @@ -67,13 +70,14 @@ public function __construct( public function createAdminGroup( string $groupid, string $displayname = '', + string $email = '', string $quota = '1Gb', array $apps = [], ): DataResponse { $group = $this->addGroup($groupid, $displayname); $this->setGroupQuota($groupid, $quota); $this->enableApps($apps, $groupid); - $user = $this->createUser($groupid, $displayname); + $user = $this->createUser($groupid, $displayname, $email); $group->addUser($user); $this->addSubAdmin($user, $group); return new DataResponse(); @@ -125,7 +129,7 @@ private function addSubAdmin(IUser $user, IGroup $group): void { $this->subAdmin->createSubAdmin($user, $group); } - private function createUser($userId, $displayName): IUser { + private function createUser($userId, $displayName, $email): IUser { $passwordEvent = new GenerateSecurePasswordEvent(); $this->eventDispatcher->dispatchTyped($passwordEvent); $password = $passwordEvent->getPassword() ?? $this->secureRandom->generate(20); @@ -140,6 +144,12 @@ private function createUser($userId, $displayName): IUser { throw $e; } } + if ($email !== '') { + if (!$this->mailer->validateMailAddress($email)) { + throw new OCSException('Invalid email'); + } + $user->setSystemEMailAddress($email); + } return $user; } @@ -169,6 +179,9 @@ private function setGroupQuota(string $groupId, string $quota): void { } private function enableApps(array $appIds, string $groupId): void { + if (!$appIds) { + return; + } $this->jobList->add(EnableAppsForGroup::class, [ 'groupId' => $groupId, 'appIds' => $appIds, diff --git a/openapi.json b/openapi.json index 90fdf49..7dbb12b 100644 --- a/openapi.json +++ b/openapi.json @@ -82,6 +82,11 @@ "default": "", "description": "Display name of the group" }, + "email": { + "type": "string", + "default": "", + "description": "Email of admin" + }, "quota": { "type": "string", "default": "1Gb", diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 5d4f39a..45f99f0 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -88,6 +88,11 @@ export interface operations { * @default */ displayname?: string; + /** + * @description Email of admin + * @default + */ + email?: string; /** * @description Group quota in "human readable" format. Default value is 1Gb. * @default 1Gb