Merge pull request #954 from appwrite/fix-952-patch-user-prefs-event
Fix 952 patch user prefs event
This commit is contained in:
commit
7ebc7f750f
|
@ -30,6 +30,7 @@
|
|||
- Fixed a bug, that added a wrong timzone offset to user log timestamps
|
||||
- Fixed a bug, that Response format header was not added in the access-control-allow-header list.
|
||||
- Fixed a bug where countryName is unknown on sessions (#933)
|
||||
- Added missing event users.update.prefs (#952)
|
||||
|
||||
## Security
|
||||
|
||||
|
|
|
@ -117,6 +117,11 @@ return [
|
|||
'model' => Response::MODEL_USER,
|
||||
'note' => 'version >= 0.7',
|
||||
],
|
||||
'users.update.prefs' => [
|
||||
'description' => 'This event triggers when a user preference is updated from the users API.',
|
||||
'model' => Response::MODEL_ANY,
|
||||
'note' => 'version >= 0.7',
|
||||
],
|
||||
'users.update.status' => [
|
||||
'description' => 'This event triggers when a user status is updated from the users API.',
|
||||
'model' => Response::MODEL_USER,
|
||||
|
|
|
@ -373,6 +373,7 @@ App::patch('/v1/users/:userId/status')
|
|||
App::patch('/v1/users/:userId/prefs')
|
||||
->desc('Update User Preferences')
|
||||
->groups(['api', 'users'])
|
||||
->label('event', 'users.update.prefs')
|
||||
->label('scope', 'users.write')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
->label('sdk.namespace', 'users')
|
||||
|
|
|
@ -117,6 +117,7 @@ trait ProjectCustom
|
|||
'storage.files.update',
|
||||
'storage.files.delete',
|
||||
'users.create',
|
||||
'users.update.prefs',
|
||||
'users.update.status',
|
||||
'users.delete',
|
||||
'users.sessions.delete',
|
||||
|
|
|
@ -186,10 +186,43 @@ class WebhooksCustomServerTest extends Scope
|
|||
*/
|
||||
return ['userId' => $user['body']['$id'], 'name' => $user['body']['name'], 'email' => $user['body']['email']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @depends testCreateUser
|
||||
*/
|
||||
public function testUpdateUserPrefs(array $data):array
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'prefs' => ['a' => 'b']
|
||||
]);
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 200);
|
||||
$this->assertEquals($user['body']['a'], 'b');
|
||||
|
||||
$webhook = $this->getLastRequest();
|
||||
|
||||
$this->assertEquals($webhook['method'], 'POST');
|
||||
$this->assertEquals($webhook['headers']['Content-Type'], 'application/json');
|
||||
$this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io');
|
||||
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'users.update.prefs');
|
||||
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented');
|
||||
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']);
|
||||
$this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']);
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertEquals($webhook['data']['a'], 'b');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testUpdateUserPrefs
|
||||
*/
|
||||
public function testUpdateUserStatus(array $data):array
|
||||
{
|
||||
/**
|
||||
|
@ -221,7 +254,7 @@ class WebhooksCustomServerTest extends Scope
|
|||
$this->assertEquals($webhook['data']['status'], 2);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -257,8 +290,8 @@ class WebhooksCustomServerTest extends Scope
|
|||
$this->assertEquals($webhook['data']['status'], 2);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
$this->assertEquals($webhook['data']['prefs'], []);
|
||||
$this->assertEquals($webhook['data']['prefs']['a'], 'b');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue