Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avatar): Allow logged-in users to proxy avatars without a token #11885

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
8 changes: 8 additions & 0 deletions appinfo/routes/routesAvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
'token' => '^[a-z0-9]{4,30}$',
'size' => '(64|512)',
];
$requirementsNewWithSize = [
'apiVersion' => '(v1)',
'size' => '(64|512)',
];

return [
'ocs' => [
Expand All @@ -45,6 +49,10 @@
['name' => 'Avatar#getAvatarDark', 'url' => '/api/{apiVersion}/room/{token}/avatar/dark', 'verb' => 'GET', 'requirements' => $requirements],
/** @see \OCA\Talk\Controller\AvatarController::deleteAvatar() */
['name' => 'Avatar#deleteAvatar', 'url' => '/api/{apiVersion}/room/{token}/avatar', 'verb' => 'DELETE', 'requirements' => $requirements],
/** @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatarWithoutRoom() */
['name' => 'Avatar#getUserProxyAvatarWithoutRoom', 'url' => '/api/{apiVersion}/proxy/new/user-avatar/{size}', 'verb' => 'GET', 'requirements' => $requirementsNewWithSize],
/** @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatarDarkWithoutRoom() */
['name' => 'Avatar#getUserProxyAvatarDarkWithoutRoom', 'url' => '/api/{apiVersion}/proxy/new/user-avatar/{size}/dark', 'verb' => 'GET', 'requirements' => $requirementsNewWithSize],
/** @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatar() */
['name' => 'Avatar#getUserProxyAvatar', 'url' => '/api/{apiVersion}/proxy/{token}/user-avatar/{size}', 'verb' => 'GET', 'requirements' => $requirementsWithSize],
/** @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatarDark() */
Expand Down
38 changes: 38 additions & 0 deletions lib/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCA\Talk\Service\RoomFormatter;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PublicPage;
Expand Down Expand Up @@ -183,6 +184,43 @@ public function getAvatarDark(): FileDisplayResponse {
return $this->getAvatar(true);
}

/**
* Get the avatar of a cloudId user when inviting users while creating a conversation
*
* @param int $size Avatar size
* @psalm-param 64|512 $size
* @param string $cloudId Federation CloudID to get the avatar for
* @param bool $darkTheme Theme used for background
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
*
* 200: User avatar returned
*/
#[FederationSupported]
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getUserProxyAvatarWithoutRoom(int $size, string $cloudId, bool $darkTheme = false): FileDisplayResponse {
return $this->getUserProxyAvatar($size, $cloudId, $darkTheme);
}

/**
* Get the dark mode avatar of a cloudId user when inviting users while creating a conversation
*
* @param int $size Avatar size
* @psalm-param 64|512 $size
* @param string $cloudId Federation CloudID to get the avatar for
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
*
* 200: User avatar returned
*/
#[FederationSupported]
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getUserProxyAvatarDarkWithoutRoom(int $size, string $cloudId): FileDisplayResponse {
return $this->getUserProxyAvatar($size, $cloudId, true);
}

/**
* Get the avatar of a cloudId user
*
Expand Down
167 changes: 167 additions & 0 deletions openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,173 @@
}
},
"paths": {
"/ocs/v2.php/apps/spreed/api/{apiVersion}/proxy/new/user-avatar/{size}": {
"get": {
"operationId": "avatar-get-user-proxy-avatar-without-room",
"summary": "Get the avatar of a cloudId user when inviting users while creating a conversation",
"tags": [
"avatar"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "cloudId",
"in": "query",
"description": "Federation CloudID to get the avatar for",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "darkTheme",
"in": "query",
"description": "Theme used for background",
"schema": {
"type": "integer",
"default": 0,
"enum": [
0,
1
]
}
},
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v1"
],
"default": "v1"
}
},
{
"name": "size",
"in": "path",
"description": "Avatar size",
"required": true,
"schema": {
"type": "integer",
"format": "int64",
"enum": [
64,
512
]
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "User avatar returned",
"content": {
"*/*": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/proxy/new/user-avatar/{size}/dark": {
"get": {
"operationId": "avatar-get-user-proxy-avatar-dark-without-room",
"summary": "Get the dark mode avatar of a cloudId user when inviting users while creating a conversation",
"tags": [
"avatar"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "cloudId",
"in": "query",
"description": "Federation CloudID to get the avatar for",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "apiVersion",
"in": "path",
"required": true,
"schema": {
"type": "string",
"enum": [
"v1"
],
"default": "v1"
}
},
{
"name": "size",
"in": "path",
"description": "Avatar size",
"required": true,
"schema": {
"type": "integer",
"format": "int64",
"enum": [
64,
512
]
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "User avatar returned",
"content": {
"*/*": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/ocs/v2.php/apps/spreed/api/{apiVersion}/proxy/{token}/user-avatar/{size}": {
"get": {
"operationId": "avatar-get-user-proxy-avatar",
Expand Down
Loading
Loading