Skip to content

Commit

Permalink
fix(files_sharing): phpunit & openapi fixes
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jul 11, 2024
1 parent b0406a7 commit b29a7e6
Show file tree
Hide file tree
Showing 10 changed files with 703 additions and 225 deletions.
10 changes: 8 additions & 2 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2065,8 +2065,14 @@ private function checkInheritedAttributes(IShare $share): void {
/**
* Send a mail notification again for a share.
* The mail_send option must be enabled for the given share.
* @param string $id
* @param string $id the share ID
* @param string $password optional, the password to check against. Necessary for password protected shares.
* @throws OCSNotFoundException Share not found
* @throws OCSForbiddenException You are not allowed to send mail notifications
* @throws OCSBadRequestException Invalid request or wrong password
* @throws OCSException Error while sending mail notification
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
* 200: The email notification was sent successfully
*/
#[NoAdminRequired]
#[UserRateLimit(limit: 5, period: 120)]
Expand Down Expand Up @@ -2110,7 +2116,7 @@ public function sendShareEmail(string $id, $password = ''): DataResponse {
}

$provider->sendMailNotification($share);
return new DataResponse(['message' => 'ok']);
return new DataResponse();
} catch(OCSBadRequestException $e) {
throw $e;
} catch (Exception $e) {
Expand Down
183 changes: 183 additions & 0 deletions apps/files_sharing/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,15 @@
"type": "string",
"nullable": true,
"description": "Additional attributes for the share"
},
"sendMail": {
"type": "string",
"nullable": true,
"enum": [
"false",
"true"
],
"description": "Send a mail to the recipient"
}
}
}
Expand Down Expand Up @@ -2256,6 +2265,11 @@
"type": "string",
"nullable": true,
"description": "New additional attributes"
},
"sendMail": {
"type": "string",
"nullable": true,
"description": "if the share should be send by mail.\n Considering the share already exists, no mail will be send after the share is updated.\n \t\t\t\t You will have to use the sendMail action to send the mail."
}
}
}
Expand Down Expand Up @@ -2523,6 +2537,175 @@
}
}
},
"/ocs/v2.php/apps/files_sharing/api/v1/shares/{id}/send-email": {
"post": {
"operationId": "shareapi-send-share-email",
"summary": "Send a mail notification again for a share. The mail_send option must be enabled for the given share.",
"tags": [
"shareapi"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"password": {
"type": "string",
"default": "",
"description": "optional, the password to check against. Necessary for password protected shares."
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "the share ID",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"404": {
"description": "Share not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
},
"403": {
"description": "You are not allowed to send mail notifications",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
},
"400": {
"description": "Invalid request or wrong password",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
},
"200": {
"description": "The email notification was sent successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/{id}": {
"post": {
"operationId": "shareapi-accept-share",
Expand Down
6 changes: 6 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\Mail\IMailer;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -97,6 +99,8 @@ private function createOCS($userId) {
$previewManager = $this->createMock(IPreview::class);
$dateTimeZone = $this->createMock(IDateTimeZone::class);
$logger = $this->createMock(LoggerInterface::class);
$providerFactory = $this->createMock(IProviderFactory::class);
$mailer = $this->createMock(IMailer::class);
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));

return new ShareAPIController(
Expand All @@ -115,6 +119,8 @@ private function createOCS($userId) {
$previewManager,
$dateTimeZone,
$logger,
$providerFactory,
$mailer,
$userId,
);
}
Expand Down
Loading

0 comments on commit b29a7e6

Please sign in to comment.