- Frontend restriction alerts

This commit is contained in:
Čarodej
2022-01-05 18:57:02 +01:00
parent 29a954e21b
commit 05f6023053
10 changed files with 108 additions and 12 deletions

View File

@@ -200,5 +200,22 @@
"/js/main.de28ca938da3825e62b3.hot-update.js": "/js/main.de28ca938da3825e62b3.hot-update.js",
"/js/main.be91e0ed3d68ecb1af06.hot-update.js": "/js/main.be91e0ed3d68ecb1af06.hot-update.js",
"/chunks/settings.91678a5fa053e1ee00a7.hot-update.js": "/chunks/settings.91678a5fa053e1ee00a7.hot-update.js",
"/js/main.000dc4eab65b819bb1e4.hot-update.js": "/js/main.000dc4eab65b819bb1e4.hot-update.js"
"/js/main.000dc4eab65b819bb1e4.hot-update.js": "/js/main.000dc4eab65b819bb1e4.hot-update.js",
"/js/main.116ea0e969f28f2e3317.hot-update.js": "/js/main.116ea0e969f28f2e3317.hot-update.js",
"/js/main.d5f72367ca387e8f88cb.hot-update.js": "/js/main.d5f72367ca387e8f88cb.hot-update.js",
"/js/main.e139d856a64d830e75f9.hot-update.js": "/js/main.e139d856a64d830e75f9.hot-update.js",
"/js/main.0b0a92c85a5ddddcdd92.hot-update.js": "/js/main.0b0a92c85a5ddddcdd92.hot-update.js",
"/js/main.2f9d8dd0af03586e9684.hot-update.js": "/js/main.2f9d8dd0af03586e9684.hot-update.js",
"/js/main.99e190ade21b090439a6.hot-update.js": "/js/main.99e190ade21b090439a6.hot-update.js",
"/js/main.ea2d431b51a8f35de10e.hot-update.js": "/js/main.ea2d431b51a8f35de10e.hot-update.js",
"/js/main.07af7a330df3dde83ee0.hot-update.js": "/js/main.07af7a330df3dde83ee0.hot-update.js",
"/js/main.f7c4174463f274fa781c.hot-update.js": "/js/main.f7c4174463f274fa781c.hot-update.js",
"/js/main.52062fffd84321cad2d6.hot-update.js": "/js/main.52062fffd84321cad2d6.hot-update.js",
"/js/main.90534c5ed92728291a82.hot-update.js": "/js/main.90534c5ed92728291a82.hot-update.js",
"/js/main.48702d509d5cf27a0fb6.hot-update.js": "/js/main.48702d509d5cf27a0fb6.hot-update.js",
"/js/main.6546f4fadc91e708018c.hot-update.js": "/js/main.6546f4fadc91e708018c.hot-update.js",
"/js/main.fcf019dfae2cac8e0432.hot-update.js": "/js/main.fcf019dfae2cac8e0432.hot-update.js",
"/js/main.b99796b9cd80dfca9231.hot-update.js": "/js/main.b99796b9cd80dfca9231.hot-update.js",
"/js/main.ff162a01c1b21836ee9f.hot-update.js": "/js/main.ff162a01c1b21836ee9f.hot-update.js",
"/js/main.7a46e4ea987d72347892.hot-update.js": "/js/main.7a46e4ea987d72347892.hot-update.js"
}

37
resources/js/helpers/AlertHelpers.js vendored Normal file
View File

@@ -0,0 +1,37 @@
import {events} from "../bus";
import i18n from "../i18n";
const AlertHelpers = {
install(Vue) {
Vue.prototype.$temporarilyDisabledUpload = function () {
events.$emit('alert:open', {
title: i18n.t('Upload is temporarily disabled'),
message: i18n.t('Please review your billing settings.')
})
}
Vue.prototype.$temporarilyDisabledFolderCreate = function () {
events.$emit('alert:open', {
title: i18n.t('Folder creation is temporarily disabled'),
message: i18n.t('Please review your billing settings.')
})
}
Vue.prototype.$temporarilyDisabledDownload = function () {
events.$emit('alert:open', {
title: i18n.t('File download is temporarily disabled'),
message: i18n.t('Please review your billing settings.')
})
}
Vue.prototype.$isSomethingWrong = function () {
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message')
})
}
}
}
export default AlertHelpers

View File

@@ -149,6 +149,12 @@ const FunctionHelpers = {
}
Vue.prototype.$uploadFiles = async function (files) {
// Show alert message when upload is disabled
if (! store.getters.user.data.meta.restrictions.canUpload) {
Vue.prototype.$temporarilyDisabledUpload()
return
}
if (files.length === 0) return
@@ -171,6 +177,12 @@ const FunctionHelpers = {
}
Vue.prototype.$uploadDraggedFiles = async function (event, parent_id) {
// Show alert message when upload is disabled
if (! store.getters.user.data.meta.restrictions.canUpload) {
Vue.prototype.$temporarilyDisabledUpload()
return
}
// Prevent submit empty files
if (event.dataTransfer.items.length === 0) return
@@ -258,6 +270,13 @@ const FunctionHelpers = {
}
Vue.prototype.$downloadFile = function (url, filename) {
// Show alert message when download is disabled
if (! store.getters.user.data.meta.restrictions.canDownload) {
Vue.prototype.$temporarilyDisabledDownload()
return
}
var anchor = document.createElement('a')
anchor.href = url
@@ -416,13 +435,6 @@ const FunctionHelpers = {
}
}
Vue.prototype.$isSomethingWrong = function () {
events.$emit('alert:open', {
title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message')
})
}
Vue.prototype.$checkFileMimetype = function (files) {
let validated = true
let mimetypesBlacklist = store.getters.config.mimetypesBlacklist

View File

@@ -24,12 +24,26 @@ const itemHelpers = {
}
Vue.prototype.$createFolder = function () {
// Show alert message when create folder is disabled
if (! store.getters.user.data.meta.restrictions.canCreateFolder) {
Vue.prototype.$temporarilyDisabledFolderCreate()
return
}
store.dispatch('createFolder', {
name: i18n.t('popup_create_folder.folder_default_name')
})
}
Vue.prototype.$downloadSelection = function (item) {
// Show alert message when download is disabled
if (! store.getters.user.data.meta.restrictions.canDownload) {
Vue.prototype.$temporarilyDisabledDownload()
return
}
let clipboard = store.getters.clipboard
if (clipboard.length > 1 || (clipboard.length === 1 && clipboard[0].data.type === 'folder'))
@@ -62,6 +76,13 @@ const itemHelpers = {
},
Vue.prototype.$createTeamFolder = function () {
// Show alert message when create folder is disabled
if (! store.getters.user.data.meta.restrictions.canCreateTeamFolder) {
Vue.prototype.$temporarilyDisabledFolderCreate()
return
}
events.$emit('popup:open', {name: 'create-team-folder'})
}

View File

@@ -10,12 +10,14 @@ import {events} from "./bus";
import SubscriptionHelpers from "./helpers/SubscriptionHelpers";
import ValidatorHelpers from "./helpers/ValidatorHelpers";
import functionHelpers from "./helpers/functionHelpers";
import AlertHelpers from "./helpers/AlertHelpers";
import itemHelpers from "./helpers/itemHelpers"
Vue.use(VueRouter);
Vue.use(SubscriptionHelpers);
Vue.use(ValidatorHelpers);
Vue.use(functionHelpers);
Vue.use(AlertHelpers);
Vue.use(itemHelpers);
Vue.config.productionTip = false;

View File

@@ -39,7 +39,7 @@ class DefaultRestrictionsEngine implements RestrictionsEngine
return true;
}
public function canInviteTeamMembers(User $user, array $newInvites): bool
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
{
return resolve(CheckMaxTeamMembersLimitAction::class)($user, $newInvites);
}

View File

@@ -34,7 +34,7 @@ class FixedBillingRestrictionsEngine implements RestrictionsEngine
return true;
}
public function canInviteTeamMembers(User $user, array $newInvites): bool
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
{
return resolve(CheckMaxTeamMembersLimitAction::class)($user, $newInvites);
}

View File

@@ -30,7 +30,7 @@ class MeteredBillingRestrictionsEngine implements RestrictionsEngine
return ! ($user->failedPayments()->count() >= 3);
}
public function canInviteTeamMembers(User $user, array $newInvites): bool
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
{
return true;
}

View File

@@ -13,5 +13,5 @@ interface RestrictionsEngine
public function canCreateTeamFolder(User $user): bool;
public function canInviteTeamMembers(User $user, array $newInvites): bool;
public function canInviteTeamMembers(User $user, array $newInvites = []): bool;
}

View File

@@ -58,6 +58,13 @@ class UserResource extends JsonResource
]),
],
'meta' => [
'restrictions' => [
'canUpload' => $this->canUpload(),
'canDownload' => $this->canDownload(),
'canCreateFolder' => $this->canCreateFolder(),
'canCreateTeamFolder' => $this->canCreateTeamFolder(),
'canInviteTeamMembers' => $this->canInviteTeamMembers(),
],
$this->mergeWhen($isFixedSubscription, fn () => [
'limitations' => $this->limitations->summary(),
]),