Skip to content

Commit

Permalink
fix(Sharing): Do not create new share in guest app
Browse files Browse the repository at this point in the history
Only create the template for share and return the the 'Sharing UI'
in the sidebar.

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
Fenn-CS committed Jun 24, 2024
1 parent eacd50f commit 4bb6956
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/services/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getLoggerBuilder } from '@nextcloud/logger'

export const logger = getLoggerBuilder()
.setApp('guests')
.detectUser()
.build()
23 changes: 11 additions & 12 deletions src/views/GuestForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
</template>

<script>
import { logger } from '../services/logger.ts'
import { generateOcsUrl } from '@nextcloud/router'
import { Type as ShareTypes } from '@nextcloud/sharing'
import AccountPlus from 'vue-material-design-icons/AccountPlus.vue'
import axios from '@nextcloud/axios'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand Down Expand Up @@ -200,6 +203,7 @@ export default {
this.loading = true
try {
await axios.put(generateOcsUrl('/apps/guests/api/v1/users'), {
displayName: this.guest.fullName,
email: this.guest.email,
Expand All @@ -216,7 +220,8 @@ export default {
this.closeModal()
return
}
await this.addGuestShare()
await this.setupGuestShare()
} catch ({ response }) {
const error = response && response.data && response.data.ocs && response.data.ocs.data
? response.data.ocs.data.errorMessages
Expand All @@ -230,22 +235,16 @@ export default {
}
},
async addGuestShare() {
async setupGuestShare() {
try {
const url = generateOcsUrl('/apps/files_sharing/api/v1/shares')
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
const result = await axios.post(url + '?format=json', {
shareType: OC.Share.SHARE_TYPE_USER,
const shareTemplate = {
shareType: ShareTypes.SHARE_TYPE_USER,
shareWith: this.guest.username,
path,
})
if (!result.data.ocs) {
this.reject(result)
}
this.resolve(result.data.ocs.data)
logger.info('Created share template with newly invited guest', { shareTemplate })
this.resolve(shareTemplate)
this.closeModal()
} catch ({ response }) {
this.reject(response)
Expand Down

0 comments on commit 4bb6956

Please sign in to comment.