Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/CrowdinApiClient/Api/Enterprise/SecurityLogApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace CrowdinApiClient\Api\Enterprise;

use CrowdinApiClient\Api\SecurityLogApi as CrowdinSecurityLogApi;
use CrowdinApiClient\Model\SecurityLog;
use CrowdinApiClient\ModelCollection;

/**
* Security Logs API gives you the possibility to get information about organization security activities.
*
* @package Crowdin\Api\Enterprise
*/
class SecurityLogApi extends CrowdinSecurityLogApi
{
/**
* List Organization Security Logs
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Security-Logs/operation/api.security-logs.getMany API Documentation
*
* @param array $params
* string $params[event] Enum: "login" "password.set" "password.change" "email.change" "login.change" "personal_token.issued" "personal_token.revoked" "mfa.enabled" "mfa.disabled" "session.revoke" "session.revoke_all" "sso.connect" "sso.disconnect" "user.registered" "user.remove" "application.connected" "application.disconnected" "webauthn.created" "webauthn.deleted" "trusted_device.remove" "trusted_device.remove_all" "device_verification.enabled" "device_verification.disabled"<br>
* string $params[createdAfter]<br>
* string $params[createdBefore]<br>
* string $params[ipAddress]<br>
* integer $params[userId]<br>
* integer $params[limit]<br>
* integer $params[offset]<br>
* @return ModelCollection
*/
public function listOrganizationSecurityLogs(array $params = []): ModelCollection
{
return $this->_list('security-logs', SecurityLog::class, $params);
}

/**
* Get Organization Security Log
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Security-Logs/operation/api.security-logs.get API Documentation
*
* @param int $securityLogId
* @return SecurityLog|null
*/
public function getOrganizationSecurityLog(int $securityLogId): ?SecurityLog
{
$path = sprintf('security-logs/%d', $securityLogId);
return $this->_get($path, SecurityLog::class);
}
}
50 changes: 50 additions & 0 deletions src/CrowdinApiClient/Api/SecurityLogApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Model\SecurityLog;
use CrowdinApiClient\ModelCollection;

/**
* Security Logs API gives you the possibility to get information about user security activities.
*
* @package Crowdin\Api
*/
class SecurityLogApi extends AbstractApi
{
/**
* List User Security Logs
* @link https://support.crowdin.com/developer/api/v2/#tag/Security-Logs/operation/api.users.security-logs.getMany API Documentation
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Security-Logs/operation/api.users.security-logs.getMany API Documentation Enterprise
*
* @param int $userId
* @param array $params
* string $params[event] Enum: "login" "password.set" "password.change" "email.change" "login.change" "personal_token.issued" "personal_token.revoked" "mfa.enabled" "mfa.disabled" "session.revoke" "session.revoke_all" "sso.connect" "sso.disconnect" "user.registered" "user.remove" "application.connected" "application.disconnected" "webauthn.created" "webauthn.deleted" "trusted_device.remove" "trusted_device.remove_all" "device_verification.enabled" "device_verification.disabled"<br>
* string $params[createdAfter]<br>
* string $params[createdBefore]<br>
* string $params[ipAddress]<br>
* integer $params[limit]<br>
* integer $params[offset]<br>
* @return ModelCollection
*/
public function listUserSecurityLogs(int $userId, array $params = []): ModelCollection
{
$path = sprintf('users/%d/security-logs', $userId);
return $this->_list($path, SecurityLog::class, $params);
}

/**
* Get User Security Log
* @link https://support.crowdin.com/developer/api/v2/#tag/Security-Logs/operation/api.users.security-logs.get API Documentation
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Security-Logs/operation/api.users.security-logs.get API Documentation Enterprise
*
* @param int $userId
* @param int $securityLogId
* @return SecurityLog|null
*/
public function getUserSecurityLog(int $userId, int $securityLogId): ?SecurityLog
{
$path = sprintf('users/%d/security-logs/%d', $userId, $securityLogId);
return $this->_get($path, SecurityLog::class);
}
}
3 changes: 3 additions & 0 deletions src/CrowdinApiClient/Crowdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @property \CrowdinApiClient\Api\OrganizationWebhookApi $organizationWebhook
* @property \CrowdinApiClient\Api\ReportArchiveApi|\CrowdinApiClient\Api\Enterprise\ReportArchiveApi $reportArchive
* @property \CrowdinApiClient\Api\GraphqlApi $graphql
* @property \CrowdinApiClient\Api\SecurityLogApi|\CrowdinApiClient\Api\Enterprise\SecurityLogApi $securityLog
*/
class Crowdin
{
Expand Down Expand Up @@ -116,6 +117,7 @@ class Crowdin
'organizationWebhook',
'reportArchive',
'graphql',
'securityLog',
];

protected $servicesEnterprise = [
Expand Down Expand Up @@ -154,6 +156,7 @@ class Crowdin
'organizationWebhook',
'reportArchive',
'graphql',
'securityLog',
];

public function __construct(array $config)
Expand Down
127 changes: 127 additions & 0 deletions src/CrowdinApiClient/Model/SecurityLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class SecurityLog extends BaseModel
{
/**
* @var integer
*/
protected $id;

/**
* @var string
*/
protected $event;

/**
* @var string
*/
protected $info;

/**
* @var integer
*/
protected $userId;

/**
* @var string
*/
protected $location;

/**
* @var string
*/
protected $ipAddress;

/**
* @var string
*/
protected $deviceName;

/**
* @var string
*/
protected $createdAt;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->id = (int)$this->getDataProperty('id');
$this->event = (string)$this->getDataProperty('event');
$this->info = (string)$this->getDataProperty('info');
$this->userId = (int)$this->getDataProperty('userId');
$this->location = (string)$this->getDataProperty('location');
$this->ipAddress = (string)$this->getDataProperty('ipAddress');
$this->deviceName = (string)$this->getDataProperty('deviceName');
$this->createdAt = (string)$this->getDataProperty('createdAt');
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getEvent(): string
{
return $this->event;
}

/**
* @return string
*/
public function getInfo(): string
{
return $this->info;
}

/**
* @return int
*/
public function getUserId(): int
{
return $this->userId;
}

/**
* @return string
*/
public function getLocation(): string
{
return $this->location;
}

/**
* @return string
*/
public function getIpAddress(): string
{
return $this->ipAddress;
}

/**
* @return string
*/
public function getDeviceName(): string
{
return $this->deviceName;
}

/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}
}
76 changes: 76 additions & 0 deletions tests/CrowdinApiClient/Api/Enterprise/SecurityLogApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace CrowdinApiClient\Tests\Api\Enterprise;

use CrowdinApiClient\Model\SecurityLog;
use CrowdinApiClient\ModelCollection;

class SecurityLogApiTest extends AbstractTestApi
{
public function testList()
{
$this->mockRequestGet('/security-logs', '{
"data": [
{
"data": {
"id": 2,
"event": "Some event",
"info": "Some info",
"userId": 4,
"location": "USA",
"ipAddress": "127.0.0.1",
"deviceName": "MacOs on MacBook",
"createdAt": "2019-09-19T15:10:43+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}');

$securityLogs = $this->crowdin->securityLog->listOrganizationSecurityLogs();
$this->assertInstanceOf(ModelCollection::class, $securityLogs);
$this->assertCount(1, $securityLogs);

/** @var SecurityLog $securityLog */
$securityLog = $securityLogs[0];
$this->assertInstanceOf(SecurityLog::class, $securityLog);
$this->assertEquals(2, $securityLog->getId());
$this->assertEquals('Some event', $securityLog->getEvent());
$this->assertEquals('Some info', $securityLog->getInfo());
$this->assertEquals(4, $securityLog->getUserId());
$this->assertEquals('USA', $securityLog->getLocation());
$this->assertEquals('127.0.0.1', $securityLog->getIpAddress());
$this->assertEquals('MacOs on MacBook', $securityLog->getDeviceName());
$this->assertEquals('2019-09-19T15:10:43+00:00', $securityLog->getCreatedAt());
}

public function testGet()
{
$this->mockRequestGet('/security-logs/2', '{
"data": {
"id": 2,
"event": "Some event",
"info": "Some info",
"userId": 4,
"location": "USA",
"ipAddress": "127.0.0.1",
"deviceName": "MacOs on MacBook",
"createdAt": "2019-09-19T15:10:43+00:00"
}
}');

$securityLog = $this->crowdin->securityLog->getOrganizationSecurityLog(2);
$this->assertInstanceOf(SecurityLog::class, $securityLog);
$this->assertEquals(2, $securityLog->getId());
$this->assertEquals('Some event', $securityLog->getEvent());
$this->assertEquals('Some info', $securityLog->getInfo());
$this->assertEquals(4, $securityLog->getUserId());
$this->assertEquals('USA', $securityLog->getLocation());
$this->assertEquals('127.0.0.1', $securityLog->getIpAddress());
$this->assertEquals('MacOs on MacBook', $securityLog->getDeviceName());
$this->assertEquals('2019-09-19T15:10:43+00:00', $securityLog->getCreatedAt());
}
}
Loading