Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asinn134 committed Oct 24, 2024
1 parent dabfef5 commit 99d115b
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 76 deletions.
5 changes: 1 addition & 4 deletions services/common/src/components/forms/RenderFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ export const FileUpload: FC<FileUploadProps> = ({
metadata: {
filename: file.name,
filetype: file.type || APPLICATION_OCTET_STREAM,
maxfilenamelength: metadata.maxfilenamelength,
},
onError: (err, uploadResult) => {
setUploadResultsFor(fileId, uploadResult);
Expand Down Expand Up @@ -326,7 +325,6 @@ export const FileUpload: FC<FileUploadProps> = ({
metadata: {
filename: file.name,
filetype: file.type || APPLICATION_OCTET_STREAM,
maxfilenamelength: metadata.maxfilenamelength,
},
onBeforeRequest: (req) => {
// Set authorization header on each request to make use
Expand Down Expand Up @@ -465,9 +463,8 @@ export const FileUpload: FC<FileUploadProps> = ({
}, []);

const handleFileAdd = (err, file) => {
// Add properties to file metadata so we can reference it later
// Add ID to file metadata so we can reference it later
file.setMetadata("filepondid", file.id);
file.setMetadata("maxfilenamelength", maxFileNameLength);
};

const getLabel = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ exports[`Project Management renders properly 1`] = `
<span
class="ant-comment-content-author-time comment-time"
>
9
10
days ago
</span>
</div>
Expand Down Expand Up @@ -546,7 +546,7 @@ exports[`Project Management renders properly 1`] = `
<span
class="ant-comment-content-author-time comment-time"
>
9
10
days ago
</span>
</div>
Expand Down Expand Up @@ -612,7 +612,7 @@ exports[`Project Management renders properly 1`] = `
<span
class="ant-comment-content-author-time comment-time"
>
9
10
days ago
</span>
</div>
Expand Down
1 change: 0 additions & 1 deletion services/common/src/utils/fileUploadHelper.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface FileUploadHelperProps {
metadata: {
filename: string;
filetype: string;
maxfilenamelength: string;
};
uploadResults?: UploadResult[];
uploadData?: MultipartDocumentUpload;
Expand Down
4 changes: 4 additions & 0 deletions services/core-api/app/api/constants.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
from app.api.projects.project.models.project import Project
from app.api.mines.mine.models.mine import Mine
from app.api.services.document_manager_service import DocumentManagerService

from app.api.constants import MAX_DOCUMENT_NAME_LENGTHS

class InformationRequirementsTableDocumentUploadResource(Resource, UserMixin):
@api.doc(
description='Upload final Information Requirements Table (IRT) spreadsheet to S3 bucket.',
params={'project_guid': 'The GUID of the project the IRT belongs to.'})
def post(self, project_guid):
project = Project.find_by_project_guid(project_guid)

if not project:
raise NotFound('Project not found.')

mine = Mine.find_by_mine_guid(str(project.mine_guid))

if not mine:
raise NotFound('Mine not found.')

return DocumentManagerService.initializeFileUploadWithDocumentManager(
request, mine, 'information_requirements_table')
request, mine, 'information_requirements_table', MAX_DOCUMENT_NAME_LENGTHS['MAJOR_PROJECTS'])
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app.api.projects.project.models.project import Project
from app.api.mines.mine.models.mine import Mine
from app.api.services.document_manager_service import DocumentManagerService
from app.api.constants import MAX_DOCUMENT_NAME_LENGTHS


class MajorMineApplicationDocumentUploadResource(Resource, UserMixin):
Expand All @@ -30,4 +31,4 @@ def post(self, project_guid):
raise NotFound('Mine not found.')

return DocumentManagerService.initializeFileUploadWithDocumentManager(
request, mine, 'major_mine_application')
request, mine, 'major_mine_application', MAX_DOCUMENT_NAME_LENGTHS['MAJOR_PROJECTS'])
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app.api.projects.project.models.project import Project
from app.api.mines.mine.models.mine import Mine
from app.api.services.document_manager_service import DocumentManagerService
from app.api.constants import MAX_DOCUMENT_NAME_LENGTHS


class ProjectDecisionPackageDocumentUploadResource(Resource, UserMixin):
Expand All @@ -30,4 +31,4 @@ def post(self, project_guid):
raise NotFound('Mine not found.')

return DocumentManagerService.initializeFileUploadWithDocumentManager(
request, mine, 'project_decision_package')
request, mine, 'project_decision_package', MAX_DOCUMENT_NAME_LENGTHS['MAJOR_PROJECTS'])
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from app.api.services.document_manager_service import DocumentManagerService
from app.config import Config
from app.api.utils.feature_flag import is_feature_enabled, Feature
from app.api.constants import MAX_DOCUMENT_NAME_LENGTHS

class ProjectSummaryDocumentUploadResource(Resource, UserMixin):
@api.doc(
Expand All @@ -29,7 +30,8 @@ def post(self, project_guid, project_summary_guid):

if is_feature_enabled(Feature.MAJOR_PROJECT_REPLACE_FILE):
return DocumentManagerService.validateFileNameAndInitializeFileUploadWithDocumentManager(
request, mine, project_guid, 'project_summaries')
request, mine, project_guid, 'project_summaries', MAX_DOCUMENT_NAME_LENGTHS['MAJOR_PROJECTS'])
else:
return DocumentManagerService.initializeFileUploadWithDocumentManager(request, mine, 'project_summaries')
return DocumentManagerService.initializeFileUploadWithDocumentManager(
request, mine, 'project_summaries', MAX_DOCUMENT_NAME_LENGTHS['MAJOR_PROJECTS'])

12 changes: 6 additions & 6 deletions services/core-api/app/api/services/document_manager_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class DocumentManagerService():
document_manager_document_resource_url = f'{Config.DOCUMENT_MANAGER_URL}/documents'

@classmethod
def validateFileNameAndInitializeFileUploadWithDocumentManager(cls, request, mine, project_guid, document_category):
def validateFileNameAndInitializeFileUploadWithDocumentManager(
cls, request, mine, project_guid, document_category, max_document_name_length=None):

metadata = cls._parse_request_metadata(request)
file_name = metadata.get('filename')
Expand All @@ -44,7 +45,7 @@ def validateFileNameAndInitializeFileUploadWithDocumentManager(cls, request, min
resp = None

if not mine_document: # No existing file found in this application hence continuing the file uploading
resp = DocumentManagerService.initializeFileUploadWithDocumentManager(request, mine, document_category)
resp = DocumentManagerService.initializeFileUploadWithDocumentManager(request, mine, document_category, max_document_name_length)
elif mine_document.is_archived: # An archived file with the same name in this application found, hence responing with 409
content = {
"description" : f"Archived file already exist with the given name: {file_name}",
Expand Down Expand Up @@ -76,15 +77,14 @@ def validateFileNameAndInitializeFileUploadWithDocumentManager(cls, request, min
return resp

@classmethod
def initializeFileUploadWithDocumentManager(cls, request, mine, document_category):
def initializeFileUploadWithDocumentManager(cls, request, mine, document_category, max_document_name_length=None):
metadata = cls._parse_request_metadata(request)
if not metadata or not metadata.get('filename'):
raise Exception('Request metadata missing filename')

max_file_name_length = metadata.get('maxfilenamelength', None)
file_name = ((metadata.get('filename')).rsplit('.', 1))[0]
if max_file_name_length and max_file_name_length.isdigit() and len(file_name) > int(max_file_name_length):
raise BadRequest(f'File name exceeds the {max_file_name_length} character limit')
if max_document_name_length and len(file_name) > max_document_name_length:
raise BadRequest(f'File name exceeds the {max_document_name_length} character limit')

folder, pretty_folder = cls._parse_upload_folders(mine, document_category)
data = {
Expand Down
2 changes: 1 addition & 1 deletion services/core-web/cypress/e2e/majorprojects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("Major Projects", () => {
expect(interception.request.headers["upload-length"]).to.equal("16368");
expect(interception.request.headers["upload-protocol"]).to.equal("s3-multipart");
expect(interception.request.headers["upload-metadata"]).to.equal(
"filename ZHVtbXkucGRm,filetype YXBwbGljYXRpb24vcGRm,maxfilenamelength NTA="
"filename ZHVtbXkucGRm,filetype YXBwbGljYXRpb24vcGRm"
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import PropTypes from "prop-types";
import { compose } from "redux";
import { Field, reduxForm, getFormValues } from "redux-form";
import { connect } from "react-redux";
import { Form } from "@ant-design/compatible";
import "@ant-design/compatible/assets/index.css";
import { Button, Col, Row, Popconfirm, Typography, Divider, Checkbox } from "antd";
import { Button, Col, Row, Popconfirm, Typography, Divider, Checkbox, Form } from "antd";
import { resetForm } from "@common/utils/helpers";
import * as FORM from "@/constants/forms";
import ProjectDecisionPackageFileUpload from "@/components/mine/Projects/ProjectDecisionPackageFileUpload";
Expand Down Expand Up @@ -65,16 +63,14 @@ export const UploadProjectDecisionPackageDocumentForm = (props) => {
</Row>
<Row gutter={16}>
<Col span={24}>
<Form.Item className="decision-package-uploads">
<Field
id="uploadedFiles"
name="uploadedFiles"
onFileLoad={onFileLoad}
onRemoveFile={onRemoveFile}
projectGuid={props.projectGuid}
component={ProjectDecisionPackageFileUpload}
/>
</Form.Item>
<Field
id="uploadedFiles"
name="uploadedFiles"
onFileLoad={onFileLoad}
onRemoveFile={onRemoveFile}
projectGuid={props.projectGuid}
component={ProjectDecisionPackageFileUpload}
/>
</Col>
</Row>
{isDecisionPackageEligible && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import { Field } from "redux-form";
import { Form } from "@ant-design/compatible";
import "@ant-design/compatible/assets/index.css";
import { PROJECT_DECISION_PACKAGE_DOCUMENTS } from "@mds/common/constants/API";
import FileUpload from "@/components/common/FileUpload";
import { DOCUMENT, EXCEL, IMAGE, SPATIAL } from "@/constants/fileTypes";
Expand All @@ -16,22 +14,20 @@ const propTypes = {
};

export const ProjectDecisionPackageFileUpload = (props) => (
<Form.Item>
<Field
id="fileUpload"
name="fileUpload"
component={FileUpload}
uploadUrl={PROJECT_DECISION_PACKAGE_DOCUMENTS(props.projectGuid)}
acceptedFileTypesMap={{ ...DOCUMENT, ...EXCEL, ...IMAGE, ...SPATIAL }}
onFileLoad={props.onFileLoad}
onRemoveFile={props.onRemoveFile}
allowRevert
allowMultiple={props.allowMultiple}
maxFileNameLength={MAX_DOCUMENT_NAME_LENGTHS.MAJOR_PROJECTS}
abbrevLabel={true}
label="Upload Files"
/>
</Form.Item>
<Field
id="fileUpload"
name="fileUpload"
component={FileUpload}
uploadUrl={PROJECT_DECISION_PACKAGE_DOCUMENTS(props.projectGuid)}
acceptedFileTypesMap={{ ...DOCUMENT, ...EXCEL, ...IMAGE, ...SPATIAL }}
onFileLoad={props.onFileLoad}
onRemoveFile={props.onRemoveFile}
allowRevert
allowMultiple={props.allowMultiple}
maxFileNameLength={MAX_DOCUMENT_NAME_LENGTHS.MAJOR_PROJECTS}
abbrevLabel={true}
label="Upload Files"
/>
);

ProjectDecisionPackageFileUpload.propTypes = propTypes;
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion services/core-web/src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@
@import "./components/PermitConditions.scss";
@import "./components/HelpGuide.scss";
@import "./components/RichTextEditor.scss";
@import "./components/MajorMineApplication.scss";

// UTILITIES - utilities and helper classes. This layer has the highest specificity.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UploadProjectDecisionPackageDocumentForm renders properly 1`] = `
<Form
colon={true}
hideRequiredMark={false}
<ForwardRef(InternalForm)
layout="vertical"
onSubmit={[Function]}
>
<Row
gutter={16}
Expand All @@ -29,19 +26,14 @@ exports[`UploadProjectDecisionPackageDocumentForm renders properly 1`] = `
<Col
span={24}
>
<FormItem
className="decision-package-uploads"
hasFeedback={false}
>
<Field
component={[Function]}
id="uploadedFiles"
name="uploadedFiles"
onFileLoad={[Function]}
onRemoveFile={[Function]}
projectGuid="ed678588-1e92-4cfc-b2aa-29332931d1ca"
/>
</FormItem>
<Field
component={[Function]}
id="uploadedFiles"
name="uploadedFiles"
onFileLoad={[Function]}
onRemoveFile={[Function]}
projectGuid="ed678588-1e92-4cfc-b2aa-29332931d1ca"
/>
</Col>
</Row>
<div
Expand Down Expand Up @@ -72,5 +64,5 @@ exports[`UploadProjectDecisionPackageDocumentForm renders properly 1`] = `
Update
</Button>
</div>
</Form>
</ForwardRef(InternalForm)>
`;

0 comments on commit 99d115b

Please sign in to comment.