Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attribute values lost in PUT call while creating AppGroup #340

Merged
merged 8 commits into from
Jan 10, 2024
24 changes: 22 additions & 2 deletions src/Api/ApigeeX/Controller/AppGroupMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupMembershipSerializer;
use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership;
use Apigee\Edge\Api\Management\Serializer\AttributesPropertyAwareEntitySerializer;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\AbstractController;
use Apigee\Edge\Controller\OrganizationAwareControllerTrait;
Expand Down Expand Up @@ -47,7 +48,7 @@ class AppGroupMembersController extends AbstractController implements AppGroupMe
*
* @param string $appGroup
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param ClientInterface $client
*/
public function __construct(string $appGroup, string $organization, ClientInterface $client)
{
Expand All @@ -73,8 +74,10 @@ public function getMembers(): AppGroupMembership
public function setMembers(AppGroupMembership $members): AppGroupMembership
{
$members = $this->serializer->normalize($members);
$apigeeReservedMembers = new AttributesProperty();

// We don't have a separate API to get appgroup attributes,
// that is why we are calling getAppGroupAttributes() method.
$apigeeReservedMembers = $this->getAppGroupAttributes();
// Adding the new members into the attribute.
$apigeeReservedMembers->add('__apigee_reserved__developer_details', json_encode($members));
$response = $this->client->put(
Expand All @@ -101,6 +104,23 @@ public function removeMember(string $email): void
$this->client->delete($this->getBaseEndpointUri()->withPath("{$this->getBaseEndpointUri()->getPath()}/{$encoded}"));
}

/**
* Helper function for getting all attributes in AppGroup.
*
* @return AttributesProperty
*/
public function getAppGroupAttributes(): AttributesProperty
{
$appGroup = $this->responseToArray($this->client->get($this->getBaseEndpointUri()));
$serializer = new AttributesPropertyAwareEntitySerializer();
$appGroupAttributes = $serializer->denormalize(
$appGroup['attributes'],
AttributesProperty::class
);

return $appGroupAttributes;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInte
/**
* List all developers associated with a appgroup.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Array of developers with their optional roles in the appgroup.
*/
public function getMembers(): AppGroupMembership;
Expand All @@ -39,10 +39,10 @@ public function getMembers(): AppGroupMembership;
* WARNING! If you pass en empty membership object you remove all developers
* from the appgroup.
*
* @param \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership $members
* @param AppGroupMembership $members
* Membership object with the changes to be applied.
*
* @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership
* @return AppGroupMembership
* Membership object with the applied changes, it does not contain all
* members. Use getMembers() to retrieve them.
*/
Expand Down
Loading