diff --git a/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPI.ts b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPI.ts new file mode 100644 index 00000000000..512b17c44c4 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/axiosAPIs/rolesAPI.ts @@ -0,0 +1,66 @@ +/* + * Copyright 2021 Collate + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AxiosResponse } from 'axios'; +import { Operation } from 'fast-json-patch'; +import { Policy } from '../pages/RolesPage/policy.interface'; +import { getURLWithQueryFields } from '../utils/APIUtils'; +import APIClient from './index'; + +export const getRoles = ( + arrQueryFields?: string | string[] +): Promise => { + const url = getURLWithQueryFields('/roles', arrQueryFields); + + return APIClient.get(`${url}${arrQueryFields ? '&' : '?'}limit=1000000`); +}; +export const getRoleByName = ( + name: string, + arrQueryFields?: string | string[] +): Promise => { + const url = getURLWithQueryFields(`/roles/name/${name}`, arrQueryFields); + + return APIClient.get(url); +}; + +export const createRole = ( + data: Record +): Promise => { + return APIClient.post('/roles', data); +}; + +export const updateRole = ( + id: string, + patch: Operation[] +): Promise => { + const configOptions = { + headers: { 'Content-type': 'application/json-patch+json' }, + }; + + return APIClient.patch(`/roles/${id}`, patch, configOptions); +}; + +export const getPolicy = ( + id: string, + arrQueryFields?: string | string[] +): Promise => { + const url = getURLWithQueryFields(`/policies/${id}`, arrQueryFields); + + return APIClient.get(url); +}; + +export const updatePolicy = ( + data: Pick +): Promise => { + return APIClient.put(`/policies`, data); +}; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Modals/RulesModal/AddRuleModal.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Modals/RulesModal/AddRuleModal.tsx new file mode 100644 index 00000000000..652cc84bec8 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/Modals/RulesModal/AddRuleModal.tsx @@ -0,0 +1,169 @@ +/* + * Copyright 2021 Collate + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import classNames from 'classnames'; +import { isUndefined } from 'lodash'; +import { FormErrorData } from 'Models'; +import React, { FC, useState } from 'react'; +import { RuleAccess } from '../../../enums/rule.enum'; +import { + Operation, + Rule, +} from '../../../generated/entity/policies/accessControl/rule'; +import { errorMsg } from '../../../utils/CommonUtils'; +import { Button } from '../../buttons/Button/Button'; + +interface AddRuleProps { + header: string; + errorData?: FormErrorData; + initialData: Rule; + isEditing?: boolean; + onCancel: () => void; + onSave: (data: Rule) => void; + onChange?: (data: Rule) => void; +} + +const AddRuleModal: FC = ({ + onCancel, + header, + initialData, + errorData, + onSave, + isEditing = false, + onChange, +}: AddRuleProps) => { + const [data, setData] = useState(initialData); + const [access, setAccess] = useState( + initialData.allow ? RuleAccess.ALLOW : RuleAccess.DENY + ); + const [isEnabled, setIsEnabled] = useState( + Boolean(initialData.enabled) + ); + const onChangeHadler = ( + e: React.ChangeEvent + ) => { + e.persist(); + let rule = data; + setData((prevState) => { + rule = { + ...prevState, + [e.target.name]: e.target.value, + }; + + return rule; + }); + onChange?.(rule); + }; + + const onSubmitHandler = (e: React.FormEvent) => { + e.preventDefault(); + const rule = { + ...data, + allow: access === RuleAccess.ALLOW, + enabled: isEnabled, + }; + onSave(rule); + onChange?.(rule); + }; + + return ( + +
onCancel()} /> +
+
+
+

+ {header} +

+
+
+ {!isUndefined(initialData.operation) && ( +
+ + + {errorData?.operation && errorMsg(errorData.operation)} +
+ )} + +
+ + +
+
+ +
setIsEnabled((pre) => !pre)}> +
+
+
+
+
+ + +
+ +
+
+ ); +}; + +export default AddRuleModal; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/Toast/Toast.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/Toast/Toast.tsx index d68eb4f3dc4..c384d5109a5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/Toast/Toast.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/Toast/Toast.tsx @@ -49,7 +49,9 @@ const Toast = (props: ToastProps) => { /> -
{body}
+
+ {body} +
+ + + + ); + }; + + const fetchLeftPanel = () => { + return ( + <> +
+
Roles
+ +