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
26 changes: 20 additions & 6 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,27 +598,41 @@ $teamspeak->channelPermissions()->deleteForClient(channelId: 1, clientDatabaseId

## permissionlist

Not implemented.
```php
$teamspeak->permissions()->list();
```

## permidgetbyname

Not implemented.
```php
$teamspeak->permissions()->getIdByName(name: 'b_serverinstance_help_view');
```

## permoverview

Not implemented.
```php
$teamspeak->permissions()->overview(channelId: 1, clientDatabaseId: 2);
```

## permget

Not implemented.
```php
$teamspeak->permissions()->get(id: 17835);
$teamspeak->permissions()->get(id: 'b_serverinstance_help_view');
```

## permfind

Not implemented.
```php
$teamspeak->permissions()->find(id: 17835);
$teamspeak->permissions()->find(id: 'b_serverinstance_help_view');
```

## permreset

Not implemented.
```php
$teamspeak->permissions()->reset();
```

## privilegekeylist

Expand Down
46 changes: 45 additions & 1 deletion src/Contracts/Resources/PermissionsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,48 @@

namespace TeamSpeak\WebQuery\Contracts\Resources;

interface PermissionsContract {}
use TeamSpeak\WebQuery\Responses\Permissions\FindResponse;
use TeamSpeak\WebQuery\Responses\Permissions\GetIdByNameResponse;
use TeamSpeak\WebQuery\Responses\Permissions\GetResponse;
use TeamSpeak\WebQuery\Responses\Permissions\ListResponse;
use TeamSpeak\WebQuery\Responses\Permissions\OverviewResponse;
use TeamSpeak\WebQuery\Responses\Permissions\ResetResponse;

interface PermissionsContract
{
/**
* Displays a list of all permissions available on the server.
*/
public function list(): ListResponse;

/**
* Returns the ID of a permission specified by name.
*/
public function getIdByName(string $name): GetIdByNameResponse;

/**
* Displays all permissions for a client in a specific channel.
*/
public function overview(int $channelId, int $clientDatabaseId): OverviewResponse;

/**
* Displays the current value of a permission for the selected virtual server.
*
* A permission can be specified by ID or name.
*/
public function get(string|int $id): GetResponse;

/**
* Displays all clients and groups assigned a specific permission.
*
* A permission can be specified by ID or name.
*/
public function find(string|int $id): FindResponse;

/**
* Resets the permission settings of the virtual server to default values.
*
* Returns a new administrator privilege key.
*/
public function reset(): ResetResponse;
}
110 changes: 110 additions & 0 deletions src/Resources/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,118 @@
namespace TeamSpeak\WebQuery\Resources;

use TeamSpeak\WebQuery\Contracts\Resources\PermissionsContract;
use TeamSpeak\WebQuery\Enums\Query\Command;
use TeamSpeak\WebQuery\Responses\Permissions\FindResponse;
use TeamSpeak\WebQuery\Responses\Permissions\GetIdByNameResponse;
use TeamSpeak\WebQuery\Responses\Permissions\GetResponse;
use TeamSpeak\WebQuery\Responses\Permissions\ListResponse;
use TeamSpeak\WebQuery\Responses\Permissions\OverviewResponse;
use TeamSpeak\WebQuery\Responses\Permissions\ResetResponse;
use TeamSpeak\WebQuery\ValueObjects\Transporter\Payload;

final class Permissions implements PermissionsContract
{
use Concerns\Transportable;

/**
* Displays a list of all permissions available on the server.
*/
public function list(): ListResponse
{
$payload = new Payload(Command::PermissionList);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<list<array{permid: string, permname: string, permdesc: string, permtype: string, permisflag: string}>> $response */
$response = $this->transporter->request($payload);

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

/**
* Returns the ID of a permission specified by name.
*/
public function getIdByName(string $name): GetIdByNameResponse
{
$payload = new Payload(
command: Command::PermIdGetByName,
parameters: ['permsid' => $name],
);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<array{0: array{permid: string, permsid: string}}> $response */
$response = $this->transporter->request($payload);

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

/**
* Displays all permissions for a client in a specific channel.
*/
public function overview(int $channelId, int $clientDatabaseId): OverviewResponse
{
$payload = new Payload(
command: Command::PermOverview,
parameters: ['cid' => $channelId, 'cldbid' => $clientDatabaseId],
);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<list<array{t: string, id1: string, id2: string, p: string, v: string, n: string, s: string}>> $response */
$response = $this->transporter->request($payload);

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

/**
* Displays the current value of a permission for the selected virtual server.
*
* A permission can be specified by ID or name.
*/
public function get(string|int $id): GetResponse
{
$payload = new Payload(
command: Command::PermGet,
parameters: [
...is_int($id) ? ['permid' => $id] : [],
...is_string($id) ? ['permsid' => $id] : [],
],
);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<array{0: array{permid: string, permsid: string, permvalue: string}}> $response */
$response = $this->transporter->request($payload);

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

/**
* Displays all clients and groups assigned a specific permission.
*
* A permission can be specified by ID or name.
*/
public function find(string|int $id): FindResponse
{
$payload = new Payload(
command: Command::PermFind,
parameters: [
...is_int($id) ? ['permid' => $id] : [],
...is_string($id) ? ['permsid' => $id] : [],
],
);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<list<array{t: string, id1: string, id2: string, p: string}>> $response */
$response = $this->transporter->request($payload);

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

/**
* Resets the permission settings of the virtual server to default values.
*
* Returns a new administrator privilege key.
*/
public function reset(): ResetResponse
{
$payload = new Payload(Command::PermReset);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<array{0: array{token: string}}> $response */
$response = $this->transporter->request($payload);

return ResetResponse::from($response->body());
}
}
25 changes: 25 additions & 0 deletions src/Responses/Permissions/FindResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class FindResponse
{
/**
* @param list<FindResponseAssignment> $assignments
*/
private function __construct(
public array $assignments,
) {}

/**
* @param list<array{t: string, id1: string, id2: string, p: string}> $attributes
*/
public static function from(array $attributes): self
{
return new self(
array_map(FindResponseAssignment::from(...), $attributes),
);
}
}
28 changes: 28 additions & 0 deletions src/Responses/Permissions/FindResponseAssignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class FindResponseAssignment
{
private function __construct(
public int $type,
public int $id1,
public int $id2,
public int $permId,
) {}

/**
* @param array{t: string, id1: string, id2: string, p: string} $attributes
*/
public static function from(array $attributes): self
{
return new self(
(int) $attributes['t'],
(int) $attributes['id1'],
(int) $attributes['id2'],
(int) $attributes['p'],
);
}
}
24 changes: 24 additions & 0 deletions src/Responses/Permissions/GetIdByNameResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class GetIdByNameResponse
{
private function __construct(
public int $id,
public string $name,
) {}

/**
* @param array{0: array{permid: string, permsid: string}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
(int) $attributes[0]['permid'],
$attributes[0]['permsid'],
);
}
}
26 changes: 26 additions & 0 deletions src/Responses/Permissions/GetResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class GetResponse
{
private function __construct(
public int $id,
public string $name,
public int $value,
) {}

/**
* @param array{0: array{permid: string, permsid: string, permvalue: string}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
(int) $attributes[0]['permid'],
$attributes[0]['permsid'],
(int) $attributes[0]['permvalue'],
);
}
}
25 changes: 25 additions & 0 deletions src/Responses/Permissions/ListResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class ListResponse
{
/**
* @param list<ListResponsePermission> $permissions
*/
private function __construct(
public array $permissions,
) {}

/**
* @param list<array{permid: string, permname: string, permdesc: string, permtype: string, permisflag: string}> $attributes
*/
public static function from(array $attributes): self
{
return new self(
array_map(ListResponsePermission::from(...), $attributes),
);
}
}
30 changes: 30 additions & 0 deletions src/Responses/Permissions/ListResponsePermission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\Permissions;

final readonly class ListResponsePermission
{
private function __construct(
public int $id,
public string $name,
public string $description,
public int $type,
public bool $isFlag,
) {}

/**
* @param array{permid: string, permname: string, permdesc: string, permtype: string, permisflag: string} $attributes
*/
public static function from(array $attributes): self
{
return new self(
(int) $attributes['permid'],
$attributes['permname'],
$attributes['permdesc'],
(int) $attributes['permtype'],
(bool) $attributes['permisflag'],
);
}
}
Loading
Loading