Skip to content

Commit

Permalink
EZP-29962: As a Developer I want API to detect if object is user/grou…
Browse files Browse the repository at this point in the history
…p (#2509)

* EZP-29962: As a Developer I want API to detect if object is user/group

To be able to avoid expensive uncached API calls in Admin UI to always
have to load to see if a object is User or User Group, simply expose
isUser() and isUserGroup() APIs on UserService to avoid this,
as it can check against config instead.
  • Loading branch information
andrerom committed Dec 21, 2018
1 parent 953d7b1 commit fcd784d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Repository/Tests/UserServiceTest.php
Expand Up @@ -54,6 +54,10 @@ public function testLoadUserGroup()
/* END: Use Case */

$this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroup', $userGroup);

// User group happens to also be a Content; isUserGroup() should be true and isUser() should be false
$this->assertTrue($userService->isUserGroup($userGroup), 'isUserGroup() => false on a user group');
$this->assertFalse($userService->isUser($userGroup), 'isUser() => true on a user group');
}

/**
Expand Down Expand Up @@ -1123,6 +1127,10 @@ public function testLoadUser()
/* END: Use Case */

$this->assertEquals($user, $userReloaded);

// User happens to also be a Content; isUser() should be true and isUserGroup() should be false
$this->assertTrue($userService->isUser($user), 'isUser() => false on a user');
$this->assertFalse($userService->isUserGroup($user), 'isUserGroup() => true on a user group');
}

/**
Expand Down
23 changes: 23 additions & 0 deletions Repository/UserService.php
Expand Up @@ -8,6 +8,7 @@
*/
namespace eZ\Publish\API\Repository;

use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\User\PasswordValidationContext;
use eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct;
use eZ\Publish\API\Repository\Values\User\UserCreateStruct;
Expand Down Expand Up @@ -305,6 +306,28 @@ public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25, array
*/
public function loadUsersOfUserGroup(UserGroup $userGroup, $offset = 0, $limit = 25, array $prioritizedLanguages = []);

/**
* Checks if Content is a user.
*
* @since 7.4
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
*
* @return bool
*/
public function isUser(Content $content): bool;

/**
* Checks if Content is a user group.
*
* @since 7.4
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $content
*
* @return bool
*/
public function isUserGroup(Content $content): bool;

/**
* Instantiate a user create class.
*
Expand Down

0 comments on commit fcd784d

Please sign in to comment.