Skip to content

Commit

Permalink
Fix permission for template tables
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Aug 8, 2024
1 parent ae08e14 commit f17250c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
import { ModelType } from '../../../../enums/ModelType';
import { TemplateTable } from '../../../../tables/settings/TemplateTable';

export default function LabelTemplatePanel() {
return (
<TemplateTable
templateProps={{
modelType: ModelType.labeltemplate,
templateEndpoint: ApiEndpoints.label_list,
printingEndpoint: ApiEndpoints.label_print,
additionalFormFields: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
import { ModelType } from '../../../../enums/ModelType';
import { TemplateTable } from '../../../../tables/settings/TemplateTable';

export default function ReportTemplateTable() {
return (
<TemplateTable
templateProps={{
modelType: ModelType.reporttemplate,
templateEndpoint: ApiEndpoints.report_list,
printingEndpoint: ApiEndpoints.report_print,
additionalFormFields: {
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/src/tables/settings/TemplateTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type TemplateI = {
};

export interface TemplateProps {
modelType: ModelType;
templateEndpoint: ApiEndpoints;
printingEndpoint: ApiEndpoints;
additionalFormFields?: ApiFormFieldSet;
Expand Down Expand Up @@ -175,18 +176,22 @@ export function TemplateTable({
title: t`Modify`,
tooltip: t`Modify template file`,
icon: <IconFileCode />,
onClick: () => openDetailDrawer(record.pk)
onClick: () => openDetailDrawer(record.pk),
hidden: !user.hasChangePermission(templateProps.modelType)
},
RowEditAction({
hidden: !user.hasChangePermission(templateProps.modelType),
onClick: () => {
setSelectedTemplate(record.pk);
editTemplate.open();
}
}),
RowDuplicateAction({
hidden: true
// TODO: Duplicate selected template
}),
RowDeleteAction({
hidden: !user.hasDeletePermission(templateProps.modelType),
onClick: () => {
setSelectedTemplate(record.pk);
deleteTemplate.open();
Expand Down Expand Up @@ -252,9 +257,10 @@ export function TemplateTable({
key="add-template"
onClick={() => newTemplate.open()}
tooltip={t`Add template`}
hidden={!user.hasAddPermission(templateProps.modelType)}
/>
];
}, []);
}, [user]);

const modelTypeFilters = useFilters({
url: apiUrl(templateEndpoint),
Expand Down

0 comments on commit f17250c

Please sign in to comment.