1
0
Fork 0
mirror of synced 2024-05-21 05:02:37 +12:00

Merge pull request #954 from appwrite/fix-952-patch-user-prefs-event

Fix 952 patch user prefs event
This commit is contained in:
Eldad A. Fux 2021-03-12 17:41:39 +02:00 committed by GitHub
commit 7ebc7f750f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 5 deletions

View file

@ -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

View file

@ -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,

View file

@ -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')

View file

@ -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',

View file

@ -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;
}
}
}