Skip to content

Commit

Permalink
Merge pull request #844 from assemblee-virtuelle/821_return_201_when_…
Browse files Browse the repository at this point in the history
…upload_finish_and_500_if_upload_fail

return 201 when upload finish (and not before) and 500 if upload fail
  • Loading branch information
simonLouvet committed Sep 10, 2021
2 parents e0be4db + a5569bd commit 40f11d5
Show file tree
Hide file tree
Showing 15 changed files with 17,582 additions and 18,836 deletions.
36,128 changes: 17,440 additions & 18,688 deletions src/frontend/boilerplates/archipelago/package-lock.json

Large diffs are not rendered by default.

220 changes: 95 additions & 125 deletions src/frontend/boilerplates/dms/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const AvatarField = ({ record, label, defaultLabel, image, fallback, variant, la
classes = useStyles(classes);
if (!record) return null;

const computedLabel = ( typeof label === 'function' ? label(record) : record[label] ) || defaultLabel;
const computedLabel = (typeof label === 'function' ? label(record) : record[label]) || defaultLabel;
const computedImage = typeof image === 'function' ? image(record) : record[image];
const computedFallback = typeof fallback === 'function' ? fallback(record) : fallback;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const SeparatedListField = props => {
const { ids, data, loaded, resource, basePath } = useListContext(props);

if (linkType !== undefined) {
console.warn(
"The 'linkType' prop is deprecated and should be named to 'link' in <SeparatedListField />"
);
console.warn("The 'linkType' prop is deprecated and should be named to 'link' in <SeparatedListField />");
link = linkType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const LocalLoginPage = props => {
const redirectTo = searchParams.get('redirect');
const { identity } = useGetIdentity();

if( identity?.id ) {
if (identity?.id) {
// Do not show login page if user is already connected
return( <Redirect to={redirectTo || '/'} /> );
return <Redirect to={redirectTo || '/'} />;
} else {
return (
<ThemeProvider theme={muiTheme}>
Expand All @@ -61,7 +61,11 @@ const LocalLoginPage = props => {
<LockIcon />
</Avatar>
</div>
{isSignup ? <SignupForm redirectTo={redirectTo} delayBeforeRedirect={3000} /> : <LoginForm redirectTo={redirectTo} />}
{isSignup ? (
<SignupForm redirectTo={redirectTo} delayBeforeRedirect={3000} />
) : (
<LoginForm redirectTo={redirectTo} />
)}
<div className={classes.switch}>
{isSignup ? (
<Link to="/login">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const SignupForm = ({ redirectTo, delayBeforeRedirect }) => {
setLoading(true);
signup(values)
.then(webId => {
if(delayBeforeRedirect) {
if (delayBeforeRedirect) {
setTimeout(() => {
history.push(redirectTo || '/Person/' + encodeURIComponent(webId) + '/edit');
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const useStyles = makeStyles(theme => ({
text: {
maxWidth: 300,
textAlign: 'center',
padding: '4px 8px 8px',
padding: '4px 8px 8px'
},
card: {
minWidth: 300,
Expand Down Expand Up @@ -90,7 +90,11 @@ const SsoLoginPage = ({ theme, history, location, buttons, userResource, text })
<LockIcon />
</Avatar>
</div>
{text && <Typography variant="body2" className={classes.text}>{text}</Typography>}
{text && (
<Typography variant="body2" className={classes.text}>
{text}
</Typography>
)}
{buttons &&
buttons.map((button, i) => (
<CardActions key={i}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react';
import { usePermissionsOptimized, useRedirect, useNotify, useGetIdentity } from 'react-admin';
import { rights, forbiddenErrors } from '../constants';
import useCheckAuthenticated from "./useCheckAuthenticated";
import useCheckAuthenticated from './useCheckAuthenticated';

const useCheckPermissions = (resourceId, mode, redirectUrl = '/') => {
const { identity } = useCheckAuthenticated();
Expand Down
8 changes: 2 additions & 6 deletions src/frontend/packages/auth-provider/src/hooks/useSignup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { useAuthProvider } from 'react-admin';
const useSignup = () => {
const authProvider = useAuthProvider();

return useCallback(
(params = {}) =>
authProvider.signup(params),
[authProvider]
);
return useCallback((params = {}) => authProvider.signup(params), [authProvider]);
};

export default useSignup;
export default useSignup;
12 changes: 10 additions & 2 deletions src/frontend/packages/semantic-data-provider/src/dataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ const isType = (type, resource) => {
return Array.isArray(resourceType) ? resourceType.includes(type) : resourceType === type;
};

const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonContext, uploadsContainerUri, returnFailedResources = false }) => {
const dataProvider = ({
sparqlEndpoint,
httpClient,
resources,
ontologies,
jsonContext,
uploadsContainerUri,
returnFailedResources = false
}) => {
const uploadFile = async rawFile => {
if (!uploadsContainerUri) throw new Error('No uploadsContainerUri defined for the data provider');

Expand Down Expand Up @@ -258,7 +266,7 @@ const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonC
// Catch if one resource fails to load
// Otherwise no references will be show if only one is missing
// See https://github.com/marmelab/react-admin/issues/5190
if( returnFailedResources ) {
if (returnFailedResources) {
// Return only the ID of the resource
returnData.push({ id });
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/packages/auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports = {
resource['semapps:fileName'] = filename;

try {
fileStream.pipe(fs.createWriteStream(resource['semapps:localPath']));
await this.streamToFile(fileStream, resource['semapps:localPath']);
} catch (e) {
throw new MoleculerError(e, 500, 'Server Error');
}
Expand Down
12 changes: 12 additions & 0 deletions src/middleware/packages/ldp/services/resource/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ const rdfParser = require('rdf-parse').default;
const streamifyString = require('streamify-string');
const { variable } = require('rdf-data-model');
const { MIME_TYPES } = require('@semapps/mime-types');
const fs = require('fs');

const { defaultToArray } = require('../../utils');

// TODO put each method in a different file (problems with "this" not working)
module.exports = {
async streamToFile(inputStream, filePath) {
return new Promise((resolve, reject) => {
const fileWriteStream = fs.createWriteStream(filePath);
inputStream
.pipe(fileWriteStream)
.on('finish', resolve)
.on('error', reject);
});
},

async bodyToTriples(body, contentType) {
return new Promise((resolve, reject) => {
if (contentType === 'application/ld+json' && typeof body === 'object') body = JSON.stringify(body);
Expand Down
4 changes: 3 additions & 1 deletion src/middleware/packages/ldp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const buildFiltersQuery = filters => {
Object.keys(filters).forEach((predicate, i) => {
if (filters[predicate]) {
where += `
FILTER EXISTS { ?s1 ${predicate.startsWith('http') ? `<${predicate}>` : predicate} ${filters[predicate].startsWith('http') ? `<${filters[predicate]}>` : `"${filters[predicate]}"`} } .
FILTER EXISTS { ?s1 ${predicate.startsWith('http') ? `<${predicate}>` : predicate} ${
filters[predicate].startsWith('http') ? `<${filters[predicate]}>` : `"${filters[predicate]}"`
} } .
`;
} else {
where += `
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/packages/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const parseJson = async (req, res, next) => {
};

const parseFile = (req, res, next) => {
if (!req.$ctx.meta.parser) {
if (!req.$ctx.meta.parser && (req.method == 'POST' || req.method == 'PUT')) {
if (req.headers['content-type'] && req.headers['content-type'].includes('multipart/form-data')) {
const busboy = new Busboy({ headers: req.headers });
let files = [];
Expand Down

1 comment on commit 40f11d5

@vercel
Copy link

@vercel vercel bot commented on 40f11d5 Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

archipel – ./src/frontend

archipel.assemblee-virtuelle.org
archipel-semapps.vercel.app
archipel-git-master-semapps.vercel.app

Please sign in to comment.