From aefcfeb019791b4272f36f54d99ec88f9bf6761d Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Tue, 9 Jan 2024 14:37:09 +0530 Subject: [PATCH 1/4] Fix attribute values lost in PUT call --- .../Controller/AppGroupMembersController.php | 19 ++++++++++++++++++- .../AppGroupMembersControllerInterface.php | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersController.php b/src/Api/ApigeeX/Controller/AppGroupMembersController.php index a4fe6b4b..b1324897 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersController.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersController.php @@ -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; @@ -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( @@ -101,6 +104,20 @@ public function removeMember(string $email): void $this->client->delete($this->getBaseEndpointUri()->withPath("{$this->getBaseEndpointUri()->getPath()}/{$encoded}")); } + /** + * {@inheritdoc} + */ + 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} */ diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php index 9f5f67b1..3e041152 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php @@ -19,12 +19,20 @@ namespace Apigee\Edge\Api\ApigeeX\Controller; use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership; +use Apigee\Edge\Structure\AttributesProperty; /** * Interface AppGroupMembersControllerInterface. */ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInterface { + /** + * Returns a list of all entity attributes from AppGroup. + * + * @return AttributesProperty + */ + public function getAppGroupAttributes(): AttributesProperty; + /** * List all developers associated with a appgroup. * From 5a5d40dbe339dd4902f63532e09514f86c255a27 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Tue, 9 Jan 2024 17:16:20 +0530 Subject: [PATCH 2/4] Fix phpcs fully_qualified_strict_types error --- src/Api/ApigeeX/Controller/AppGroupMembersController.php | 3 ++- .../Controller/AppGroupMembersControllerInterface.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersController.php b/src/Api/ApigeeX/Controller/AppGroupMembersController.php index b1324897..533ade6d 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersController.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersController.php @@ -48,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) { @@ -115,6 +115,7 @@ public function getAppGroupAttributes(): AttributesProperty $appGroup['attributes'], AttributesProperty::class ); + return $appGroupAttributes; } diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php index 3e041152..3e23fd82 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php @@ -36,7 +36,7 @@ public function getAppGroupAttributes(): AttributesProperty; /** * 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; @@ -47,10 +47,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. */ From 1e87bec651fb4f08dabebfc8f98ca2abea67a4d2 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Wed, 10 Jan 2024 10:14:07 +0530 Subject: [PATCH 3/4] Helper method removed from interface as its not required --- src/Api/ApigeeX/Controller/AppGroupMembersController.php | 4 +++- .../Controller/AppGroupMembersControllerInterface.php | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersController.php b/src/Api/ApigeeX/Controller/AppGroupMembersController.php index 533ade6d..411eaa3d 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersController.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersController.php @@ -105,7 +105,9 @@ public function removeMember(string $email): void } /** - * {@inheritdoc} + * Helper function for getting all attributes in AppGroup. + * + * @return AttributesProperty */ public function getAppGroupAttributes(): AttributesProperty { diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php index 3e23fd82..1a9b7bf4 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php @@ -26,13 +26,6 @@ */ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInterface { - /** - * Returns a list of all entity attributes from AppGroup. - * - * @return AttributesProperty - */ - public function getAppGroupAttributes(): AttributesProperty; - /** * List all developers associated with a appgroup. * From 1e8403fc88c62b077675d3a70c39908f6415df53 Mon Sep 17 00:00:00 2001 From: Shishir Suvarna Date: Wed, 10 Jan 2024 10:16:17 +0530 Subject: [PATCH 4/4] Removed unused imports --- .../ApigeeX/Controller/AppGroupMembersControllerInterface.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php index 1a9b7bf4..a321d92e 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php @@ -19,7 +19,6 @@ namespace Apigee\Edge\Api\ApigeeX\Controller; use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership; -use Apigee\Edge\Structure\AttributesProperty; /** * Interface AppGroupMembersControllerInterface.