@@ -277,4 +277,45 @@ public function testRemoveNonExistingUser()
277
277
$ this ->expectException (ClientException::class);
278
278
$ this ->client ->removeUser ($ email );
279
279
}
280
+
281
+ public function testNormalUserCanDeleteUserWhenHavingFeature ()
282
+ {
283
+ $ featureName = 'can-manage-users ' ;
284
+
285
+ $ token = $ this ->normalUserClient ->verifyToken ();
286
+ $ this ->assertArrayHasKey ('user ' , $ token );
287
+ $ userId = $ token ['user ' ]['id ' ];
288
+
289
+ $ this ->client ->removeUserFeature ($ userId , $ featureName );
290
+
291
+ $ organization = $ this ->client ->createOrganization ($ this ->testMaintainerId , ['name ' => 'ToRemoveOrg-1 ' ]);
292
+ $ project = $ this ->client ->createProject ($ organization ['id ' ], [
293
+ 'name ' => 'ToRemoveProj-1 ' ,
294
+ 'dataRetentionTimeInDays ' => 1 ,
295
+ ]);
296
+ $ email = 'devel-tests+remove ' . uniqid () . '@keboola.com ' ;
297
+
298
+ $ this ->client ->addUserToProject ($ project ['id ' ], ['email ' => $ email ]);
299
+ $ newUser = $ this ->client ->getUser ($ email );
300
+
301
+ try {
302
+ // Remove user by normal user without feature
303
+ $ this ->normalUserClient ->removeUser ($ newUser ['id ' ]);
304
+ $ this ->fail ('Normal user cannot delete user ' );
305
+ } catch (ClientException $ e ) {
306
+ $ this ->assertEquals (403 , $ e ->getCode ());
307
+ $ this ->assertEquals ('accessDenied ' , $ e ->getStringCode ());
308
+ }
309
+
310
+ // Add feature to normal user
311
+ $ this ->client ->addUserFeature ($ userId , $ featureName );
312
+
313
+ // now normal user should be able to delete user
314
+ $ this ->normalUserClient ->removeUser ($ newUser ['id ' ]);
315
+ $ deletedUser = $ this ->client ->getUser ($ newUser ['id ' ]);
316
+
317
+ $ this ->assertSame ('DELETED ' , $ deletedUser ['email ' ], 'User e-mail has not been deleted ' );
318
+ $ this ->assertSame (false , $ deletedUser ['mfaEnabled ' ], 'User mfa has not been disabled ' );
319
+ $ this ->assertSame ('DELETED ' , $ deletedUser ['name ' ], 'User name has not been deleted ' );
320
+ }
280
321
}
0 commit comments