Skip to content

Commit

Permalink
Merge pull request #3463 from hotosm/develop
Browse files Browse the repository at this point in the history
v4.1.5 Release
  • Loading branch information
willemarcel authored Aug 12, 2020
2 parents 3aa971d + dcee61f commit 872dace
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 184 deletions.
61 changes: 27 additions & 34 deletions backend/api/system/image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from flask_restful import Resource, request, current_app

from backend.services.organisation_service import OrganisationService
from backend.services.users.authentication_service import token_auth


Expand Down Expand Up @@ -56,42 +55,36 @@ def post(self):
return {"Error": "Image upload service not defined"}, 500

try:
is_org_manager = (
len(
OrganisationService.get_organisations_managed_by_user(
token_auth.current_user()
)
)
> 0
)
data = request.get_json()
if is_org_manager:
if data.get("filename") is None:
return {"Error": "Missing filename parameter"}, 400
if data.get("mime") in ["image/png", "image/jpeg", "image/webp"]:
headers = {
"x-api-key": current_app.config["IMAGE_UPLOAD_API_KEY"],
"Content-Type": "application/json",
}
url = "{}?filename={}".format(
current_app.config["IMAGE_UPLOAD_API_URL"], data.get("filename")
)
result = requests.post(
url, headers=headers, data=json.dumps({"image": data})
)
if result.ok:
return result.json(), 201
else:
return result.json(), 400
if data.get("filename") is None:
return {"Error": "Missing filename parameter"}, 400
if data.get("mime") in [
"image/png",
"image/jpeg",
"image/webp",
"image/gif",
]:
headers = {
"x-api-key": current_app.config["IMAGE_UPLOAD_API_KEY"],
"Content-Type": "application/json",
}
url = "{}?filename={}".format(
current_app.config["IMAGE_UPLOAD_API_URL"], data.get("filename")
)
result = requests.post(
url, headers=headers, data=json.dumps({"image": data})
)
if result.ok:
return result.json(), 201
else:
return (
{
"Error": "Mimetype is not allowed. Use are 'image/png', 'image/jpeg', 'image/webp'"
},
400,
)
return result.json(), 400
else:
return {"Error": "User is not admin or organisation manager"}, 403
return (
{
"Error": "Mimetype is not allowed. The supported formats are: png, jpeg, webp and gif."
},
400,
)
except Exception as e:
error_msg = f"Image upload POST API - unhandled error: {str(e)}"
current_app.logger.critical(error_msg)
Expand Down
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"react-meta-elements": "^1.0.0",
"react-placeholder": "^4.0.3",
"react-redux": "^7.2.1",
"react-scripts": "^3.4.1",
"react-scripts": "^3.4.2",
"react-select": "^3.1.0",
"react-tooltip": "^4.2.8",
"reactjs-popup": "^1.5.0",
Expand Down Expand Up @@ -90,12 +90,12 @@
]
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.2",
"@testing-library/jest-dom": "^5.11.3",
"@testing-library/react": "^10.4.8",
"@testing-library/react-hooks": "^3.4.1",
"combine-react-intl-messages": "^4.0.0",
"jest-canvas-mock": "^2.2.0",
"msw": "^0.20.4",
"msw": "^0.20.5",
"prettier": "^2.0.5",
"react-test-renderer": "^16.13.1"
},
Expand Down
Loading

0 comments on commit 872dace

Please sign in to comment.