Skip to content

Commit

Permalink
Merge branch 'main' into fix/impersonate-url
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina authored Nov 20, 2023
2 parents 4e3c331 + d343e74 commit d02f5ac
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { useTable, useBlockLayout } from 'react-table';
import { FixedSizeList, areEqual } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import { useFileListing, useSystems } from 'hooks/datafiles';
import { LoadingSpinner, SectionMessage } from '_common';
import './DataFilesTable.scss';
Expand All @@ -19,6 +19,9 @@ import * as ROUTES from '../../../constants/routes';
// What to render if there are no files to display
const DataFilesTablePlaceholder = ({ section, data }) => {
const { params, error: err, loading } = useFileListing(section);

const isPublicSystem = params?.scheme === 'public';

const { api: currentListing, scheme } = params ?? {};

const dispatch = useDispatch();
Expand Down Expand Up @@ -170,6 +173,14 @@ const DataFilesTablePlaceholder = ({ section, data }) => {
);
}
if (err === '403') {
if (isPublicSystem)
return (
<div className="h-100 listing-placeholder">
<SectionMessage type="warning">
You must be logged in to view this data.
</SectionMessage>
</div>
);
return (
<div className="h-100 listing-placeholder">
<SectionMessage type="warning">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ describe('DataFilesTable', () => {
</BrowserRouter>
</Provider>
);
expect(
getByText(/You are missing the required allocation for this system./)
).toBeDefined();
expect(getByText(/You must be logged in to view this data./)).toBeDefined();
});

it('should display an error for 400 when the api is Google Drive', async () => {
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/PublicData/PublicData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useSelectedFiles } from 'hooks/datafiles';
import DataFilesBreadcrumbs from '../DataFiles/DataFilesBreadcrumbs/DataFilesBreadcrumbs';
import DataFilesListing from '../DataFiles/DataFilesListing/DataFilesListing';
import DataFilesPreviewModal from '../DataFiles/DataFilesModals/DataFilesPreviewModal';
import DataFilesShowPathModal from '../DataFiles/DataFilesModals/DataFilesShowPathModal';
import { ToolbarButton } from '../DataFiles/DataFilesToolbar/DataFilesToolbar';

import styles from './PublicData.module.css';
Expand Down Expand Up @@ -46,7 +47,9 @@ const PublicData = () => {
useEffect(() => {
const pathLength = location.pathname.split('/').length;
if (publicDataSystem.system && pathLength < 6) {
history.push(`/public-data/tapis/public/${publicDataSystem.system}/`);
history.push(
`/public-data/tapis/public/${publicDataSystem.system}${publicDataSystem.homeDir}`
);
}
}, [publicDataSystem.system]);

Expand All @@ -67,6 +70,7 @@ const PublicData = () => {
</Route>
</Switch>
<DataFilesPreviewModal />
<DataFilesShowPathModal />
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions client/src/components/PublicData/PublicData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const systems = {
{
name: 'Public Data',
system: 'cep.storage.public',
homeDir: '/',
scheme: 'public',
api: 'tapis',
icon: null,
Expand Down
16 changes: 12 additions & 4 deletions server/portal/apps/datafiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ def get(self, request):
return JsonResponse(response)


@method_decorator(login_required, name='dispatch')
class SystemDefinitionView(BaseApiView):
"""Get definitions for individual systems"""

def get(self, request, systemId):
system_def = request.user.tapis_oauth.client.systems.getSystem(systemId=systemId)
try:
client = request.user.tapis_oauth.client
except AttributeError:
# Make sure that we only let unauth'd users see public systems
public_sys = next((sys for sys in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS if sys['scheme'] == 'public'), None)
if public_sys and public_sys['system'] == systemId:
client = service_account()
else:
return JsonResponse({'message': 'Unauthorized'}, status=401)
system_def = client.systems.getSystem(systemId=systemId)
return JsonResponse(
{
"status": 200,
Expand All @@ -81,8 +89,8 @@ def get(self, request, operation=None, scheme=None, system=None, path='/'):
client = request.user.tapis_oauth.client
except AttributeError:
# Make sure that we only let unauth'd users see public systems
if next((sys for sys in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
if sys['system'] == system and sys['scheme'] == 'public'), None):
public_sys = next((sys for sys in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS if sys['scheme'] == 'public'), None)
if public_sys and public_sys['system'] == system and path.startswith(public_sys['homeDir'].strip('/')):
client = service_account()
else:
return JsonResponse(
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/datafiles/views_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_get_system_forbidden(client, regular_user, mock_tapis_client, agave_sto
mock_tapis_client.systems.get.return_value = agave_storage_system_mock

response = client.get("/api/datafiles/systems/definition/MySystem/")
assert response.status_code == 302 # redirect to login
assert response.status_code == 401


@pytest.fixture
Expand Down

0 comments on commit d02f5ac

Please sign in to comment.