Detect disabled apps in drive context menu

pull/1/head
yflory 3 years ago
parent aa601db3ee
commit f3cdf33daa

@ -40,15 +40,15 @@ define([
return function () {
var icons = [
[ 'pad', Msg.type.pad],
[ 'code', Msg.type.code],
[ 'slide', Msg.type.slide],
[ 'sheet', Msg.type.sheet],
[ 'doc', Msg.type.doc],
[ 'presentation', Msg.type.presentation],
[ 'pad', Msg.type.pad],
[ 'code', Msg.type.code],
[ 'form', Msg.type.form],
[ 'kanban', Msg.type.kanban],
[ 'whiteboard', Msg.type.whiteboard],
[ 'slide', Msg.type.slide],
[ 'drive', Msg.type.drive]
].filter(function (x) {
return isAvailableType(x[0]);

@ -11,7 +11,7 @@ define(function() {
* redirected to the drive.
* You should never remove the drive from this list.
*/
AppConfig.availablePadTypes = ['drive', 'teams', 'doc', 'sheet', 'presentation', 'pad', 'code', 'slide', 'poll', 'kanban', 'whiteboard',
AppConfig.availablePadTypes = ['drive', 'teams', 'sheet', 'doc', 'presentation', 'pad', 'code', 'slide', 'poll', 'kanban', 'whiteboard',
'file', 'contacts', 'form', 'convert'];
/* The registered only types are apps restricted to registered users.
* You should never remove apps from this list unless you know what you're doing. The apps

@ -348,6 +348,13 @@ define([
var html = '<i class="'+cls+'"></i>' + Messages.type[app];
return Messages._getKey('fc_openIn', [html]);
};
var isAppEnabled = function (app) {
if (!Array.isArray(AppConfig.availablePadTypes)) { return true; }
var registered = common.isLoggedIn() || !(AppConfig.registeredOnlyTypes || []).includes(app);
var restricted = common.checkRestrictedApp(app) < 0;
if (restricted === 0) { return 0; }
return AppConfig.availablePadTypes.includes(app) && registered && !restricted;
};
var menu = h('div.cp-contextmenu.dropdown.cp-unselectable', [
h('ul.dropdown-menu', {
'role': 'menu',
@ -367,22 +374,22 @@ define([
'tabindex': '-1',
'data-icon': faReadOnly,
}, h('span.cp-text', Messages.fc_open_ro))),
h('li', UI.setHTML(h('a.cp-app-drive-context-openincode.dropdown-item', {
isAppEnabled('code') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openincode.dropdown-item', {
'tabindex': '-1',
'data-icon': 'fa-arrows',
}), getOpenIn('code'))),
h('li', UI.setHTML(h('a.cp-app-drive-context-openinsheet.dropdown-item', {
}), getOpenIn('code'))) : undefined,
isAppEnabled('sheet') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openinsheet.dropdown-item', {
'tabindex': '-1',
'data-icon': 'fa-arrows',
}), getOpenIn('sheet'))),
premiumD < 0 ? undefined : h('li', UI.setHTML(h('a.cp-app-drive-context-openindoc.dropdown-item' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
}), getOpenIn('sheet'))) : undefined,
isAppEnabled('doc') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openindoc.dropdown-item' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1',
'data-icon': 'fa-arrows',
}), getOpenIn('doc'))),
premiumP < 0 ? undefined : h('li', UI.setHTML(h('a.cp-app-drive-context-openinpresentation.dropdown-item' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
}), getOpenIn('doc'))) : undefined,
isAppEnabled('presentation') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openinpresentation.dropdown-item' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1',
'data-icon': 'fa-arrows',
}), getOpenIn('presentation'))),
}), getOpenIn('presentation'))) : undefined,
h('li', h('a.cp-app-drive-context-savelocal.dropdown-item', {
'tabindex': '-1',
'data-icon': 'fa-cloud-upload',
@ -429,57 +436,57 @@ define([
'data-icon': faUploadFolder,
}, Messages.uploadFolderButton)),
$separator.clone()[0],
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
isAppEnabled('pad') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.pad,
'data-type': 'pad'
}, Messages.button_newpad)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
}, Messages.button_newpad)) : undefined,
isAppEnabled('code') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.code,
'data-type': 'code'
}, Messages.button_newcode)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
}, Messages.button_newcode)) : undefined,
isAppEnabled('sheet') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.slide,
'data-type': 'slide'
}, Messages.button_newslide)),
'data-icon': AppConfig.applicationsIcon.sheet,
'data-type': 'sheet'
}, Messages.button_newsheet)) : undefined,
h('li.dropdown-submenu', [
h('a.cp-app-drive-context-newdocmenu.dropdown-item', {
'tabindex': '-1',
'data-icon': "fa-plus",
}, Messages.fm_morePads),
h("ul.dropdown-menu", [
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.sheet,
'data-type': 'sheet'
}, Messages.button_newsheet)),
premiumD === -1 ? undefined : h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
isAppEnabled('doc') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.doc,
'data-type': 'doc'
}, Messages.button_newdoc)),
premiumP === -1 ? undefined : h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
}, Messages.button_newdoc)) : undefined,
isAppEnabled('presentation') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.presentation,
'data-type': 'presentation'
}, Messages.button_newpresentation)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
}, Messages.button_newpresentation)) : undefined,
isAppEnabled('whiteboard') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.whiteboard,
'data-type': 'whiteboard'
}, Messages.button_newwhiteboard)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
}, Messages.button_newwhiteboard)) : undefined,
isAppEnabled('kanban') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.kanban,
'data-type': 'kanban'
}, Messages.button_newkanban)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
}, Messages.button_newkanban)) : undefined,
isAppEnabled('form') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.form,
'data-type': 'form'
}, Messages.button_newform)) : undefined,
isAppEnabled('slide') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.poll,
'data-type': 'poll'
}, Messages.button_newpoll)),
'data-icon': AppConfig.applicationsIcon.slide,
'data-type': 'slide'
}, Messages.button_newslide)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.link,

Loading…
Cancel
Save