Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru-aot committed Feb 21, 2024
1 parent f02433b commit 5542f85
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
7 changes: 4 additions & 3 deletions services/common/src/components/comments/CommentEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export class CommentEditor extends Component {

render() {
const canAddComment = this.props.addCommentPermission
? this.props.userRoles.includes(USER_ROLES[this.props.addCommentPermission])
? Object.values(USER_ROLES).includes(this.props.addCommentPermission)
: true;

const minespaceReadyForComments = false;

return (
<div>
{canAddComment && (
Expand All @@ -65,8 +67,7 @@ export class CommentEditor extends Component {
/>
</Form.Item>
)}
{// TODO: Hide until Minespace is updated to display comments.
false && (
{minespaceReadyForComments && (
<Form.Item>
<Checkbox
name="visible"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe("ReportDetailsForm", () => {
</div>
}
handleSubmit={() => {}}
createPermission={"role_edit_incidents"}
/>
</ReduxWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ describe("ReportDetailsForm", () => {
</div>
}
handleSubmit={() => {}}
createPermission={"role_edit_incidents"}
/>
</ReduxWrapper>
);
Expand Down
9 changes: 5 additions & 4 deletions services/common/src/components/reports/ReportDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
} from "@mds/common/redux/actionCreators/reportCommentActionCreator";
import AuthorizationWrapper from "@mds/common/wrappers/AuthorizationWrapper";
import * as Permission from "@mds/common/constants/permissions";
import * as PermissionEnv from "@mds/common/constants/environment";

const RenderContacts: FC<any> = ({ fields, isEditMode, mineSpaceEdit }) => {
const canEdit = isEditMode && !mineSpaceEdit;
Expand Down Expand Up @@ -97,7 +98,6 @@ interface ReportDetailsFormProps {
formButtons: ReactNode;
handleSubmit: (values) => void;
currentReportDefinition?: IMineReportDefinition;
createPermission: string;
}

const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
Expand All @@ -107,8 +107,9 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
formButtons,
handleSubmit,
currentReportDefinition,
createPermission = Permission.EDIT_INCIDENTS,
}) => {
const coreEditReportPermission = PermissionEnv.USER_ROLES.role_edit_reports;
const coreViewAllPermission = PermissionEnv.USER_ROLES.role_view;
const dispatch = useDispatch();
const formValues: IMineReportSubmission =
useSelector((state) => getFormValues(FORM.VIEW_EDIT_REPORT)(state)) ?? {};
Expand Down Expand Up @@ -470,7 +471,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
</Typography.Title>
</Col>
<Col span={24}>
<AuthorizationWrapper permission={createPermission}>
<AuthorizationWrapper permission={coreViewAllPermission}>
<Typography.Paragraph>
<strong>
These comments are for internal staff only and will not be shown to proponents.
Expand All @@ -490,7 +491,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
actions: null,
datetime: comment.timestamp,
}))}
createPermission={createPermission}
createPermission={coreEditReportPermission}
/>
</Col>
</Row>
Expand Down
18 changes: 15 additions & 3 deletions services/common/src/wrappers/AuthorizationWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { startCase, camelCase } from "lodash";
import { getUserAccessData } from "@mds/common/redux/selectors/authenticationSelectors";
import { USER_ROLES, detectDevelopmentEnvironment, detectProdEnvironment } from "@mds/common";
import { Tooltip } from "antd";
import * as Permission from "@mds/common/constants/permissions";
// import * as Permission from "@mds/common/constants/permissions";
import * as Permission from "@mds/common/constants/environment";

/**
* @constant AuthorizationWrapper conditionally renders react children depending
Expand Down Expand Up @@ -63,14 +64,25 @@ const defaultProps = {
};

export const AuthorizationWrapper = (props) => {
console.log("props....auth wrapper...: ", props);
const inDevCheck =
props.inDevelopment === undefined || (props.inDevelopment && detectDevelopmentEnvironment());
const inTestCheck =
props.inTesting === undefined || (props.inTesting && !detectProdEnvironment());
// const permissionCheck =
// props.permission === undefined || props.userRoles.includes(USER_ROLES[props.permission]);
const permissionCheck =
props.permission === undefined || props.userRoles.includes(USER_ROLES[props.permission]);
props.permission === undefined || Object.values(USER_ROLES).includes(props.permission);

const isMajorMine = props.isMajorMine === undefined || props.isMajorMine;
const isAdmin = props.userRoles.includes(USER_ROLES[Permission.ADMIN]);
// const isAdmin = props.userRoles.includes(USER_ROLES[Permission.USER_ROLES.role_admin]);
const isAdmin = Object.values(USER_ROLES).includes(Permission.USER_ROLES.role_admin);

console.log("Auth Wrapper - props.userRoles: ", props.userRoles);
console.log("Auth Wrapper - props.permission: ", props.permission);
console.log("Auth Wrapper - USER_ROLES: ", USER_ROLES);
console.log("Auth Wrapper - USER_ROLES[props.permission]: ", USER_ROLES[props.permission]);
console.log("permissionCheck: ", permissionCheck);

const title = () => {
const permission = props.permission ? `${USER_ROLES[props.permission]}` : "";
Expand Down

0 comments on commit 5542f85

Please sign in to comment.