[pricelist] add permissions

This commit is contained in:
Tim Gröger 2021-04-14 22:42:09 +02:00
parent cee6eda585
commit 8b21ccf978
7 changed files with 103 additions and 18 deletions

View File

@ -19,7 +19,7 @@
</q-menu>
</q-btn>
<q-btn
v-if="!public && !nodetails && editable"
v-if="!public && !nodetails && editable && hasPermission(PERMISSIONS.CREATE)"
color="primary"
round
icon="mdi-plus"
@ -155,6 +155,8 @@ import { filter, Search } from '../utils/filter';
import { Notify } from 'quasar';
import { sort } from '../utils/sort';
import { DeleteObjects } from 'src/plugins/pricelist/utils/utils';
import { hasPermission } from 'src/utils/permission';
import { PERMISSIONS } from 'src/plugins/pricelist/permissions';
export default defineComponent({
name: 'CalculationTable',
@ -185,7 +187,6 @@ export default defineComponent({
void store.getDrinks();
});
const columns = [
{
name: 'picture',
@ -498,6 +499,8 @@ export default defineComponent({
notLoading,
getImageLoading,
newDrink,
hasPermission,
PERMISSIONS,
};
},
});

View File

@ -32,7 +32,7 @@ export default defineComponent({
props: {
steps: {
type: Array as PropType<Array<string>>,
default: undefined
default: undefined,
},
editable: {
type: Boolean,

View File

@ -26,7 +26,10 @@
step="0.001"
@update:model-value="updateVolume(volume)"
/>
<div v-if="deleteable && editable" class="q-pa-sm col-2 text-right">
<div
v-if="deleteable && editable && hasPermission(PERMISSIONS.DELETE_VOLUME)"
class="q-pa-sm col-2 text-right"
>
<q-btn round icon="mdi-delete" size="sm" color="negative" @click="deleteVolume">
<q-tooltip> Abgabe entfernen </q-tooltip>
</q-btn>
@ -41,7 +44,12 @@
<div class="q-pa-sm">
<div v-for="(price, index) in volume.prices" :key="price.id">
<div class="fit row justify-around q-py-sm">
<div v-if="!editable" class="text-body1 col-3">{{ price.price.toFixed(2) }}</div>
<div
v-if="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)"
class="text-body1 col-3"
>
{{ price.price.toFixed(2) }}
</div>
<q-input
v-else
v-model.number="price.price"
@ -58,13 +66,16 @@
<div class="text-body1 col-2">
<q-toggle
v-model="price.public"
:disable="!editable"
:disable="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)"
checked-icon="mdi-earth"
unchecked-icon="mdi-earth-off"
@update:model-value="change"
/>
</div>
<div v-if="!editable" class="text-body1 col-5">
<div
v-if="!editable || !hasPermission(PERMISSIONS.EDIT_PRICE)"
class="text-body1 col-5"
>
{{ price.description }}
</div>
<q-input
@ -76,7 +87,7 @@
label="Beschreibung"
@update:model-value="change"
/>
<div v-if="editable" class="col-1">
<div v-if="editable && hasPermission(PERMISSIONS.DELETE_PRICE)" class="col-1">
<q-btn round icon="mdi-delete" color="negative" size="xs" @click="deletePrice(price)">
<q-tooltip> Preis entfernen </q-tooltip>
</q-btn>
@ -90,7 +101,10 @@
>
Einer der Preise ist unterhalb des niedrigsten minimal Preises.
</div>
<div v-if="editable" class="full-width row justify-end text-right">
<div
v-if="editable && hasPermission(PERMISSIONS.EDIT_PRICE)"
class="full-width row justify-end text-right"
>
<q-btn round icon="mdi-plus" size="sm" color="primary">
<q-tooltip> Preis hinzufügen </q-tooltip>
<q-menu anchor="center middle" self="center middle">
@ -103,7 +117,7 @@
<ingredients
v-if="!public && !costPerVolume"
v-model="volume.ingredients"
:editable="editable"
:editable="editable && hasPermission(PERMISSIONS.EDIT_INGREDIENTS_DRINK)"
@update="updateVolume(volume)"
@delete-ingredient="deleteIngredient"
/>
@ -128,6 +142,9 @@ import { DrinkPriceVolume } from 'src/plugins/pricelist/store';
import Ingredients from 'src/plugins/pricelist/components/CalculationTable/Ingredients.vue';
import NewPrice from 'src/plugins/pricelist/components/CalculationTable/NewPrice.vue';
import { calc_volume, clone } from '../../utils/utils';
import { hasPermission } from 'src/utils/permission';
import { PERMISSIONS } from '../../permissions';
export default defineComponent({
name: 'DrinkPriceVolume',
components: { Ingredients, NewPrice },
@ -138,7 +155,7 @@ export default defineComponent({
},
costPerVolume: {
type: undefined,
default: undefined
default: undefined,
},
editable: {
type: Boolean,
@ -308,6 +325,8 @@ export default defineComponent({
deleteIngredient,
change,
isUnderMinPrice,
hasPermission,
PERMISSIONS,
};
},
});

View File

@ -126,7 +126,7 @@
<drink-price-volumes
v-model="edit_volumes"
:cost-per-volume="cost_per_volume"
editable
:editable="hasPermission(PERMISSIONS.EDIT_VOLUME)"
@update="updateVolume"
@delete-volume="deleteVolume"
@delete-price="deletePrice"
@ -150,6 +150,9 @@ import DrinkPriceVolumes from './CalculationTable/DrinkPriceVolumes.vue';
import { clone, calc_min_prices, DeleteObjects, calc_cost_per_volume } from '../utils/utils';
import BuildManual from 'src/plugins/pricelist/components/CalculationTable/BuildManual.vue';
import config from 'src/config';
import { hasPermission } from 'src/utils/permission';
import { PERMISSIONS } from 'src/plugins/pricelist/permissions';
export default defineComponent({
name: 'DrinkModify',
components: { BuildManual, DrinkPriceVolumes },
@ -343,6 +346,8 @@ export default defineComponent({
edit_volumes,
key,
hasIngredients,
hasPermission,
PERMISSIONS,
};
},
});

View File

@ -56,6 +56,7 @@ import CalculationTable from 'src/plugins/pricelist/components/CalculationTable.
import ExtraIngredients from 'src/plugins/pricelist/components/ExtraIngredients.vue';
import Tags from '../components/Tags.vue';
import { usePricelistStore } from 'src/plugins/pricelist/store';
import { hasPermissions } from 'src/utils/permission';
export default defineComponent({
name: 'Settings',
@ -64,6 +65,7 @@ export default defineComponent({
interface Tab {
name: string;
label: string;
permissions: Array<string>;
}
const store = usePricelistStore();
onBeforeMount(() => {
@ -90,13 +92,36 @@ export default defineComponent({
},
});
const tabs: Tab[] = [
{ name: 'pricelist', label: 'Getränke' },
{ name: 'extra_ingredients', label: 'Zutaten' },
{ name: 'drink_types', label: 'Getränketypen' },
{ name: 'tags', label: 'Tags' },
const _tabs: Tab[] = [
{ name: 'pricelist', label: 'Getränke', permissions: ['drink_edit'] },
{ name: 'extra_ingredients', label: 'Zutaten', permissions: [] },
{
name: 'drink_types',
label: 'Getränketypen',
permissions: ['drink_type_edit', 'drink_type_delete'],
},
{
name: 'tags',
label: 'Tags',
permissions: ['drink_tag_edit', 'drink_tag_create', 'drink_tag_delete'],
},
];
const tabs = computed(() => {
const retVal: Tab[] = [];
_tabs.forEach((tab) => {
if (tab.permissions.length > 0) {
if (hasPermissions(tab.permissions)) {
retVal.push(tab);
}
}
if (tab.permissions.length === 0) {
retVal.push(tab);
}
});
return retVal;
});
const tab = ref<string>('pricelist');
return { tabs, tab, showDrawer };

View File

@ -0,0 +1,33 @@
export const PERMISSIONS = {
CREATE: 'drink_create',
EDIT: 'drink_edit',
DELETE: 'drink_delete',
CREATE_TAG: 'drink_tag_create',
EDIT_PRICE: 'edit_price',
DELETE_PRICE: 'delete_price',
EDIT_VOLUME: 'edit_volume',
DELETE_VOLUME: 'delete_volume',
EDIT_INGREDIENTS_DRINK: 'edit_ingredients_drink',
DELETE_INGREDIENTS_DRINK: 'delete_ingredients_drink',
EDIT_INGREDIENTS: 'edit_ingredients',
DELETE_INGREDIENTS: 'delete_ingredients',
EDIT_TAG: 'drink_tag_edit',
DELETE_TAG: 'drink_tag_delete',
CREATE_TYPE: 'drink_type_create',
EDIT_TYPE: 'drink_type_edit',
DELETE_TYPE: 'drink_type_delete',
EDIT_MIN_PRICES: 'edit_min_prices',
};

View File

@ -48,7 +48,7 @@ export const innerRoutes: FG_Plugin.MenuRoute[] = [
title: 'Einstellungen',
icon: 'mdi-coffee-to-go',
shortcut: false,
permissions: ['user'],
permissions: ['drink_edit', 'drink_tag_edit'],
route: {
path: 'settings',
name: 'drinks-settings',