Skip to content

Commit

Permalink
HOTFIX: psp-5105, psp-5123 (#2539)
Browse files Browse the repository at this point in the history
* psp-5105 allow for missing content-length header in mayan document download response.

* Prevent document list view from displaying when the user does not have permissions within activities.

* increment hotfix number.

* test corrections.

Co-authored-by: Smith <[email protected]>
  • Loading branch information
devinleighsmith and Smith authored Dec 14, 2022
1 parent 977c50a commit e3cb685
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 815 deletions.
6 changes: 3 additions & 3 deletions source/backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>3.0.0-41.15</Version>
<Version>3.0.0-41.15</Version>
<AssemblyVersion>3.0.0.41</AssemblyVersion>
<Version>3.0.1-41.15</Version>
<Version>3.0.1-41.15</Version>
<AssemblyVersion>3.0.1.41</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>16BC0468-78F6-4C91-87DA-7403C919E646</ProjectGuid>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -173,6 +175,8 @@ public async Task<ExternalResult<FileDownload>> DownloadFileAsync(long documentI
HttpResponseMessage response = await client.GetAsync(endpoint).ConfigureAwait(true);
byte[] payload = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(true);
_logger.LogTrace("Response: {response}", response);
response.Content.Headers.TryGetValues("Content-Length", out IEnumerable<string> contentLengthHeaders);
int contentLength = contentLengthHeaders?.FirstOrDefault() != null ? int.Parse(contentLengthHeaders.FirstOrDefault()) : payload.Length;
switch (response.StatusCode)
{
case HttpStatusCode.OK:
Expand All @@ -183,7 +187,7 @@ public async Task<ExternalResult<FileDownload>> DownloadFileAsync(long documentI
retVal.Payload = new FileDownload()
{
FilePayload = payload,
Size = int.Parse(response.Content.Headers.GetValues("Content-Length").FirstOrDefault()),
Size = contentLength,
Mimetype = response.Content.Headers.GetValues("Content-Type").FirstOrDefault(),
FileName = fileName,
};
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "3.0.0-41.15",
"version": "3.0.1-41.15",
"private": true,
"dependencies": {
"@bcgov/bc-sans": "1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ describe('ActivityForm test', () => {
{
...renderOptions,
store: storeState,
claims: renderOptions?.claims ?? [Claims.ACTIVITY_EDIT, Claims.PROPERTY_EDIT],
claims: renderOptions?.claims ?? [
Claims.ACTIVITY_EDIT,
Claims.PROPERTY_EDIT,
Claims.DOCUMENT_VIEW,
Claims.NOTE_VIEW,
],
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const onEditRelatedProperties = jest.fn();
jest.mock('@react-keycloak/web');

describe('ActivityView test', () => {
const setup = (renderOptions?: RenderOptions & IActivityViewProps) => {
const setup = (renderOptions?: RenderOptions & Partial<IActivityViewProps>) => {
// render component under test
const component = render(
<Formik onSubmit={noop} initialValues={renderOptions?.activity ?? getMockActivityResponse()}>
Expand Down Expand Up @@ -65,19 +65,19 @@ describe('ActivityView test', () => {
});

it('sections are expanded by default', async () => {
const { getByTitle } = setup();
const { getByTitle } = setup({ claims: [Claims.DOCUMENT_VIEW, Claims.NOTE_VIEW] });
expect(getByTitle('collapse-documents')).toBeInTheDocument();
expect(getByTitle('collapse-notes')).toBeInTheDocument();
expect(getByTitle('collapse-description')).toBeInTheDocument();
});

it('documents are displayed', async () => {
const { getByText } = setup();
const { getByText } = setup({ claims: [Claims.DOCUMENT_VIEW] });
expect(getByText('Document type')).toBeVisible();
});

it('notes are displayed', async () => {
const { getByText } = setup();
const { getByText } = setup({ claims: [Claims.NOTE_VIEW] });
expect(getByText('Note')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Claims } from 'constants/claims';
import { DocumentRelationshipType } from 'constants/documentRelationshipType';
import { NoteTypes } from 'constants/noteTypes';
import DocumentListContainer from 'features/documents/list/DocumentListContainer';
import { Section } from 'features/mapSideBar/tabs/Section';
import { NoteListView } from 'features/notes/list/NoteListView';
import useKeycloakWrapper from 'hooks/useKeycloakWrapper';
import * as React from 'react';
import styled from 'styled-components';

Expand All @@ -27,6 +29,7 @@ export const ActivityView: React.FunctionComponent<IActivityViewProps> = ({
onEditRelatedProperties,
children,
}) => {
const { hasClaim } = useKeycloakWrapper();
return (
<>
<ActivityHeader file={file} activity={activity} />
Expand All @@ -39,11 +42,15 @@ export const ActivityView: React.FunctionComponent<IActivityViewProps> = ({
<ActivityDescription isEditable={isEditable} editMode={editMode} />
</Section>
{children}
<DocumentListContainer
relationshipType={DocumentRelationshipType.ACTIVITIES}
parentId={activity.id}
/>
<NoteListView type={NoteTypes.Activity} entityId={activity.id} />
{hasClaim(Claims.DOCUMENT_VIEW) && (
<DocumentListContainer
relationshipType={DocumentRelationshipType.ACTIVITIES}
parentId={activity.id}
/>
)}
{hasClaim(Claims.NOTE_VIEW) && (
<NoteListView type={NoteTypes.Activity} entityId={activity.id} />
)}
</StyledContent>
</>
);
Expand Down
Loading

0 comments on commit e3cb685

Please sign in to comment.