Skip to content

Commit 3b553d0

Browse files
committed
feat: able to set email
Signed-off-by: Vitor Mattos <[email protected]>
1 parent dc46e37 commit 3b553d0

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

lib/Controller/AdminGroupController.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\IRequest;
2727
use OCP\IUser;
2828
use OCP\IUserManager;
29+
use OCP\Mail\IMailer;
2930
use OCP\Security\Events\GenerateSecurePasswordEvent;
3031
use OCP\Security\ISecureRandom;
3132
use Psr\Log\LoggerInterface;
@@ -37,6 +38,7 @@ public function __construct(
3738
protected LoggerInterface $logger,
3839
protected IGroupManager $groupManager,
3940
protected IUserManager $userManager,
41+
protected IMailer $mailer,
4042
protected ISubAdmin $subAdmin,
4143
protected IAppManager $appManager,
4244
protected IAppConfig $appConfig,
@@ -54,6 +56,7 @@ public function __construct(
5456
*
5557
* @param string $groupid ID of the group
5658
* @param string $displayname Display name of the group
59+
* @param string $email Email of admin
5760
* @param string $quota Group quota in "human readable" format. Default value is 1Gb.
5861
* @param list<string> $apps List of app ids to enable
5962
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
@@ -67,13 +70,14 @@ public function __construct(
6770
public function createAdminGroup(
6871
string $groupid,
6972
string $displayname = '',
73+
string $email = '',
7074
string $quota = '1Gb',
7175
array $apps = [],
7276
): DataResponse {
7377
$group = $this->addGroup($groupid, $displayname);
7478
$this->setGroupQuota($groupid, $quota);
7579
$this->enableApps($apps, $groupid);
76-
$user = $this->createUser($groupid, $displayname);
80+
$user = $this->createUser($groupid, $displayname, $email);
7781
$group->addUser($user);
7882
$this->addSubAdmin($user, $group);
7983
return new DataResponse();
@@ -125,7 +129,7 @@ private function addSubAdmin(IUser $user, IGroup $group): void {
125129
$this->subAdmin->createSubAdmin($user, $group);
126130
}
127131

128-
private function createUser($userId, $displayName): IUser {
132+
private function createUser($userId, $displayName, $email): IUser {
129133
$passwordEvent = new GenerateSecurePasswordEvent();
130134
$this->eventDispatcher->dispatchTyped($passwordEvent);
131135
$password = $passwordEvent->getPassword() ?? $this->secureRandom->generate(20);
@@ -140,6 +144,12 @@ private function createUser($userId, $displayName): IUser {
140144
throw $e;
141145
}
142146
}
147+
if ($email !== '') {
148+
if (!$this->mailer->validateMailAddress($email)) {
149+
throw new OCSException('Invalid email');
150+
}
151+
$user->setSystemEMailAddress($email);
152+
}
143153
return $user;
144154
}
145155

@@ -169,6 +179,9 @@ private function setGroupQuota(string $groupId, string $quota): void {
169179
}
170180

171181
private function enableApps(array $appIds, string $groupId): void {
182+
if (!$appIds) {
183+
return;
184+
}
172185
$this->jobList->add(EnableAppsForGroup::class, [
173186
'groupId' => $groupId,
174187
'appIds' => $appIds,

openapi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
"default": "",
8383
"description": "Display name of the group"
8484
},
85+
"email": {
86+
"type": "string",
87+
"default": "",
88+
"description": "Email of admin"
89+
},
8590
"quota": {
8691
"type": "string",
8792
"default": "1Gb",

src/types/openapi/openapi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export interface operations {
8888
* @default
8989
*/
9090
displayname?: string;
91+
/**
92+
* @description Email of admin
93+
* @default
94+
*/
95+
email?: string;
9196
/**
9297
* @description Group quota in "human readable" format. Default value is 1Gb.
9398
* @default 1Gb

0 commit comments

Comments
 (0)