diff --git a/bbbeasy-backend/app/src/Actions/Roles/Edit.php b/bbbeasy-backend/app/src/Actions/Roles/Edit.php index aa94900d..9e6fee4f 100644 --- a/bbbeasy-backend/app/src/Actions/Roles/Edit.php +++ b/bbbeasy-backend/app/src/Actions/Roles/Edit.php @@ -68,6 +68,14 @@ public function save($f3, $params): void return; } + + if ($role->id == 1 || $role->id == 2) { + $this->logger->error('Role could not be updated', ['error' => 'Role could not be updated']); + $this->renderJson(['errors' => ['id' => 'Role could not be updated']], ResponseCode::HTTP_PRECONDITION_FAILED); + + return; + } + } else { $this->logger->error($errorMessage, ['errors' => $dataChecker->getErrors()]); $this->renderJson(['errors' => $dataChecker->getErrors()], ResponseCode::HTTP_UNPROCESSABLE_ENTITY); diff --git a/bbbeasy-frontend/src/components/EditableTableUsers.tsx b/bbbeasy-frontend/src/components/EditableTableUsers.tsx new file mode 100644 index 00000000..ea4f647a --- /dev/null +++ b/bbbeasy-frontend/src/components/EditableTableUsers.tsx @@ -0,0 +1,146 @@ +/** + * BBBEasy open source platform - https://riadvice.tn/ + * + * Copyright (c) 2022-2023 RIADVICE SUARL and by respective authors (see below). + * + * This program is free software; you can redistribute it and/or modify it under the + * terms of the GNU Affero General Public License as published by the Free Software + * Foundation; either version 3.0 of the License, or (at your option) any later + * version. + * + * BBBeasy is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License along + * with BBBEasy; if not, see . + */ + +import React from 'react'; +import { Trans } from 'react-i18next'; +import EN_US from '../locale/en-US.json'; +import { t } from 'i18next'; + +import { Form, Space } from 'antd'; + +import { RecordingType } from '../types/RecordingType'; +import { UserType } from '../types/UserType'; +import { RoleType } from '../types/RoleType'; +import { LabelType } from '../types/LabelType'; + +type Props = { + editing: boolean; + children: React.ReactNode; + dataIndex: string; + record: RecordingType | LabelType | UserType | RoleType; + inputNode: JSX.Element; + errorsEdit: object; + editRules?: object; + + editable?: boolean; + editComponent?: React.ReactNode; + mouseOverFct?: () => void; + mouseLeaveFct?: () => void; + + showLabelColor?: boolean; + inputColor?: JSX.Element; +}; + +const EditableTableUsers: React.FC = ({ + editing, + children, + dataIndex, + record, + inputNode, + errorsEdit, + editRules, + editable, + editComponent, + mouseOverFct, + mouseLeaveFct, + showLabelColor, + inputColor, + ...restProps + }) => { + let firstTest = false; + let secondTest = false; + + if (editable != undefined) { + if (editing) { + firstTest = true; + } else { + secondTest = true; + } + } else { + if (editing) { + firstTest = true; + } + } + + const customFormItem = (index: string, customInputNode: JSX.Element) => { + if (index != 'description') { + return ( + EN_US[elem] == errorsEdit[index])} + /> + ), + validateStatus: 'error', + })} + rules={[ + { + required: true, + message: t('required_' + index), + }, + { ...editRules }, + ]} + > + {customInputNode} + + ); + } else { + return ( + EN_US[elem] == errorsEdit[index])} + /> + ), + validateStatus: 'error', + })} + > + {customInputNode} + + ); + } + }; + + return ( + + {firstTest ? ( + + {customFormItem(dataIndex, inputNode)} + {showLabelColor && customFormItem('color', inputColor)} + + ) : secondTest ? ( + <> + {children} + {editComponent} + + ) : ( + children + )} + + ); +}; + +export default EditableTableUsers; diff --git a/bbbeasy-frontend/src/components/Presets.tsx b/bbbeasy-frontend/src/components/Presets.tsx index e21b43bc..bb809452 100644 --- a/bbbeasy-frontend/src/components/Presets.tsx +++ b/bbbeasy-frontend/src/components/Presets.tsx @@ -98,12 +98,12 @@ type formType = { }; const PresetsCol: React.FC = ({ - key, - preset, - editName, - editClickHandler, - copyClickHandler, - deleteClickHandler, + key, + preset, + editName, + editClickHandler, + copyClickHandler, + deleteClickHandler, }) => { const [file, setFile] = React.useState(null); const [fileList, setFileList] = React.useState(null); @@ -208,6 +208,9 @@ const PresetsCol: React.FC = ({ setErrorsEdit({}); setIsEditing(false); }; + function compareObjs(obj1,obj2){ + return JSON.stringify(obj1)===JSON.stringify(obj2); + } const handleSaveEdit = async () => { setErrorsEdit({}); try { @@ -215,6 +218,11 @@ const PresetsCol: React.FC = ({ PresetsService.edit_preset(values, preset.id) .then((response) => { + if (compareObjs(response.data.preset, preset)) { + Notifications.openNotificationWithIcon('info', t('no_changes')); + cancelEdit(); + return; + } editClickHandler(response.data.preset, preset); cancelEdit(); @@ -395,8 +403,8 @@ const PresetsCol: React.FC = ({ ? 'leftTop' : 'left' : item.enabled - ? 'rightTop' - : 'right' + ? 'rightTop' + : 'right' } overlayClassName={item.enabled ? 'install-tooltip' : 'title-tooltip'} title={ @@ -472,11 +480,11 @@ const PresetsCol: React.FC = ({ value={ item.value == true ? ReactDomServer.renderToString( - - ) + + ) : ReactDomServer.renderToString( - - ) + + ) } /> @@ -573,8 +581,8 @@ const PresetsCol: React.FC = ({ label: 'Guest Policy' == modalTitle ? ReactDomServer.renderToString( - - ) + + ) : data.name, value: data.value, }))} @@ -651,10 +659,7 @@ const Presets = () => { //edit const editPreset = (newPreset: MyPresetType, oldPreset: MyPresetType) => { - if (newPreset.name == oldPreset.name) { - Notifications.openNotificationWithIcon('info', t('no_changes')); - return; - } + const newPresets = [...myPresets]; const index = newPresets.findIndex((item) => oldPreset.id === item.id); if (index > -1 && newPreset != undefined) { diff --git a/bbbeasy-frontend/src/components/Roles.tsx b/bbbeasy-frontend/src/components/Roles.tsx index 42a1baa0..734b9812 100644 --- a/bbbeasy-frontend/src/components/Roles.tsx +++ b/bbbeasy-frontend/src/components/Roles.tsx @@ -23,7 +23,7 @@ import EN_US from '../locale/en-US.json'; import { PageHeader } from '@ant-design/pro-layout'; -import { Button, Row, Col, Typography, Space, Modal, Popconfirm, Card, Checkbox, Input } from 'antd'; +import {Button, Row, Col, Typography, Space, Modal, Popconfirm, Card, Checkbox, Input, Alert} from 'antd'; import { DeleteOutlined, QuestionCircleOutlined, @@ -408,12 +408,20 @@ const Roles = () => { editable={editable} editComponent={ isShown && - AuthService.isAllowedAction(actions, 'edit') && ( + AuthService.isAllowedAction(actions, 'edit') &&(