Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions backend/apps/ifc_validation_bff/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from django.urls import path

from .views_legacy import me, models_paginated, download, upload, delete, revalidate
from .views_legacy import me, models_paginated, upload, delete
from .views_legacy import report, report_error

urlpatterns = [

# 'Flask'-way of doing things; backend for legacy API (< 0.6)
path('api/me', me),
path('api/models_paginated/<int:start>/<int:end>', models_paginated),
path('api/download/<str:id>', download),
path('api/', upload),
path('api/delete/<str:ids>', delete),
path('api/revalidate/<str:ids>', revalidate),
path('api/report/<str:id>', report),
path('api/report_error', report_error),

Expand Down
33 changes: 0 additions & 33 deletions backend/apps/ifc_validation_bff/views_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,39 +272,6 @@ def models_paginated(request, start: int, end: int):
return JsonResponse(response_data)


@ensure_csrf_cookie
def download(request, id: int):

if request.method != "GET":
return HttpResponseNotAllowed()

# fetch current user
user = get_current_user(request)
if not user:
return create_redirect_response(login=True)

logger.debug(f"Locating file for pub='{id}' pk='{ValidationRequest.to_private_id(id)}'")
request = ValidationRequest.objects.filter(created_by__id=user.id, deleted=False, id=ValidationRequest.to_private_id(id)).first()
if request:
file_path = os.path.join(os.path.abspath(MEDIA_ROOT), request.file.name)
logger.debug(f"File to be downloaded is located at '{file_path}'")

if request.file.name.endswith('.gz'):
file_handle = open(file_path, 'rb')
response = FileResponse(file_handle, content_type="application/gzip")
response['Content-Length'] = os.path.getsize(file_path)
logger.debug(f"Sending file with id='{id}' back as '{request.file_name}'")
else:
response = HttpResponse(open(file_path), content_type="application/x-step")
response['Content-Disposition'] = f'attachment; filename="{request.file_name}"'
logger.debug(f"Sending file with id='{id}' back as '{request.file_name}'")

return response
else:
logger.debug(f"Could not download file with id='{id}' for user.id='{user.id}' as it does not exist")
return HttpResponseNotFound()


@ensure_csrf_cookie
@csrf_protect
def upload(request):
Expand Down
64 changes: 32 additions & 32 deletions frontend/src/DashboardTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import InfoIcon from '@mui/icons-material/Info';
import MailLockIcon from '@mui/icons-material/MailLock';
import Tooltip from '@mui/material/Tooltip';
import DeleteIcon from '@mui/icons-material/Delete';
//import ReplayIcon from '@mui/icons-material/Replay';
import CircularStatic from "./CircularStatic";
import ErrorIcon from '@mui/icons-material/Error';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
Expand All @@ -26,6 +25,8 @@ import WarningIcon from '@mui/icons-material/Warning';
import HourglassBottomIcon from '@mui/icons-material/HourglassBottom';
import BlockIcon from '@mui/icons-material/Block';
import Link from '@mui/material/Link';
import Button from '@mui/material/Button';

import { FETCH_PATH } from './environment'
import { useEffect, useState, useContext } from 'react';
import { PageContext } from './Page';
Expand Down Expand Up @@ -210,13 +211,6 @@ function EnhancedTableToolbar({ numSelected, onDelete, onRevalidate }) {
</IconButton>
</Tooltip>)}

{/* {numSelected > 0 && (
<Tooltip title="Revalidate">
<IconButton onClick={onRevalidate}>
<ReplayIcon />
</IconButton>
</Tooltip>)} */}

{numSelected > 0 ? (
<Typography
//sx={{ flex: '1 1 100%' }}
Expand Down Expand Up @@ -253,7 +247,6 @@ export default function DashboardTable({ models }) {
const [rowsPerPage, setRowsPerPage] = React.useState(5);
const [count, setCount] = React.useState(0);
const [deleted, setDeleted] = useState('');
const [revalidated, setRevalidated] = useState('');
const [progress, setProgress] = useState(0);

const context = useContext(PageContext);
Expand Down Expand Up @@ -323,7 +316,9 @@ export default function DashboardTable({ models }) {
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0;

useEffect(() => {
if (deleted) {

if (deleted && deleted.length > 0) {

fetch(`${FETCH_PATH}/api/delete/${deleted}`, {
method: 'DELETE',
headers: { 'x-csrf-token': getCookieValue('csrftoken') },
Expand All @@ -334,33 +329,19 @@ export default function DashboardTable({ models }) {
setSelected([])
setDeleted([])
});
} else if (revalidated) {
fetch(`${FETCH_PATH}/api/revalidate/${revalidated}`, {
method: 'POST',
headers: { 'x-csrf-token': getCookieValue('csrftoken') },
credential: 'include'
})
.then((response) => response.json())
.then((json) => {
setSelected([])
setRevalidated([])
});
}

}, [deleted, revalidated]);
}, [deleted]);

function onDelete() {
setDeleted(selected.join(','))
if (window.confirm(`Delete ${selected.length} selected IFC file(s)? This action cannot be undone.`)) {
setDeleted(selected.join(','))
}
}

// function onRevalidate() {
// setRevalidated(selected.join(','))
// }

return (
<Box sx={{ width: '100%', alignSelf: 'start' }}>

{/* <EnhancedTableToolbar numSelected={selected.length} onDelete={onDelete} onRevalidate={onRevalidate} /> */}
<EnhancedTableToolbar numSelected={selected.length} onDelete={onDelete} />
<TableContainer>
<Table
Expand Down Expand Up @@ -459,10 +440,29 @@ export default function DashboardTable({ models }) {

<TableCell align="left">
{
(row.status_magic_clamav != 'i') ?
<Link href={`${FETCH_PATH}/api/download/${row.id}`} underline="hover" onClick={evt => evt.stopPropagation()}>
{'Download file'}
</Link> : 'File unavailable'
(row.deleted ? '-' : <div>
<Button
variant="text"
disabled={!isRowAllowedToBeDeleted(row)}
sx={{
textTransform: 'none',
color: 'primary.main',
'&:hover': { textDecoration: 'underline', backgroundColor: 'transparent', },
}}
onClick={ (evt) => {
evt.stopPropagation();
if (window.confirm('Are you sure you want to delete this IFC file? This action cannot be undone.'))
setDeleted(row.id);
}}>{'Delete IFC file'
}</Button>

<Tooltip title={!isRowAllowedToBeDeleted(row) ? "Unable to delete your IFC file as it is still being processed." : "Delete your IFC file immediately from the Validation Service. In any case, your file will be deleted after 2 weeks - as per our file retention policy."}>
<span style={{display: 'inline-block'}}>
<span style={{fontSize: '.83em', verticalAlign: 'super'}}>ⓘ</span>
</span>
</Tooltip>
</div>
)
}
</TableCell>
</TableRow>
Expand Down