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
10 changes: 8 additions & 2 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,17 @@ $teamspeak->serverGroups()->getByClient(clientDatabaseId: 18);

## servergroupautoaddperm

Not implemented.
```php
$teamspeak->serverGroups()->addAutoPermission(type: PermissionGroupDatabaseTypes::Regular, id: 17835, value: 75);
$teamspeak->serverGroups()->addAutoPermission(type: PermissionGroupDatabaseTypes::Regular, id: 'b_serverinstance_help_view', value: 75, negated: true, skip: true);
```

## servergroupautodelperm

Not implemented.
```php
$teamspeak->serverGroups()->deleteAutoPermission(type: PermissionGroupDatabaseTypes::Regular, id: 17835);
$teamspeak->serverGroups()->deleteAutoPermission(type: PermissionGroupDatabaseTypes::Regular, id: 'b_serverinstance_help_view');
```

## serversnapshotcreate

Expand Down
10 changes: 10 additions & 0 deletions src/Contracts/Resources/ServerGroupsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,14 @@ public function getClients(int $id, bool $names = false): GetClientsResponse;
* Displays all server groups the client is currently residing in.
*/
public function getByClient(int $clientDatabaseId): GetByClientResponse;

/**
* Adds a permission to all server groups of the specified type.
*/
public function addAutoPermission(PermissionGroupDatabaseTypes $type, string|int $id, int $value, bool $negated = false, bool $skip = false): void;

/**
* Removes a permission from all server groups of the specified type.
*/
public function deleteAutoPermission(PermissionGroupDatabaseTypes $type, string|int $id): void;
}
37 changes: 37 additions & 0 deletions src/Resources/ServerGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,41 @@ public function getByClient(int $clientDatabaseId): GetByClientResponse

return GetByClientResponse::from($response->body());
}

/**
* Adds a permission to all server groups of the specified type.
*/
public function addAutoPermission(PermissionGroupDatabaseTypes $type, string|int $id, int $value, bool $negated = false, bool $skip = false): void
{
$payload = new Payload(
command: Command::ServerGroupAutoAddPerm,
parameters: [
'sgtype' => $type->value,
...is_int($id) ? ['permid' => $id] : [],
...is_string($id) ? ['permsid' => $id] : [],
'permvalue' => $value,
'permnegated' => $negated,
'permskip' => $skip,
],
);

$this->transporter->request($payload);
}

/**
* Removes a permission from all server groups of the specified type.
*/
public function deleteAutoPermission(PermissionGroupDatabaseTypes $type, string|int $id): void
{
$payload = new Payload(
command: Command::ServerGroupAutoDelPerm,
parameters: [
'sgtype' => $type->value,
...is_int($id) ? ['permid' => $id] : [],
...is_string($id) ? ['permsid' => $id] : [],
],
);

$this->transporter->request($payload);
}
}
85 changes: 85 additions & 0 deletions tests/Unit/Resources/ServerGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Psr7\Request as Psr7Request;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Client\ClientInterface;
use TeamSpeak\WebQuery\Enums\PermissionGroupDatabaseTypes;
use TeamSpeak\WebQuery\Resources\ServerGroups;
use TeamSpeak\WebQuery\Transporters\HttpTransporter;
use TeamSpeak\WebQuery\ValueObjects\ApiKey;
Expand Down Expand Up @@ -525,3 +526,87 @@

$resource->getByClient(18);
});

test('add auto permission by ID', function () {
$resource = new ServerGroups($this->http);

$response = new Response(200, ['Content-Type' => 'application/json'], json_encode([
'status' => ['code' => 0, 'message' => 'ok'],
]));

$this->client
->shouldReceive('sendRequest')
->once()
->withArgs(function (Psr7Request $request) {
expect($request->getBody()->getContents())->toBeJson()
->json()
->toBe(['sgtype' => '1', 'permid' => '17835', 'permvalue' => '75', 'permnegated' => '0', 'permskip' => '0']);

return true;
})->andReturn($response);

$resource->addAutoPermission(PermissionGroupDatabaseTypes::Regular, 17835, 75);
})->doesNotPerformAssertions();

test('add auto permission by name', function () {
$resource = new ServerGroups($this->http);

$response = new Response(200, ['Content-Type' => 'application/json'], json_encode([
'status' => ['code' => 0, 'message' => 'ok'],
]));

$this->client
->shouldReceive('sendRequest')
->once()
->withArgs(function (Psr7Request $request) {
expect($request->getBody()->getContents())->toBeJson()
->json()
->toBe(['sgtype' => '1', 'permsid' => 'b_serverinstance_help_view', 'permvalue' => '75', 'permnegated' => '1', 'permskip' => '1']);

return true;
})->andReturn($response);

$resource->addAutoPermission(PermissionGroupDatabaseTypes::Regular, 'b_serverinstance_help_view', 75, true, true);
})->doesNotPerformAssertions();

test('delete auto permission by ID', function () {
$resource = new ServerGroups($this->http);

$response = new Response(200, ['Content-Type' => 'application/json'], json_encode([
'status' => ['code' => 0, 'message' => 'ok'],
]));

$this->client
->shouldReceive('sendRequest')
->once()
->withArgs(function (Psr7Request $request) {
expect($request->getBody()->getContents())->toBeJson()
->json()
->toBe(['sgtype' => '1', 'permid' => '17835']);

return true;
})->andReturn($response);

$resource->deleteAutoPermission(PermissionGroupDatabaseTypes::Regular, 17835);
})->doesNotPerformAssertions();

test('delete auto permission by name', function () {
$resource = new ServerGroups($this->http);

$response = new Response(200, ['Content-Type' => 'application/json'], json_encode([
'status' => ['code' => 0, 'message' => 'ok'],
]));

$this->client
->shouldReceive('sendRequest')
->once()
->withArgs(function (Psr7Request $request) {
expect($request->getBody()->getContents())->toBeJson()
->json()
->toBe(['sgtype' => '1', 'permsid' => 'b_serverinstance_help_view']);

return true;
})->andReturn($response);

$resource->deleteAutoPermission(PermissionGroupDatabaseTypes::Regular, 'b_serverinstance_help_view');
})->doesNotPerformAssertions();
Loading