6363use OCP \IConfig ;
6464use OCP \IGroup ;
6565use OCP \IGroupManager ;
66+ use OCP \IL10N ;
6667use OCP \IPhoneNumberUtil ;
6768use OCP \IRequest ;
6869use OCP \IURLGenerator ;
7980 * @psalm-import-type Provisioning_APIUserDetails from ResponseDefinitions
8081 */
8182class UsersController extends AUserData {
82- /** @var IURLGenerator */
83- protected $ urlGenerator ;
84- /** @var LoggerInterface */
85- private $ logger ;
86- /** @var IFactory */
87- protected $ l10nFactory ;
88- /** @var NewUserMailHelper */
89- private $ newUserMailHelper ;
90- /** @var ISecureRandom */
91- private $ secureRandom ;
92- /** @var RemoteWipe */
93- private $ remoteWipe ;
94- /** @var KnownUserService */
95- private $ knownUserService ;
96- /** @var IEventDispatcher */
97- private $ eventDispatcher ;
83+
84+ private IL10N $ l10n ;
9885
9986 public function __construct (
10087 string $ appName ,
@@ -104,14 +91,14 @@ public function __construct(
10491 IGroupManager $ groupManager ,
10592 IUserSession $ userSession ,
10693 IAccountManager $ accountManager ,
107- IURLGenerator $ urlGenerator ,
108- LoggerInterface $ logger ,
10994 IFactory $ l10nFactory ,
110- NewUserMailHelper $ newUserMailHelper ,
111- ISecureRandom $ secureRandom ,
112- RemoteWipe $ remoteWipe ,
113- KnownUserService $ knownUserService ,
114- IEventDispatcher $ eventDispatcher ,
95+ private IURLGenerator $ urlGenerator ,
96+ private LoggerInterface $ logger ,
97+ private NewUserMailHelper $ newUserMailHelper ,
98+ private ISecureRandom $ secureRandom ,
99+ private RemoteWipe $ remoteWipe ,
100+ private KnownUserService $ knownUserService ,
101+ private IEventDispatcher $ eventDispatcher ,
115102 private IPhoneNumberUtil $ phoneNumberUtil ,
116103 ) {
117104 parent ::__construct (
@@ -125,14 +112,7 @@ public function __construct(
125112 $ l10nFactory
126113 );
127114
128- $ this ->urlGenerator = $ urlGenerator ;
129- $ this ->logger = $ logger ;
130- $ this ->l10nFactory = $ l10nFactory ;
131- $ this ->newUserMailHelper = $ newUserMailHelper ;
132- $ this ->secureRandom = $ secureRandom ;
133- $ this ->remoteWipe = $ remoteWipe ;
134- $ this ->knownUserService = $ knownUserService ;
135- $ this ->eventDispatcher = $ eventDispatcher ;
115+ $ this ->l10n = $ l10nFactory ->get ($ appName );
136116 }
137117
138118 /**
@@ -437,21 +417,21 @@ public function addUser(
437417
438418 if ($ this ->userManager ->userExists ($ userid )) {
439419 $ this ->logger ->error ('Failed addUser attempt: User already exists. ' , ['app ' => 'ocs_api ' ]);
440- throw new OCSException ($ this ->l10nFactory -> get ( ' provisioning_api ' ) ->t ('User already exists ' ), 102 );
420+ throw new OCSException ($ this ->l10n ->t ('User already exists ' ), 102 );
441421 }
442422
443423 if ($ groups !== []) {
444424 foreach ($ groups as $ group ) {
445425 if (!$ this ->groupManager ->groupExists ($ group )) {
446- throw new OCSException (' group ' . $ group . ' does not exist ' , 104 );
426+ throw new OCSException ($ this -> l10n -> t ( ' Group %1$s does not exist ', [ $ group ]) , 104 );
447427 }
448428 if (!$ isAdmin && !$ subAdminManager ->isSubAdminOfGroup ($ user , $ this ->groupManager ->get ($ group ))) {
449- throw new OCSException (' insufficient privileges for group ' . $ group , 105 );
429+ throw new OCSException ($ this -> l10n -> t ( ' Insufficient privileges for group %1$s ' , [ $ group]) , 105 );
450430 }
451431 }
452432 } else {
453433 if (!$ isAdmin ) {
454- throw new OCSException (' no group specified (required for subadmins) ' , 106 );
434+ throw new OCSException ($ this -> l10n -> t ( ' No group specified (required for sub-admins) ' ) , 106 );
455435 }
456436 }
457437
@@ -461,15 +441,15 @@ public function addUser(
461441 $ group = $ this ->groupManager ->get ($ groupid );
462442 // Check if group exists
463443 if ($ group === null ) {
464- throw new OCSException ('Subadmin group does not exist ' , 102 );
444+ throw new OCSException ('Sub-admin group does not exist ' , 102 );
465445 }
466446 // Check if trying to make subadmin of admin group
467447 if ($ group ->getGID () === 'admin ' ) {
468- throw new OCSException ('Cannot create subadmins for admin group ' , 103 );
448+ throw new OCSException ('Cannot create sub-admins for admin group ' , 103 );
469449 }
470450 // Check if has permission to promote subadmins
471451 if (!$ subAdminManager ->isSubAdminOfGroup ($ user , $ group ) && !$ isAdmin ) {
472- throw new OCSForbiddenException ('No permissions to promote subadmins ' );
452+ throw new OCSForbiddenException ('No permissions to promote sub-admins ' );
473453 }
474454 $ subadminGroups [] = $ group ;
475455 }
@@ -545,7 +525,7 @@ public function addUser(
545525
546526 // Send new user mail only if a mail is set
547527 if ($ email !== '' ) {
548- $ newUser ->setEMailAddress ($ email );
528+ $ newUser ->setSystemEMailAddress ($ email );
549529 if ($ this ->config ->getAppValue ('core ' , 'newUser.sendEmail ' , 'yes ' ) === 'yes ' ) {
550530 try {
551531 $ emailTemplate = $ this ->newUserMailHelper ->generateTemplate ($ newUser , $ generatePasswordResetToken );
@@ -1058,7 +1038,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10581038 break ;
10591039 case IAccountManager::PROPERTY_EMAIL :
10601040 if (filter_var ($ value , FILTER_VALIDATE_EMAIL ) || $ value === '' ) {
1061- $ targetUser ->setEMailAddress ($ value );
1041+ $ targetUser ->setSystemEMailAddress ($ value );
10621042 } else {
10631043 throw new OCSException ('' , 102 );
10641044 }
@@ -1415,11 +1395,11 @@ public function removeFromGroup(string $userId, string $groupid): DataResponse {
14151395 if ($ targetUser ->getUID () === $ loggedInUser ->getUID ()) {
14161396 if ($ this ->groupManager ->isAdmin ($ loggedInUser ->getUID ())) {
14171397 if ($ group ->getGID () === 'admin ' ) {
1418- throw new OCSException ('Cannot remove yourself from the admin group ' , 105 );
1398+ throw new OCSException ($ this -> l10n -> t ( 'Cannot remove yourself from the admin group ' ) , 105 );
14191399 }
14201400 } else {
14211401 // Not an admin, so the user must be a subadmin of this group, but that is not allowed.
1422- throw new OCSException ('Cannot remove yourself from this group as you are a SubAdmin ' , 105 );
1402+ throw new OCSException ($ this -> l10n -> t ( 'Cannot remove yourself from this group as you are a sub-admin ' ) , 105 );
14231403 }
14241404 } elseif (!$ this ->groupManager ->isAdmin ($ loggedInUser ->getUID ())) {
14251405 /** @var IGroup[] $subAdminGroups */
@@ -1432,7 +1412,7 @@ public function removeFromGroup(string $userId, string $groupid): DataResponse {
14321412
14331413 if (count ($ userSubAdminGroups ) <= 1 ) {
14341414 // Subadmin must not be able to remove a user from all their subadmin groups.
1435- throw new OCSException ('Not viable to remove user from the last group you are SubAdmin of ' , 105 );
1415+ throw new OCSException ($ this -> l10n -> t ( 'Not viable to remove user from the last group you are sub-admin of ' ) , 105 );
14361416 }
14371417 }
14381418
@@ -1459,15 +1439,15 @@ public function addSubAdmin(string $userId, string $groupid): DataResponse {
14591439
14601440 // Check if the user exists
14611441 if ($ user === null ) {
1462- throw new OCSException ('User does not exist ' , 101 );
1442+ throw new OCSException ($ this -> l10n -> t ( 'User does not exist ' ) , 101 );
14631443 }
14641444 // Check if group exists
14651445 if ($ group === null ) {
1466- throw new OCSException ('Group does not exist ' , 102 );
1446+ throw new OCSException ($ this -> l10n -> t ( 'Group does not exist ' ) , 102 );
14671447 }
14681448 // Check if trying to make subadmin of admin group
14691449 if ($ group ->getGID () === 'admin ' ) {
1470- throw new OCSException ('Cannot create subadmins for admin group ' , 103 );
1450+ throw new OCSException ($ this -> l10n -> t ( 'Cannot create sub-admins for admin group ' ) , 103 );
14711451 }
14721452
14731453 $ subAdminManager = $ this ->groupManager ->getSubAdmin ();
@@ -1500,15 +1480,15 @@ public function removeSubAdmin(string $userId, string $groupid): DataResponse {
15001480
15011481 // Check if the user exists
15021482 if ($ user === null ) {
1503- throw new OCSException ('User does not exist ' , 101 );
1483+ throw new OCSException ($ this -> l10n -> t ( 'User does not exist ' ) , 101 );
15041484 }
15051485 // Check if the group exists
15061486 if ($ group === null ) {
1507- throw new OCSException ('Group does not exist ' , 101 );
1487+ throw new OCSException ($ this -> l10n -> t ( 'Group does not exist ' ) , 101 );
15081488 }
15091489 // Check if they are a subadmin of this said group
15101490 if (!$ subAdminManager ->isSubAdminOfGroup ($ user , $ group )) {
1511- throw new OCSException ('User is not a subadmin of this group ' , 102 );
1491+ throw new OCSException ($ this -> l10n -> t ( 'User is not a sub-admin of this group ' ) , 102 );
15121492 }
15131493
15141494 // Go
@@ -1562,7 +1542,7 @@ public function resendWelcomeMessage(string $userId): DataResponse {
15621542
15631543 $ email = $ targetUser ->getEMailAddress ();
15641544 if ($ email === '' || $ email === null ) {
1565- throw new OCSException ('Email address not available ' , 101 );
1545+ throw new OCSException ($ this -> l10n -> t ( 'Email address not available ' ) , 101 );
15661546 }
15671547
15681548 try {
@@ -1576,7 +1556,7 @@ public function resendWelcomeMessage(string $userId): DataResponse {
15761556 'exception ' => $ e ,
15771557 ]
15781558 );
1579- throw new OCSException ('Sending email failed ' , 102 );
1559+ throw new OCSException ($ this -> l10n -> t ( 'Sending email failed ' ) , 102 );
15801560 }
15811561
15821562 return new DataResponse ();
0 commit comments