Skip to content

Commit d76b2c4

Browse files
tcnichollongshuicy
andauthored
485 public datasets visible when not logged in (#832)
* adding new file * modal allows selecting public * changing front end to allow changing to PUBLIC * changing to public now works * adding new routes for public datasets * routers for public files and datasets added download is available, though button will not work on page when added * running codegen for new files * running codegen for new files * does not work right now * small fixes, a few typos * working now * new direction if public * adding PublicDataset will probably need to refactor content from Dataset so that they can both import the same things, with 'publicView' as boolean that will determine what is shown * fixing indents * adding public folders * error on folders and details * folders do not show details not working * moving layout to new component this should make having a public dataset easier * public dataset view uses DatasetLayout now * console logs, should remove later * cannot read properties of undefined? * cannot read properties of undefined? * fix package lock * error gone but with hardcoded limit,not sure why * works now with limit * this seemed to get rid of the error * public view works, shows only public datasets changes coming to PublicDataset need some refactoring of Dataset component * fixing import, working on publicDataset component now * files table has option for public now, will use different route * publicactions menu added removing tabs we don't use for public datasets * new tab panel components * removing unused components * adding public file * adding actions and states for public folders gradually switching public views to use different states than private ones * fixing package lock * fixing wrong method called for public dataset details we see file, some features removed that a public file should not have * public file - no editing or modifying user metadata * index now has authenticated and public using booleans instead of statuses here for now, might change later * adding public and authenticated to index these will be used for searching later * adding new routes for public search from public pages, the search will only return stuff that is public * adding tests * sort of works * using a status field rather than 2 booleans since both cannot be true * tests pass for public datasets, need tests for authenticated added * adding public and authenticated to the user clause * public no longer private router, but problems with layout * errors on files, using new publicLayout for later * public file actions not tested yet, * dataset works, need to fix file * public file added tabs removed for public dataset * public file page shows up, has error * something breaks on page, might be related to visualizations * errors seem to be on visualization dab * routes had dependency that was not needed * public file menu boolean, not all options should appear adding public visualizations, we need that and metadata eventually * adding public visualizations * public visualization view * adding to reducers index, fixing names * will need to use another file actions menu * removing some unused imports adding public metadata * deleting the metadata public routers just adding method to the public files and datasets * public metadata * adding metadata * fixing public dataset details * no more error on public file * user metadata tab should work now checks if public view, uses other route if public * adding method to public_datasets.js for metadata listener metadata tab * public layout removes links we do not use in this view * change explore to public * some fake data will be public change to DatasetIn * fix public metadata extraction tab for file missing import * using public layout in public dataset * download public file version * route to download public dataset * HACK ADDED - probably not a good idea if the user is public, an email is returned for [email protected] * register or login for public page * adding authenticated status * return public datasets * have some authenticated datasets as well * fixing auth for public datasets * checking for public dataset files * changing auth for public or authenticated things * adding filestatus for easier checks * changing status of files? * adding has public access method * new method * adding public as well as authenticated * can now view files if they are public but it looks like the viewer can do things they should not be able to * check public access method added, fixed to work for files * viewer cannot run extraction on file * formatting * running codegen * formatting * fixing package lock, ws wrong * formatting * remove extraction history tab on public view fixing update of status on dataset patch * fix file summary on public file * reverting change * fixing file status change, looks like that broke removing unnecessary file status field just using downloadResource * return public access * fixing public visualization * fixed the broken visualization on public files * formatting * does not work * think this fixed it * putting downloadPublicResource back in, errors not fixed * putting downloadPublicResource back in, errors not fixed * adding publicView option to the various visualizations. this means the right URL will be used if we are seeing this in public view. otherwise the raw bytes do not download * fix package lock * removing console logs * removing console logs * removing console logs * catch case if authorization is None and no public access for file * role was not working for dataset, fixed there but still not showing on tab * does not break on front end, still needs clean up * back end fixes after merge, some authorizations were not checked correctly. files did not switch to public or authenticated properly * fix file tab extractor * file metadata from listeners now displays for public files * button back for add metadata dataset * ran codegen * public metadata definitions * metadata should work now for public when not signed in * fixed text visualization, endpoint for public_files had a typo * fixing more typoes * formatting * codegen * removing search for now * increment should be false for getting public files * adding public check to dataset files * check public or authenticated in dataset routes * don't use public route * removing console logs * fake data should populate both PUBLIC and AUTHENTICATED datasets * fixing download * fixing type on public/files dataset download fixed download file and file version fixed public elasticsearch added to router * removing unused methods * remove divider * codegen * put divider back in public dataset card allows dataset download when public * removed divider * can download public file from file menu now * remove unused method black formatting * black formatting * black formatting --------- Co-authored-by: Chen Wang <[email protected]>
1 parent cf3877e commit d76b2c4

File tree

76 files changed

+5744
-263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+5744
-263
lines changed

backend/app/deps/authorization_deps.py

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,41 @@
55
from app.keycloak_auth import get_current_username
66
from app.models.authorization import RoleType, AuthorizationDB
77
from app.models.datasets import DatasetDB, DatasetStatus
8-
from app.models.files import FileDB
9-
from app.models.groups import GroupDB
8+
from app.models.files import FileOut, FileDB, FileStatus
9+
from app.models.groups import GroupOut, GroupDB
1010
from app.models.metadata import MetadataDB
1111
from app.models.pyobjectid import PyObjectId
1212
from app.routers.authentication import get_admin
1313
from app.routers.authentication import get_admin_mode
1414

1515

16+
async def check_public_access(
17+
resource_id: str,
18+
resource_type: str,
19+
role: RoleType,
20+
current_user=Depends(get_current_username),
21+
) -> bool:
22+
has_public_access = False
23+
if role == RoleType.VIEWER:
24+
if resource_type == "dataset":
25+
if (
26+
dataset := await DatasetDB.get(PydanticObjectId(resource_id))
27+
) is not None:
28+
if (
29+
dataset.status == DatasetStatus.PUBLIC.name
30+
or dataset.status == DatasetStatus.AUTHENTICATED.name
31+
):
32+
has_public_access = True
33+
elif resource_type == "file":
34+
if (file := await FileDB.get(PydanticObjectId(resource_id))) is not None:
35+
if (
36+
file.status == FileStatus.PUBLIC.name
37+
or file.status == FileStatus.AUTHENTICATED.name
38+
):
39+
has_public_access = True
40+
return has_public_access
41+
42+
1643
async def get_role(
1744
dataset_id: str,
1845
current_user=Depends(get_current_username),
@@ -31,6 +58,11 @@ async def get_role(
3158
AuthorizationDB.user_ids == current_user,
3259
),
3360
)
61+
public_access = await check_public_access(
62+
dataset_id, "dataset", RoleType.VIEWER, current_user
63+
)
64+
if authorization is None and public_access:
65+
return RoleType.VIEWER
3466
return authorization.role
3567

3668

@@ -55,15 +87,11 @@ async def get_role_by_file(
5587
if (
5688
dataset := await DatasetDB.get(PydanticObjectId(file.dataset_id))
5789
) is not None:
58-
if dataset.status == DatasetStatus.AUTHENTICATED.name:
59-
auth_dict = {
60-
"creator": dataset.author.email,
61-
"dataset_id": file.dataset_id,
62-
"user_ids": [current_user],
63-
"role": RoleType.VIEWER,
64-
}
65-
authenticated_auth = AuthorizationDB(**auth_dict)
66-
return authenticated_auth
90+
if (
91+
dataset.status == DatasetStatus.AUTHENTICATED.name
92+
or dataset.status == DatasetStatus.PUBLIC.name
93+
):
94+
return RoleType.VIEWER
6795
else:
6896
raise HTTPException(
6997
status_code=403,
@@ -199,6 +227,7 @@ async def __call__(
199227
) is not None:
200228
if (
201229
current_dataset.status == DatasetStatus.AUTHENTICATED.name
230+
or current_dataset.status == DatasetStatus.PUBLIC.name
202231
and self.role == "viewer"
203232
):
204233
return True
@@ -249,7 +278,15 @@ async def __call__(
249278
detail=f"User `{current_user} does not have `{self.role}` permission on file {file_id}",
250279
)
251280
else:
252-
raise HTTPException(status_code=404, detail=f"File {file_id} not found")
281+
if (
282+
file.status == FileStatus.PUBLIC.name
283+
or file.status == FileStatus.AUTHENTICATED.name
284+
) and self.role == RoleType.VIEWER:
285+
return True
286+
else:
287+
raise HTTPException(
288+
status_code=404, detail=f"File {file_id} not found"
289+
)
253290

254291

255292
class MetadataAuthorization:

backend/app/main.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,27 @@
3030
from app.models.users import UserDB, UserAPIKeyDB, ListenerAPIKeyDB
3131
from app.models.visualization_config import VisualizationConfigDB
3232
from app.models.visualization_data import VisualizationDataDB
33-
from app.routers import folders, groups, status
33+
from app.routers import folders, groups, public_folders, status
3434
from app.routers import (
3535
users,
3636
authorization,
3737
metadata,
38+
public_metadata,
3839
files,
40+
public_files,
3941
metadata_files,
4042
datasets,
43+
public_datasets,
4144
metadata_datasets,
4245
authentication,
4346
keycloak,
4447
elasticsearch,
48+
public_elasticsearch,
4549
listeners,
4650
feeds,
4751
jobs,
4852
visualization,
53+
public_visualization,
4954
thumbnails,
5055
)
5156

@@ -113,12 +118,22 @@
113118
tags=["metadata"],
114119
dependencies=[Depends(get_current_username)],
115120
)
121+
api_router.include_router(
122+
public_metadata.router,
123+
prefix="/public_metadata",
124+
tags=["public_metadata"],
125+
)
116126
api_router.include_router(
117127
files.router,
118128
prefix="/files",
119129
tags=["files"],
120130
dependencies=[Depends(get_current_username)],
121131
)
132+
api_router.include_router(
133+
public_files.router,
134+
prefix="/public_files",
135+
tags=["public_files"],
136+
)
122137
api_router.include_router(
123138
metadata_files.router,
124139
prefix="/files",
@@ -132,14 +147,27 @@
132147
dependencies=[Depends(get_current_username)],
133148
)
134149
api_router.include_router(
135-
metadata_datasets.router, prefix="/datasets", tags=["metadata"]
150+
public_datasets.router,
151+
prefix="/public_datasets",
152+
tags=["public_datasets"],
153+
)
154+
api_router.include_router(
155+
metadata_datasets.router,
156+
prefix="/datasets",
157+
tags=["metadata"],
158+
dependencies=[Depends(get_current_username)],
136159
)
137160
api_router.include_router(
138161
folders.router,
139162
prefix="/folders",
140163
tags=["folders"],
141164
dependencies=[Depends(get_current_username)],
142165
)
166+
api_router.include_router(
167+
public_folders.router,
168+
prefix="/public_folders",
169+
tags=["public_folders"],
170+
)
143171
api_router.include_router(
144172
listeners.router,
145173
prefix="/listeners",
@@ -164,6 +192,11 @@
164192
tags=["elasticsearch"],
165193
dependencies=[Depends(get_current_username)],
166194
)
195+
api_router.include_router(
196+
public_elasticsearch.router,
197+
prefix="/public_elasticsearch",
198+
tags=["public_elasticsearch"],
199+
)
167200
api_router.include_router(
168201
feeds.router,
169202
prefix="/feeds",
@@ -182,6 +215,11 @@
182215
tags=["visualizations"],
183216
dependencies=[Depends(get_current_username)],
184217
)
218+
api_router.include_router(
219+
public_visualization.router,
220+
prefix="/public_visualizations",
221+
tags=["public_visualizations"],
222+
)
185223
api_router.include_router(
186224
thumbnails.router,
187225
prefix="/thumbnails",

backend/app/models/datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class DatasetStatus(AutoName):
2727
class DatasetBase(BaseModel):
2828
name: str = "N/A"
2929
description: Optional[str] = None
30+
status: str = DatasetStatus.PRIVATE.name
3031

3132

3233
class DatasetIn(DatasetBase):
@@ -65,7 +66,7 @@ class DatasetDBViewList(View, DatasetBase):
6566
modified: datetime = Field(default_factory=datetime.utcnow)
6667
auth: List[AuthorizationDB]
6768
thumbnail_id: Optional[PydanticObjectId] = None
68-
status: Optional[str]
69+
status: str = DatasetStatus.PRIVATE.name
6970

7071
class Settings:
7172
source = DatasetDB

backend/app/models/files.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from enum import Enum
33
from typing import Optional, List
4-
4+
from enum import Enum, auto
55
from beanie import Document, View, PydanticObjectId
66
from pydantic import Field, BaseModel
77

@@ -10,6 +10,19 @@
1010
from app.models.users import UserOut
1111

1212

13+
class AutoName(Enum):
14+
def _generate_next_value_(name, start, count, last_values):
15+
return name
16+
17+
18+
class FileStatus(AutoName):
19+
PRIVATE = auto()
20+
PUBLIC = auto()
21+
AUTHENTICATED = auto()
22+
DEFAULT = auto()
23+
TRIAL = auto()
24+
25+
1326
class StorageType(str, Enum):
1427
"""Depending on the StorageType,the file may need different properties such as local path or URL.
1528
Also, some StorageTypes do not support versioning or anonymous sharing."""
@@ -47,6 +60,7 @@ class Settings:
4760

4861
class FileBase(BaseModel):
4962
name: str = "N/A"
63+
status: str = FileStatus.PRIVATE.name
5064

5165

5266
class FileIn(FileBase):

backend/app/models/search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ class ElasticsearchEntry(BaseModel):
4646
bytes: Optional[int]
4747
# metadata fields
4848
metadata: Optional[List[dict]] = []
49+
status: Optional[str]

backend/app/routers/authorization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
from beanie import PydanticObjectId
24
from beanie.operators import Or, In
35
from bson import ObjectId
@@ -92,7 +94,10 @@ async def get_dataset_role(
9294
if (
9395
current_dataset := await DatasetDB.get(PydanticObjectId(dataset_id))
9496
) is not None:
95-
if current_dataset.status == DatasetStatus.AUTHENTICATED.name:
97+
if (
98+
current_dataset.status == DatasetStatus.AUTHENTICATED.name
99+
or current_dataset.status == DatasetStatus.PUBLIC.name
100+
):
96101
public_authorization_in = {
97102
"dataset_id": PydanticObjectId(dataset_id),
98103
"role": RoleType.VIEWER,

0 commit comments

Comments
 (0)