Skip to content

Commit

Permalink
Merge pull request #50 from utopia-php/rm_userInternalId
Browse files Browse the repository at this point in the history
Remove user internalId attribute
  • Loading branch information
abnegate authored May 15, 2023
2 parents e722808 + d5d9bac commit bdf89d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions src/Audit/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ public function setup(): void
}

$attributes = [
new Document([
'$id' => 'userInternalId',
'type' => Database::VAR_STRING,
'size' => Database::LENGTH_KEY,
'required' => true,
'signed' => true,
'array' => false,
'filters' => [],
]),
new Document([
'$id' => 'userId',
'type' => Database::VAR_STRING,
Expand Down Expand Up @@ -159,7 +150,6 @@ public function setup(): void
/**
* Add event log.
*
* @param string $userInternalId
* @param string $userId
* @param string $event
* @param string $resource
Expand All @@ -174,12 +164,11 @@ public function setup(): void
* @throws \Exception
* @throws \Throwable
*/
public function log(string $userInternalId, string $userId, string $event, string $resource, string $userAgent, string $ip, string $location, array $data = []): bool
public function log(string $userId, string $event, string $resource, string $userAgent, string $ip, string $location, array $data = []): bool
{
Authorization::skip(function () use ($userId, $userInternalId, $event, $resource, $userAgent, $ip, $location, $data) {
Authorization::skip(function () use ($userId, $event, $resource, $userAgent, $ip, $location, $data) {
$this->db->createDocument(Audit::COLLECTION, new Document([
'$permissions' => [],
'userInternalId' => $userInternalId,
'userId' => $userId,
'event' => $event,
'resource' => $resource,
Expand Down
14 changes: 6 additions & 8 deletions tests/Audit/AuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ public function tearDown(): void

public function createLogs(): void
{
$userInternalIdId = '1';
$userId = 'userId';
$userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36';
$ip = '127.0.0.1';
$location = 'US';
$data = ['key1' => 'value1', 'key2' => 'value2'];

$this->assertTrue($this->audit->log($userInternalIdId, $userId, 'update', 'database/document/1', $userAgent, $ip, $location, $data));
$this->assertTrue($this->audit->log($userInternalIdId, $userId, 'update', 'database/document/2', $userAgent, $ip, $location, $data));
$this->assertTrue($this->audit->log($userInternalIdId, $userId, 'delete', 'database/document/2', $userAgent, $ip, $location, $data));
$this->assertTrue($this->audit->log($userId, 'update', 'database/document/1', $userAgent, $ip, $location, $data));
$this->assertTrue($this->audit->log($userId, 'update', 'database/document/2', $userAgent, $ip, $location, $data));
$this->assertTrue($this->audit->log($userId, 'delete', 'database/document/2', $userAgent, $ip, $location, $data));
}

public function testGetLogsByUser(): void
Expand Down Expand Up @@ -158,18 +157,17 @@ public function testCleanup(): void
$this->assertEquals(0, \count($logs));

// Add three sample logs
$userInternalIdId = '1';
$userId = 'userId';
$userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36';
$ip = '127.0.0.1';
$location = 'US';
$data = ['key1' => 'value1', 'key2' => 'value2'];

$this->assertEquals($this->audit->log($userInternalIdId, $userId, 'update', 'database/document/1', $userAgent, $ip, $location, $data), true);
$this->assertEquals($this->audit->log($userId, 'update', 'database/document/1', $userAgent, $ip, $location, $data), true);
sleep(5);
$this->assertEquals($this->audit->log($userInternalIdId, $userId, 'update', 'database/document/2', $userAgent, $ip, $location, $data), true);
$this->assertEquals($this->audit->log($userId, 'update', 'database/document/2', $userAgent, $ip, $location, $data), true);
sleep(5);
$this->assertEquals($this->audit->log($userInternalIdId, $userId, 'delete', 'database/document/2', $userAgent, $ip, $location, $data), true);
$this->assertEquals($this->audit->log($userId, 'delete', 'database/document/2', $userAgent, $ip, $location, $data), true);
sleep(5);

// DELETE logs older than 11 seconds and check that status is true
Expand Down

0 comments on commit bdf89d7

Please sign in to comment.