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 12, 2024
1 parent 04da658 commit aac703f
Show file tree
Hide file tree
Showing 18 changed files with 804 additions and 326 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
18 changes: 10 additions & 8 deletions apps/files_sharing/src/components/NewFileRequestDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<FileRequestFinish v-if="share"
v-show="currentStep === STEP.LAST"
:emails="emails"
:isShareByMailEnabled="isShareByMailEnabled"
:is-share-by-mail-enabled="isShareByMailEnabled"
:share="share"
@add-email="email => emails.push(email)"
@remove-email="onRemoveEmail" />
Expand Down Expand Up @@ -103,18 +103,20 @@
</template>

<script lang="ts">
// eslint-disable-next-line n/no-extraneous-import
import type { AxiosError } from 'axios'
import { Permission, type Folder, type Node } from '@nextcloud/files'
import type { Folder, Node } from '@nextcloud/files'
import type { OCSResponse } from '@nextcloud/typings/ocs'
import type { PropType } from 'vue'
import { defineComponent } from 'vue'
import { emit } from '@nextcloud/event-bus'
import { generateOcsUrl } from '@nextcloud/router'
import { getCapabilities } from '@nextcloud/capabilities'
import { Permission } from '@nextcloud/files'
import { ShareType } from '@nextcloud/sharing'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate, translatePlural } from '@nextcloud/l10n'
import { Type } from '@nextcloud/sharing'
import axios from '@nextcloud/axios'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand Down Expand Up @@ -170,7 +172,7 @@ export default defineComponent({
n: translatePlural,
t: translate,
isShareByMailEnabled: getCapabilities()?.files_sharing?.sharebymail?.enabled === true
isShareByMailEnabled: getCapabilities()?.files_sharing?.sharebymail?.enabled === true,
}
},
Expand Down Expand Up @@ -254,9 +256,9 @@ export default defineComponent({
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
try {
const request = await axios.post<OCSResponse>(shareUrl, {
shareType: Type.SHARE_TYPE_EMAIL,
shareType: ShareType.Email,
permissions: Permission.CREATE,
label: this.label,
path: this.destination,
note: this.note,
Expand Down Expand Up @@ -331,7 +333,7 @@ export default defineComponent({
}
},
async sendEmails () {
async sendEmails() {
this.loading = true
// This should never happen™
Expand All @@ -358,7 +360,7 @@ export default defineComponent({
}
},
onEmailSendError(error: AxiosError<OCSResponse>|any) {
onEmailSendError(error: AxiosError<OCSResponse>) {
const errorMessage = error.response?.data?.ocs?.meta?.message
showError(
errorMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:value="expirationDate"
name="expirationDate"
type="date"
@update:value="$emit('update:expirationDate', $event)"/>
@update:value="$emit('update:expirationDate', $event)" />
</fieldset>

<!-- Password -->
Expand Down Expand Up @@ -96,7 +96,7 @@ import GeneratePassword from '../../utils/GeneratePassword'
const sharingConfig = new Config()
export default defineComponent({
name: 'FileRequestDatePassword',
name: 'NewFileRequestDialogDatePassword',
components: {
IconPasswordGen,
Expand Down Expand Up @@ -207,7 +207,6 @@ export default defineComponent({
this.$emit('update:password', null)
},
async onGeneratePassword() {
await this.generatePassword()
this.showPassword()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import IconCheck from 'vue-material-design-icons/Check.vue'
import IconClipboard from 'vue-material-design-icons/Clipboard.vue'
export default defineComponent({
name: 'FileRequestFinish',
name: 'NewFileRequestDialogFinish',
components: {
IconCheck,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
export default defineComponent({
name: 'FileRequestIntro',
name: 'NewFileRequestDialogIntro',
components: {
IconFolder,
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export default {
},
canChangeHideDownload() {
const hasDisabledDownload = (shareAttribute) => shareAttribute.scope === 'permissions' && shareAttribute.key === 'download'&& shareAttribute.value === false
const hasDisabledDownload = (shareAttribute) => shareAttribute.scope === 'permissions' && shareAttribute.key === 'download' && shareAttribute.value === false
return this.fileInfo.shareAttributes.some(hasDisabledDownload)
},
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import debounce from 'debounce'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import Config from '../services/ConfigService.ts'
import GeneratePassword from '../utils/GeneratePassword.ts'
import Share from '../models/Share.js'
import ShareRequests from '../mixins/ShareRequests.js'
import ShareTypes from '../mixins/ShareTypes.js'
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/src/models/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ export default class Share {
return this.attributes.some(isFileRequest)
}


set hasDownloadPermission(enabled) {
this.setAttribute('permissions', 'download', !!enabled)
}
Expand Down
Loading

0 comments on commit aac703f

Please sign in to comment.