26
26
use OCP \IRequest ;
27
27
use OCP \IUser ;
28
28
use OCP \IUserManager ;
29
+ use OCP \Mail \IMailer ;
29
30
use OCP \Security \Events \GenerateSecurePasswordEvent ;
30
31
use OCP \Security \ISecureRandom ;
31
32
use Psr \Log \LoggerInterface ;
@@ -37,6 +38,7 @@ public function __construct(
37
38
protected LoggerInterface $ logger ,
38
39
protected IGroupManager $ groupManager ,
39
40
protected IUserManager $ userManager ,
41
+ protected IMailer $ mailer ,
40
42
protected ISubAdmin $ subAdmin ,
41
43
protected IAppManager $ appManager ,
42
44
protected IAppConfig $ appConfig ,
@@ -54,6 +56,7 @@ public function __construct(
54
56
*
55
57
* @param string $groupid ID of the group
56
58
* @param string $displayname Display name of the group
59
+ * @param string $email Email of admin
57
60
* @param string $quota Group quota in "human readable" format. Default value is 1Gb.
58
61
* @param list<string> $apps List of app ids to enable
59
62
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
@@ -67,13 +70,14 @@ public function __construct(
67
70
public function createAdminGroup (
68
71
string $ groupid ,
69
72
string $ displayname = '' ,
73
+ string $ email = '' ,
70
74
string $ quota = '1Gb ' ,
71
75
array $ apps = [],
72
76
): DataResponse {
73
77
$ group = $ this ->addGroup ($ groupid , $ displayname );
74
78
$ this ->setGroupQuota ($ groupid , $ quota );
75
79
$ this ->enableApps ($ apps , $ groupid );
76
- $ user = $ this ->createUser ($ groupid , $ displayname );
80
+ $ user = $ this ->createUser ($ groupid , $ displayname, $ email );
77
81
$ group ->addUser ($ user );
78
82
$ this ->addSubAdmin ($ user , $ group );
79
83
return new DataResponse ();
@@ -125,7 +129,7 @@ private function addSubAdmin(IUser $user, IGroup $group): void {
125
129
$ this ->subAdmin ->createSubAdmin ($ user , $ group );
126
130
}
127
131
128
- private function createUser ($ userId , $ displayName ): IUser {
132
+ private function createUser ($ userId , $ displayName, $ email ): IUser {
129
133
$ passwordEvent = new GenerateSecurePasswordEvent ();
130
134
$ this ->eventDispatcher ->dispatchTyped ($ passwordEvent );
131
135
$ password = $ passwordEvent ->getPassword () ?? $ this ->secureRandom ->generate (20 );
@@ -140,6 +144,12 @@ private function createUser($userId, $displayName): IUser {
140
144
throw $ e ;
141
145
}
142
146
}
147
+ if ($ email !== '' ) {
148
+ if (!$ this ->mailer ->validateMailAddress ($ email )) {
149
+ throw new OCSException ('Invalid email ' );
150
+ }
151
+ $ user ->setSystemEMailAddress ($ email );
152
+ }
143
153
return $ user ;
144
154
}
145
155
@@ -169,6 +179,9 @@ private function setGroupQuota(string $groupId, string $quota): void {
169
179
}
170
180
171
181
private function enableApps (array $ appIds , string $ groupId ): void {
182
+ if (!$ appIds ) {
183
+ return ;
184
+ }
172
185
$ this ->jobList ->add (EnableAppsForGroup::class, [
173
186
'groupId ' => $ groupId ,
174
187
'appIds ' => $ appIds ,
0 commit comments