Skip to content

Commit 164b006

Browse files
committed
Add new ExternalShareActions API
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 959e4cb commit 164b006

5 files changed

Lines changed: 178 additions & 8 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!--
2+
- @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
3+
-
4+
- @author John Molakvoæ <skjnldsv@protonmail.com>
5+
-
6+
- @license GNU AGPL version 3 or any later version
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-
21+
-->
22+
23+
<template>
24+
<Component :is="data.is"
25+
v-bind="data"
26+
v-on="action.handlers">
27+
{{ data.text }}
28+
</Component>
29+
</template>
30+
31+
<script>
32+
import Share from '../models/Share'
33+
34+
export default {
35+
name: 'ExternalShareAction',
36+
37+
props: {
38+
id: {
39+
type: String,
40+
required: true,
41+
},
42+
action: {
43+
type: Object,
44+
default: () => ({}),
45+
},
46+
fileInfo: {
47+
type: Object,
48+
default: () => {},
49+
required: true,
50+
},
51+
share: {
52+
type: Share,
53+
default: null,
54+
},
55+
},
56+
57+
computed: {
58+
data() {
59+
return this.action.data(this)
60+
},
61+
},
62+
}
63+
</script>

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,16 @@
285285
@submit="onNoteSubmit" />
286286
</template>
287287

288-
<!-- external sharing via url (social...) -->
289-
<ActionLink v-for="({icon, url, name}, index) in externalActions"
288+
<!-- external actions -->
289+
<ExternalShareAction v-for="action in externalLinkActions"
290+
:id="action.id"
291+
:key="action.id"
292+
:action="action"
293+
:file-info="fileInfo"
294+
:share="share" />
295+
296+
<!-- external legacy sharing via url (social...) -->
297+
<ActionLink v-for="({icon, url, name}, index) in externalLegacyLinkActions"
290298
:key="index"
291299
:href="url(shareLink)"
292300
:icon="icon"
@@ -328,15 +336,16 @@ import Vue from 'vue'
328336
329337
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
330338
import ActionCheckbox from '@nextcloud/vue/dist/Components/ActionCheckbox'
331-
import ActionRadio from '@nextcloud/vue/dist/Components/ActionRadio'
332339
import ActionInput from '@nextcloud/vue/dist/Components/ActionInput'
340+
import ActionLink from '@nextcloud/vue/dist/Components/ActionLink'
341+
import ActionRadio from '@nextcloud/vue/dist/Components/ActionRadio'
333342
import ActionText from '@nextcloud/vue/dist/Components/ActionText'
334343
import ActionTextEditable from '@nextcloud/vue/dist/Components/ActionTextEditable'
335-
import ActionLink from '@nextcloud/vue/dist/Components/ActionLink'
336344
import Actions from '@nextcloud/vue/dist/Components/Actions'
337345
import Avatar from '@nextcloud/vue/dist/Components/Avatar'
338346
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
339347
348+
import ExternalShareAction from './ExternalShareAction'
340349
import GeneratePassword from '../utils/GeneratePassword'
341350
import Share from '../models/Share'
342351
import SharesMixin from '../mixins/SharesMixin'
@@ -354,6 +363,7 @@ export default {
354363
ActionText,
355364
ActionTextEditable,
356365
Avatar,
366+
ExternalShareAction,
357367
},
358368
359369
directives: {
@@ -381,7 +391,8 @@ export default {
381391
publicUploadRValue: OC.PERMISSION_READ,
382392
publicUploadWValue: OC.PERMISSION_CREATE,
383393
384-
ExternalLinkActions: OCA.Sharing.ExternalLinkActions.state,
394+
ExternalLegacyLinkActions: OCA.Sharing.ExternalLinkActions.state,
395+
ExternalShareActions: OCA.Sharing.ExternalShareActions.state,
385396
}
386397
},
387398
@@ -621,11 +632,23 @@ export default {
621632
},
622633
623634
/**
624-
* External aditionnal actions for the menu
635+
* External additionnai actions for the menu
636+
* @deprecated use OCA.Sharing.ExternalShareActions
637+
* @returns {Array}
638+
*/
639+
externalLegacyLinkActions() {
640+
return this.ExternalLegacyLinkActions.actions
641+
},
642+
643+
/**
644+
* Additional actions for the menu
625645
* @returns {Array}
626646
*/
627-
externalActions() {
628-
return this.ExternalLinkActions.actions
647+
externalLinkActions() {
648+
// filter only the registered actions for said link
649+
return this.ExternalShareActions.actions
650+
.filter(action => action.shareType.includes(OC.Share.SHARE_TYPE_LINK)
651+
|| action.shareType.includes(OC.Share.SHARE_TYPE_EMAIL))
629652
},
630653
631654
isPasswordPolicyEnabled() {

apps/files_sharing/src/files_sharing_tab.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { translate as t, translatePlural as n } from '@nextcloud/l10n'
2828
import SharingTab from './views/SharingTab'
2929
import ShareSearch from './services/ShareSearch'
3030
import ExternalLinkActions from './services/ExternalLinkActions'
31+
import ExternalShareActions from './services/ExternalShareActions'
3132
import TabSections from './services/TabSections'
3233

3334
// Init Sharing Tab Service
@@ -36,6 +37,7 @@ if (!window.OCA.Sharing) {
3637
}
3738
Object.assign(window.OCA.Sharing, { ShareSearch: new ShareSearch() })
3839
Object.assign(window.OCA.Sharing, { ExternalLinkActions: new ExternalLinkActions() })
40+
Object.assign(window.OCA.Sharing, { ExternalShareActions: new ExternalShareActions() })
3941
Object.assign(window.OCA.Sharing, { ShareTabSections: new TabSections() })
4042

4143
Vue.prototype.t = t

apps/files_sharing/src/services/ExternalLinkActions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export default class ExternalLinkActions {
5252
* @returns {boolean}
5353
*/
5454
registerAction(action) {
55+
console.warn('OCA.Sharing.ExternalLinkActions is deprecated, use OCA.Sharing.ExternalShareAction instead')
56+
5557
if (typeof action === 'object' && action.icon && action.name && action.url) {
5658
this._state.actions.push(action)
5759
return true
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
3+
*
4+
* @author John Molakvoæ <skjnldsv@protonmail.com>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
export default class ExternalShareActions {
24+
25+
_state;
26+
27+
constructor() {
28+
// init empty state
29+
this._state = {}
30+
31+
// init default values
32+
this._state.actions = []
33+
console.debug('OCA.Sharing.ExternalShareActions initialized')
34+
}
35+
36+
/**
37+
* Get the state
38+
*
39+
* @readonly
40+
* @memberof ExternalLinkActions
41+
* @returns {Object} the data state
42+
*/
43+
get state() {
44+
return this._state
45+
}
46+
47+
/**
48+
* Register a new option/entry for the a given share type
49+
*
50+
* @param {Object} action new action component to register
51+
* @param {string} action.id unique action id
52+
* @param {Function} action.data data to bind the component to
53+
* @param {Array} action.shareType list of OC.Share.SHARE_XXX to be mounted on
54+
* @param {Object} action.handlers list of listeners
55+
* @returns {boolean}
56+
*/
57+
registerAction(action) {
58+
// Validate action
59+
if (typeof action !== 'object'
60+
|| typeof action.id !== 'string'
61+
|| typeof action.data !== 'function' // () => {disabled: true}
62+
|| !Array.isArray(action.shareType) // [OC.Share.SHARE_TYPE_LINK, ...]
63+
|| typeof action.handlers !== 'object' // {click: () => {}, ...}
64+
|| !Object.values(action.handlers).every(handler => typeof handler === 'function')) {
65+
console.error('Invalid action provided', action)
66+
return false
67+
}
68+
69+
// Check duplicates
70+
const hasDuplicate = this._state.actions.findIndex(check => check.id === action.id) > -1
71+
if (hasDuplicate) {
72+
console.error(`An action with the same id ${action.id} already exists`, action)
73+
return false
74+
}
75+
76+
this._state.actions.push(action)
77+
return true
78+
}
79+
80+
}

0 commit comments

Comments
 (0)