Skip to content

Commit 389fdda

Browse files
Fix 587 - throw exception when change the email address using PUT /developers for ApigeeX (#598)
* Issue 587 - Throw exception when changing the email address using PUT /developers for ApigeeX
1 parent 5ecd85b commit 389fdda

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

apigee_edge.module

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use Drupal\apigee_edge\Element\StatusPropertyElement;
3131
use Drupal\apigee_edge\Entity\ApiProduct;
3232
use Drupal\apigee_edge\Entity\AppInterface;
3333
use Drupal\apigee_edge\Entity\Developer;
34+
use Drupal\apigee_edge\Exception\DeveloperUpdateFailedException;
3435
use Drupal\apigee_edge\Exception\UserDeveloperConversionNoStorageFormatterFoundException;
3536
use Drupal\apigee_edge\Exception\UserDeveloperConversionUserFieldDoesNotExistException;
3637
use Drupal\apigee_edge\Form\DeveloperSettingsForm;
@@ -1371,6 +1372,14 @@ function apigee_edge_user_presave(UserInterface $account) {
13711372
$logger->error("Unable to save @developer developer's developer id on user.", $context);
13721373
}
13731374
}
1375+
elseif ($previous->getEdgeErrorCode() === Developer::APIGEE_HYBRID_ERROR_CODE_DEVELOPER_EMAIL_MISMATCH) {
1376+
// Apigee X and Hybrid runtime v1.5.0 and v1.5.1 a call to change the developer's
1377+
// email address will not work so need to prevent user email update on
1378+
// Drupal as well.
1379+
// @see https://github.com/apigee/apigee-client-php/issues/153
1380+
// @see https://github.com/apigee/apigee-edge-drupal/issues/587
1381+
throw new DeveloperUpdateFailedException($account->getEmail(), "Developer @email profile cannot be updated. " . $previous->getMessage());
1382+
}
13741383
}
13751384
else {
13761385
$context += Error::decodeException($exception);

src/Entity/Developer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Developer extends EdgeEntityBase implements DeveloperInterface {
6565
*/
6666
const APIGEE_EDGE_ERROR_CODE_DEVELOPER_DOES_NOT_EXISTS = 'developer.service.DeveloperDoesNotExist';
6767

68+
/**
69+
* Resource name in the url doesnot match with the name in the request payload.
70+
*
71+
* @var string
72+
*/
73+
const APIGEE_HYBRID_ERROR_CODE_DEVELOPER_EMAIL_MISMATCH = 'rest.interceptor.name_mismatch';
74+
6875
/**
6976
* The decorated SDK entity.
7077
*
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2021 Google Inc.
5+
*
6+
* This program is free software; you can redistribute it and/or modify it under
7+
* the terms of the GNU General Public License version 2 as published by the
8+
* Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13+
* License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc., 51
17+
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
namespace Drupal\apigee_edge\Exception;
21+
22+
use Apigee\Edge\Exception\ApiException;
23+
24+
/**
25+
* This exception is thrown when the developer profile update fails.
26+
*/
27+
final class DeveloperUpdateFailedException extends ApiException implements ApigeeEdgeExceptionInterface {
28+
29+
/**
30+
* Email address of the developer.
31+
*
32+
* @var string
33+
*/
34+
private $email;
35+
36+
/**
37+
* DeveloperUpdateFailedException constructor.
38+
*
39+
* @param string $email
40+
* Developer email.
41+
* @param string $message
42+
* Exception message.
43+
* @param int $code
44+
* Error code.
45+
* @param \Throwable|null $previous
46+
* Previous exception.
47+
*/
48+
public function __construct(string $email, string $message = 'Developer @email profile update failed.', int $code = 0, \Throwable $previous = NULL) {
49+
$this->email = $email;
50+
$message = strtr($message, ['@email' => $email]);
51+
parent::__construct($message, $code, $previous);
52+
}
53+
54+
/**
55+
* Email address of the developer.
56+
*
57+
* @return string
58+
* Email address.
59+
*/
60+
public function getEmail(): string {
61+
return $this->email;
62+
}
63+
64+
}

0 commit comments

Comments
 (0)