Use @nextcloud/sharing in files and files_sharing

Signed-off-by: Louis Chemineau <louis@chmn.me>

Update tests

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2022-01-26 15:33:36 +01:00
parent a145edd00d
commit be968a8841
19 changed files with 78 additions and 64 deletions

View file

@ -81,6 +81,7 @@ import $ from 'jquery'
import axios from '@nextcloud/axios'
import { emit } from '@nextcloud/event-bus'
import moment from '@nextcloud/moment'
import { Type as ShareTypes } from '@nextcloud/sharing'
import AppSidebar from '@nextcloud/vue/dist/Components/AppSidebar'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
@ -323,8 +324,8 @@ export default {
} else if (fileInfo.mountType !== undefined && fileInfo.mountType !== '') {
return OC.MimeType.getIconUrl('dir-' + fileInfo.mountType)
} else if (fileInfo.shareTypes && (
fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) > -1
|| fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_EMAIL) > -1)
fileInfo.shareTypes.indexOf(ShareTypes.SHARE_TYPE_LINK) > -1
|| fileInfo.shareTypes.indexOf(ShareTypes.SHARE_TYPE_EMAIL) > -1)
) {
return OC.MimeType.getIconUrl('dir-public')
} else if (fileInfo.shareTypes && fileInfo.shareTypes.length > 0) {

View file

@ -329,6 +329,7 @@
<script>
import { generateUrl } from '@nextcloud/router'
import { Type as ShareTypes } from '@nextcloud/sharing'
import Vue from 'vue'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
@ -662,8 +663,8 @@ export default {
externalLinkActions() {
// filter only the registered actions for said link
return this.ExternalShareActions.actions
.filter(action => action.shareType.includes(OC.Share.SHARE_TYPE_LINK)
|| action.shareType.includes(OC.Share.SHARE_TYPE_EMAIL))
.filter(action => action.shareType.includes(ShareTypes.SHARE_TYPE_LINK)
|| action.shareType.includes(ShareTypes.SHARE_TYPE_EMAIL))
},
isPasswordPolicyEnabled() {
@ -682,7 +683,7 @@ export default {
}
const shareDefaults = {
share_type: OC.Share.SHARE_TYPE_LINK,
share_type: ShareTypes.SHARE_TYPE_LINK,
}
if (this.config.isDefaultExpireDateEnforced) {
// default is empty string if not set
@ -756,7 +757,7 @@ export default {
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
const newShare = await this.createShare({
path,
shareType: OC.Share.SHARE_TYPE_LINK,
shareType: ShareTypes.SHARE_TYPE_LINK,
password: share.password,
expireDate: share.expireDate,
// we do not allow setting the publicUpload

View file

@ -21,21 +21,12 @@
*
*/
import { Type as ShareTypes } from '@nextcloud/sharing'
export default {
data() {
return {
SHARE_TYPES: {
SHARE_TYPE_USER: OC.Share.SHARE_TYPE_USER,
SHARE_TYPE_GROUP: OC.Share.SHARE_TYPE_GROUP,
SHARE_TYPE_LINK: OC.Share.SHARE_TYPE_LINK,
SHARE_TYPE_EMAIL: OC.Share.SHARE_TYPE_EMAIL,
SHARE_TYPE_REMOTE: OC.Share.SHARE_TYPE_REMOTE,
SHARE_TYPE_CIRCLE: OC.Share.SHARE_TYPE_CIRCLE,
SHARE_TYPE_GUEST: OC.Share.SHARE_TYPE_GUEST,
SHARE_TYPE_DECK: OC.Share.SHARE_TYPE_DECK,
SHARE_TYPE_REMOTE_GROUP: OC.Share.SHARE_TYPE_REMOTE_GROUP,
SHARE_TYPE_ROOM: OC.Share.SHARE_TYPE_ROOM,
},
SHARE_TYPES: ShareTypes,
}
},
}

View file

@ -75,18 +75,6 @@ export default {
* ! do not remove it ot you'll lose all reactivity here
*/
reactiveState: this.share?.state,
SHARE_TYPES: {
SHARE_TYPE_USER: OC.Share.SHARE_TYPE_USER,
SHARE_TYPE_GROUP: OC.Share.SHARE_TYPE_GROUP,
SHARE_TYPE_LINK: OC.Share.SHARE_TYPE_LINK,
SHARE_TYPE_EMAIL: OC.Share.SHARE_TYPE_EMAIL,
SHARE_TYPE_REMOTE: OC.Share.SHARE_TYPE_REMOTE,
SHARE_TYPE_CIRCLE: OC.Share.SHARE_TYPE_CIRCLE,
SHARE_TYPE_GUEST: OC.Share.SHARE_TYPE_GUEST,
SHARE_TYPE_REMOTE_GROUP: OC.Share.SHARE_TYPE_REMOTE_GROUP,
SHARE_TYPE_ROOM: OC.Share.SHARE_TYPE_ROOM,
},
}
},

View file

@ -50,7 +50,7 @@ export default class ExternalShareActions {
* @param {object} action new action component to register
* @param {string} action.id unique action id
* @param {Function} action.data data to bind the component to
* @param {Array} action.shareType list of OC.Share.SHARE_XXX to be mounted on
* @param {Array} action.shareType list of \@nextcloud/sharing.Types.SHARE_XXX to be mounted on
* @param {object} action.handlers list of listeners
* @return {boolean}
*/
@ -59,7 +59,7 @@ export default class ExternalShareActions {
if (typeof action !== 'object'
|| typeof action.id !== 'string'
|| typeof action.data !== 'function' // () => {disabled: true}
|| !Array.isArray(action.shareType) // [OC.Share.SHARE_TYPE_LINK, ...]
|| !Array.isArray(action.shareType) // [\@nextcloud/sharing.Types.SHARE_TYPE_LINK, ...]
|| typeof action.handlers !== 'object' // {click: () => {}, ...}
|| !Object.values(action.handlers).every(handler => typeof handler === 'function')) {
console.error('Invalid action provided', action)

View file

@ -35,6 +35,9 @@
/* eslint-disable */
import escapeHTML from 'escape-html'
import { Type as ShareTypes } from '@nextcloud/sharing'
import { getCapabilities } from '@nextcloud/capabilities'
(function() {
_.extend(OC.Files.Client, {
@ -70,7 +73,7 @@ import escapeHTML from 'escape-html'
*/
attach: function(fileList) {
// core sharing is disabled/not loaded
if (!OC.Share) {
if (!getCapabilities().files_sharing?.api_enabled) {
return
}
if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
@ -164,30 +167,30 @@ import escapeHTML from 'escape-html'
_.each($files, function(file) {
var $tr = $(file)
var shareTypes = $tr.attr('data-share-types') || ''
var shareTypesStr = $tr.attr('data-share-types') || ''
var shareOwner = $tr.attr('data-share-owner')
if (shareTypes || shareOwner) {
if (shareTypesStr || shareOwner) {
var hasLink = false
var hasShares = false
_.each(shareTypes.split(',') || [], function(shareType) {
shareType = parseInt(shareType, 10)
if (shareType === OC.Share.SHARE_TYPE_LINK) {
_.each(shareTypesStr.split(',') || [], function(shareTypeStr) {
let shareType = parseInt(shareTypeStr, 10)
if (shareType === ShareTypes.SHARE_TYPE_LINK) {
hasLink = true
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
} else if (shareType === ShareTypes.SHARE_TYPE_EMAIL) {
hasLink = true
} else if (shareType === OC.Share.SHARE_TYPE_USER) {
} else if (shareType === ShareTypes.SHARE_TYPE_USER) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_GROUP) {
} else if (shareType === ShareTypes.SHARE_TYPE_GROUP) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
} else if (shareType === ShareTypes.SHARE_TYPE_REMOTE) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
} else if (shareType === ShareTypes.SHARE_TYPE_REMOTE_GROUP) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
} else if (shareType === ShareTypes.SHARE_TYPE_CIRCLE) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_ROOM) {
} else if (shareType === ShareTypes.SHARE_TYPE_ROOM) {
hasShares = true
} else if (shareType === OC.Share.SHARE_TYPE_DECK) {
} else if (shareType === ShareTypes.SHARE_TYPE_DECK) {
hasShares = true
}
})
@ -218,8 +221,8 @@ import escapeHTML from 'escape-html'
permissions: OC.PERMISSION_ALL,
iconClass: function(fileName, context) {
var shareType = parseInt(context.$file.data('share-types'), 10)
if (shareType === OC.Share.SHARE_TYPE_EMAIL
|| shareType === OC.Share.SHARE_TYPE_LINK) {
if (shareType === ShareTypes.SHARE_TYPE_EMAIL
|| shareType === ShareTypes.SHARE_TYPE_LINK) {
return 'icon-public'
}
return 'icon-shared'

View file

@ -22,6 +22,8 @@
*
*/
import { Type as ShareTypes } from '@nextcloud/sharing'
(function() {
'use strict'
@ -40,7 +42,7 @@
this.$el.removeClass('shared icon-public icon-shared')
if (isShared) {
this.$el.addClass('shared')
if (data.dirInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) !== -1) {
if (data.dirInfo.shareTypes.indexOf(ShareTypes.SHARE_TYPE_LINK) !== -1) {
this.$el.addClass('icon-public')
} else {
this.$el.addClass('icon-shared')

View file

@ -21,8 +21,10 @@
*
*/
import { Type as ShareTypes } from '@nextcloud/sharing'
const shareWithTitle = function(share) {
if (share.type === OC.Share.SHARE_TYPE_GROUP) {
if (share.type === ShareTypes.SHARE_TYPE_GROUP) {
return t(
'files_sharing',
'Shared with you and the group {group} by {owner}',
@ -33,7 +35,7 @@ const shareWithTitle = function(share) {
undefined,
{ escape: false }
)
} else if (share.type === OC.Share.SHARE_TYPE_CIRCLE) {
} else if (share.type === ShareTypes.SHARE_TYPE_CIRCLE) {
return t(
'files_sharing',
'Shared with you and {circle} by {owner}',
@ -44,7 +46,7 @@ const shareWithTitle = function(share) {
undefined,
{ escape: false }
)
} else if (share.type === OC.Share.SHARE_TYPE_ROOM) {
} else if (share.type === ShareTypes.SHARE_TYPE_ROOM) {
if (share.shareWithDisplayName) {
return t(
'files_sharing',

View file

@ -86,6 +86,14 @@ window.firstDay = 0;
// setup dummy webroots
/* jshint camelcase: false */
window.oc_debug = true;
// Mock @nextcloud/capabilities
window._oc_capabilities = {
files_sharing: {
api_enabled: true
}
}
// FIXME: OC.webroot is supposed to be only the path!!!
OC.webroot = location.href + '/';
OC.appswebroots = {

4
dist/core-common.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

17
package-lock.json generated
View file

@ -24,6 +24,7 @@
"@nextcloud/password-confirmation": "^1.0.1",
"@nextcloud/paths": "^2.1.0",
"@nextcloud/router": "^2.0.0",
"@nextcloud/sharing": "^0.1.0",
"@nextcloud/vue": "^4.3.0",
"@nextcloud/vue-dashboard": "^2.0.1",
"autosize": "^5.0.1",
@ -2953,6 +2954,14 @@
"core-js": "^3.6.4"
}
},
"node_modules/@nextcloud/sharing": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@nextcloud/sharing/-/sharing-0.1.0.tgz",
"integrity": "sha512-Cv4uc1aFrA18w0dltq7a5om/EbJSXf36rtO0LP3vi42E6l8ZDVCZwHLKrsZZa/TXNLeYErs1g/6tmWx5xiSSow==",
"dependencies": {
"core-js": "^3.6.4"
}
},
"node_modules/@nextcloud/stylelint-config": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@nextcloud/stylelint-config/-/stylelint-config-2.1.2.tgz",
@ -21754,6 +21763,14 @@
"core-js": "^3.6.4"
}
},
"@nextcloud/sharing": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@nextcloud/sharing/-/sharing-0.1.0.tgz",
"integrity": "sha512-Cv4uc1aFrA18w0dltq7a5om/EbJSXf36rtO0LP3vi42E6l8ZDVCZwHLKrsZZa/TXNLeYErs1g/6tmWx5xiSSow==",
"requires": {
"core-js": "^3.6.4"
}
},
"@nextcloud/stylelint-config": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@nextcloud/stylelint-config/-/stylelint-config-2.1.2.tgz",

View file

@ -41,6 +41,7 @@
"@nextcloud/password-confirmation": "^1.0.1",
"@nextcloud/paths": "^2.1.0",
"@nextcloud/router": "^2.0.0",
"@nextcloud/sharing": "^0.1.0",
"@nextcloud/vue": "^4.3.0",
"@nextcloud/vue-dashboard": "^2.0.1",
"autosize": "^5.0.1",