Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

485 public datasets visible when not logged in #832

Merged
merged 151 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
a72f9a1
adding new file
tcnichol Nov 6, 2023
5beae5c
modal allows selecting public
tcnichol Nov 6, 2023
ac34ea5
changing front end to allow changing to PUBLIC
tcnichol Nov 6, 2023
a828fbd
changing to public now works
tcnichol Nov 6, 2023
9467a8f
adding new routes for public datasets
tcnichol Nov 6, 2023
a6d6d5a
routers for public files and datasets added
tcnichol Nov 8, 2023
216188c
running codegen for new files
tcnichol Nov 9, 2023
04f3caf
running codegen for new files
tcnichol Nov 9, 2023
261b9ed
does not work right now
tcnichol Nov 9, 2023
93dabd6
small fixes, a few typos
tcnichol Nov 9, 2023
f5071c7
working now
longshuicy Nov 9, 2023
156d2d4
new direction if public
tcnichol Nov 9, 2023
fa08039
adding PublicDataset
tcnichol Nov 9, 2023
071880e
fixing indents
tcnichol Nov 9, 2023
2290fb5
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Nov 14, 2023
fe099c4
adding public folders
tcnichol Nov 14, 2023
69141bf
error on folders and details
tcnichol Nov 14, 2023
76a1dda
folders do not show
tcnichol Nov 14, 2023
58c49fe
moving layout to new component
tcnichol Nov 14, 2023
ea53a1d
public dataset view uses DatasetLayout now
tcnichol Nov 14, 2023
6e97705
console logs, should remove later
tcnichol Nov 14, 2023
618a5bf
cannot read properties of undefined?
tcnichol Nov 15, 2023
897a8bc
cannot read properties of undefined?
tcnichol Nov 15, 2023
1cc3de0
fix package lock
tcnichol Nov 15, 2023
ca8d40a
error gone but with hardcoded limit,not sure why
tcnichol Nov 15, 2023
423f8d9
works now with limit
tcnichol Nov 15, 2023
273812f
this seemed to get rid of the error
tcnichol Nov 15, 2023
bd8fe51
public view works, shows only public datasets
tcnichol Nov 16, 2023
801dca0
fixing import, working on publicDataset component now
tcnichol Nov 16, 2023
fcd07f1
files table has option for public now, will use different route
tcnichol Nov 16, 2023
b4b6a52
publicactions menu added
tcnichol Nov 16, 2023
df0b199
new tab panel components
tcnichol Nov 16, 2023
889564f
removing unused components
tcnichol Nov 16, 2023
18092e7
adding public file
tcnichol Nov 16, 2023
deffbc2
adding actions and states for public folders
tcnichol Nov 19, 2023
b0473b4
fixing package lock
tcnichol Nov 22, 2023
045d210
fixing wrong method called for public dataset details
tcnichol Nov 22, 2023
598b7af
public file - no editing or modifying user metadata
tcnichol Nov 22, 2023
f7ff2ab
index now has authenticated and public
tcnichol Nov 22, 2023
1a7cc53
adding public and authenticated to index
tcnichol Nov 25, 2023
b25d12e
adding new routes for public search
tcnichol Nov 25, 2023
d2db682
adding tests
tcnichol Nov 25, 2023
e2c4d44
sort of works
tcnichol Nov 25, 2023
687883d
using a status field rather than 2 booleans since both cannot be true
tcnichol Nov 26, 2023
85a75fc
tests pass for public datasets,
tcnichol Nov 26, 2023
28f4a99
adding public and authenticated to the user clause
tcnichol Nov 26, 2023
ab7c6d8
public no longer private router, but problems with layout
tcnichol Nov 27, 2023
3fb1ffd
errors on files, using new publicLayout for later
tcnichol Nov 27, 2023
5a097ea
public file actions
tcnichol Nov 27, 2023
8b3ba92
dataset works, need to fix file
tcnichol Nov 28, 2023
549851d
public file added
tcnichol Nov 28, 2023
f80be25
public file page shows up, has error
tcnichol Nov 28, 2023
e5da345
something breaks on page, might be related to visualizations
tcnichol Nov 28, 2023
abdb225
errors seem to be on visualization dab
tcnichol Nov 28, 2023
88e9923
routes had dependency that was not needed
tcnichol Nov 28, 2023
4342564
public file menu boolean, not all options should appear
tcnichol Nov 29, 2023
282ae31
adding public visualizations
tcnichol Nov 29, 2023
7080e15
public visualization view
tcnichol Nov 29, 2023
fa689e7
adding to reducers index, fixing names
tcnichol Nov 29, 2023
54858b2
will need to use another file actions menu
tcnichol Nov 29, 2023
f8963c6
removing some unused imports
tcnichol Nov 29, 2023
f11a578
deleting the metadata public routers
tcnichol Nov 29, 2023
87f086e
public metadata
tcnichol Nov 29, 2023
4f5c62e
adding metadata
tcnichol Nov 30, 2023
30aed55
fixing public dataset details
tcnichol Nov 30, 2023
492f3a2
no more error on public file
tcnichol Nov 30, 2023
a1df3e8
user metadata tab should work now
tcnichol Dec 1, 2023
23fe460
adding method to public_datasets.js for metadata
tcnichol Dec 1, 2023
0ee9ffb
public layout removes links we do not use in this view
tcnichol Dec 3, 2023
180d490
change explore to public
tcnichol Dec 3, 2023
06ff550
some fake data will be public
tcnichol Dec 4, 2023
4ae77f7
fix public metadata extraction tab for file
tcnichol Dec 4, 2023
28465d7
using public layout in public dataset
tcnichol Dec 4, 2023
f4a802f
download public file version
tcnichol Dec 4, 2023
0afb0c8
route to download public dataset
tcnichol Dec 4, 2023
9ad113b
HACK ADDED - probably not a good idea
tcnichol Dec 4, 2023
6fbbb73
register or login for public page
tcnichol Dec 4, 2023
4aa308d
adding authenticated status
tcnichol Dec 5, 2023
77b66c7
return public datasets
tcnichol Dec 5, 2023
6696663
have some authenticated datasets as well
tcnichol Dec 5, 2023
20ae2f7
fixing auth for public datasets
tcnichol Dec 5, 2023
b708bc9
checking for public dataset files
tcnichol Dec 5, 2023
6bbaf3f
changing auth for public or authenticated things
tcnichol Dec 5, 2023
402373f
adding filestatus for easier checks
tcnichol Dec 5, 2023
9187203
changing status of files?
tcnichol Dec 5, 2023
3bfb268
adding has public access method
tcnichol Dec 6, 2023
9c3ae63
new method
tcnichol Dec 6, 2023
f219557
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Dec 6, 2023
3690a40
adding public as well as authenticated
tcnichol Dec 6, 2023
9ee304f
can now view files if they are public
tcnichol Dec 6, 2023
3dc9e01
check public access method added, fixed to work for files
tcnichol Dec 6, 2023
f046eb4
viewer cannot run extraction on file
tcnichol Dec 6, 2023
06208dc
formatting
tcnichol Dec 7, 2023
3757010
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Dec 10, 2023
8b38803
running codegen
tcnichol Dec 11, 2023
6b11231
Merge remote-tracking branch 'origin/485-public-datasets-visible-when…
tcnichol Dec 11, 2023
997ab94
formatting
tcnichol Dec 11, 2023
91e8006
fixing package lock, ws wrong
tcnichol Dec 11, 2023
f0938ee
formatting
tcnichol Dec 11, 2023
a6d88e0
remove extraction history tab on public view
tcnichol Dec 17, 2023
0b981bf
fix file summary on public file
tcnichol Dec 17, 2023
cff19e5
reverting change
tcnichol Dec 20, 2023
ea05335
fixing file status change, looks like that broke
tcnichol Dec 20, 2023
f928f59
return public access
tcnichol Dec 20, 2023
2d1d685
fixing public visualization
tcnichol Dec 20, 2023
ebb055a
fixed the broken visualization on public files
tcnichol Dec 20, 2023
17c9223
formatting
tcnichol Dec 20, 2023
f9a7c47
does not work
tcnichol Dec 20, 2023
0eb7cce
think this fixed it
tcnichol Dec 20, 2023
b429e90
putting downloadPublicResource back in, errors not fixed
tcnichol Dec 20, 2023
516dc3a
putting downloadPublicResource back in, errors not fixed
tcnichol Jan 2, 2024
cb68184
adding publicView option to the various visualizations. this means th…
tcnichol Jan 2, 2024
2cbf2c6
fix package lock
tcnichol Jan 2, 2024
3c40eba
removing console logs
tcnichol Jan 10, 2024
7f9757f
removing console logs
tcnichol Jan 10, 2024
286afd9
removing console logs
tcnichol Jan 10, 2024
ed2fa36
catch case if authorization is None and no public access for file
tcnichol Jan 11, 2024
c60dcd8
role was not working for dataset, fixed there but still not showing o…
tcnichol Jan 17, 2024
4b7baf4
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Jan 17, 2024
83350ca
does not break on front end, still needs clean up
tcnichol Jan 18, 2024
751e513
back end fixes after merge, some authorizations were not checked corr…
tcnichol Jan 18, 2024
1d3f4ba
fix file tab extractor
tcnichol Jan 18, 2024
c31db10
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Jan 18, 2024
f526cb4
file metadata from listeners now displays for public files
tcnichol Jan 18, 2024
8f954d5
button back for add metadata dataset
tcnichol Jan 18, 2024
b534b39
ran codegen
tcnichol Jan 18, 2024
0e75ecc
public metadata definitions
tcnichol Jan 18, 2024
fcfa1b0
metadata should work now for public when not signed in
tcnichol Jan 18, 2024
6a7b4cf
fixed text visualization, endpoint for public_files had a typo
tcnichol Jan 18, 2024
0548d9c
fixing more typoes
tcnichol Jan 18, 2024
3b55341
formatting
tcnichol Jan 19, 2024
38c66db
codegen
tcnichol Jan 19, 2024
052e69a
removing search for now
tcnichol Jan 19, 2024
e1eab9f
increment should be false for getting public files
tcnichol Jan 19, 2024
6bec4fd
adding public check to dataset files
tcnichol Jan 19, 2024
f7c7321
check public or authenticated in dataset routes
tcnichol Jan 19, 2024
b7e3592
don't use public route
tcnichol Jan 19, 2024
4e47cc2
removing console logs
tcnichol Jan 19, 2024
6a99a2f
fake data should populate both PUBLIC and AUTHENTICATED datasets
tcnichol Jan 21, 2024
cdeae3d
fixing download
tcnichol Jan 22, 2024
72db254
Merge branch 'main' into 485-public-datasets-visible-when-not-logged-in
tcnichol Jan 23, 2024
4bd99c5
fixing type on public/files
tcnichol Jan 24, 2024
098b35b
removing unused methods
tcnichol Jan 24, 2024
6c1b54d
remove divider
tcnichol Jan 24, 2024
9bd7e70
codegen
tcnichol Jan 25, 2024
e8da356
put divider back in
tcnichol Jan 26, 2024
7305ed3
removed divider
tcnichol Jan 26, 2024
9556c38
can download public file from file menu now
tcnichol Jan 26, 2024
e1f02f2
remove unused method
tcnichol Jan 26, 2024
aa1763a
black formatting
tcnichol Jan 27, 2024
7659974
black formatting
tcnichol Jan 27, 2024
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
61 changes: 49 additions & 12 deletions backend/app/deps/authorization_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,41 @@
from app.keycloak_auth import get_current_username
from app.models.authorization import RoleType, AuthorizationDB
from app.models.datasets import DatasetDB, DatasetStatus
from app.models.files import FileDB
from app.models.groups import GroupDB
from app.models.files import FileOut, FileDB, FileStatus
from app.models.groups import GroupOut, GroupDB
from app.models.metadata import MetadataDB
from app.models.pyobjectid import PyObjectId
from app.routers.authentication import get_admin
from app.routers.authentication import get_admin_mode


async def check_public_access(
resource_id: str,
resource_type: str,
role: RoleType,
current_user=Depends(get_current_username),
) -> bool:
has_public_access = False
if role == RoleType.VIEWER:
if resource_type == "dataset":
if (
dataset := await DatasetDB.get(PydanticObjectId(resource_id))
) is not None:
if (
dataset.status == DatasetStatus.PUBLIC.name
or dataset.status == DatasetStatus.AUTHENTICATED.name
):
has_public_access = True
elif resource_type == "file":
if (file := await FileDB.get(PydanticObjectId(resource_id))) is not None:
if (
file.status == FileStatus.PUBLIC.name
or file.status == FileStatus.AUTHENTICATED.name
):
has_public_access = True
return has_public_access


async def get_role(
dataset_id: str,
current_user=Depends(get_current_username),
Expand All @@ -31,6 +58,11 @@ async def get_role(
AuthorizationDB.user_ids == current_user,
),
)
public_access = await check_public_access(
dataset_id, "dataset", RoleType.VIEWER, current_user
)
if authorization is None and public_access:
return RoleType.VIEWER
return authorization.role


Expand All @@ -55,15 +87,11 @@ async def get_role_by_file(
if (
dataset := await DatasetDB.get(PydanticObjectId(file.dataset_id))
) is not None:
if dataset.status == DatasetStatus.AUTHENTICATED.name:
auth_dict = {
"creator": dataset.author.email,
"dataset_id": file.dataset_id,
"user_ids": [current_user],
"role": RoleType.VIEWER,
}
authenticated_auth = AuthorizationDB(**auth_dict)
return authenticated_auth
if (
dataset.status == DatasetStatus.AUTHENTICATED.name
or dataset.status == DatasetStatus.PUBLIC.name
):
return RoleType.VIEWER
else:
raise HTTPException(
status_code=403,
Expand Down Expand Up @@ -199,6 +227,7 @@ async def __call__(
) is not None:
if (
current_dataset.status == DatasetStatus.AUTHENTICATED.name
or current_dataset.status == DatasetStatus.PUBLIC.name
and self.role == "viewer"
):
return True
Expand Down Expand Up @@ -249,7 +278,15 @@ async def __call__(
detail=f"User `{current_user} does not have `{self.role}` permission on file {file_id}",
)
else:
raise HTTPException(status_code=404, detail=f"File {file_id} not found")
if (
file.status == FileStatus.PUBLIC.name
or file.status == FileStatus.AUTHENTICATED.name
) and self.role == RoleType.VIEWER:
return True
else:
raise HTTPException(
status_code=404, detail=f"File {file_id} not found"
)


class MetadataAuthorization:
Expand Down
42 changes: 40 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,27 @@
from app.models.users import UserDB, UserAPIKeyDB, ListenerAPIKeyDB
from app.models.visualization_config import VisualizationConfigDB
from app.models.visualization_data import VisualizationDataDB
from app.routers import folders, groups, status
from app.routers import folders, groups, public_folders, status
from app.routers import (
users,
authorization,
metadata,
public_metadata,
files,
public_files,
metadata_files,
datasets,
public_datasets,
metadata_datasets,
authentication,
keycloak,
elasticsearch,
public_elasticsearch,
listeners,
feeds,
jobs,
visualization,
public_visualization,
thumbnails,
)

Expand Down Expand Up @@ -113,12 +118,22 @@
tags=["metadata"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
public_metadata.router,
prefix="/public_metadata",
tags=["public_metadata"],
)
api_router.include_router(
files.router,
prefix="/files",
tags=["files"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
public_files.router,
prefix="/public_files",
tags=["public_files"],
)
api_router.include_router(
metadata_files.router,
prefix="/files",
Expand All @@ -132,14 +147,27 @@
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
metadata_datasets.router, prefix="/datasets", tags=["metadata"]
public_datasets.router,
prefix="/public_datasets",
tags=["public_datasets"],
)
api_router.include_router(
metadata_datasets.router,
prefix="/datasets",
tags=["metadata"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
folders.router,
prefix="/folders",
tags=["folders"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
public_folders.router,
prefix="/public_folders",
tags=["public_folders"],
)
api_router.include_router(
listeners.router,
prefix="/listeners",
Expand All @@ -164,6 +192,11 @@
tags=["elasticsearch"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
public_elasticsearch.router,
prefix="/public_elasticsearch",
tags=["public_elasticsearch"],
)
api_router.include_router(
feeds.router,
prefix="/feeds",
Expand All @@ -182,6 +215,11 @@
tags=["visualizations"],
dependencies=[Depends(get_current_username)],
)
api_router.include_router(
public_visualization.router,
prefix="/public_visualizations",
tags=["public_visualizations"],
)
api_router.include_router(
thumbnails.router,
prefix="/thumbnails",
Expand Down
3 changes: 2 additions & 1 deletion backend/app/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DatasetStatus(AutoName):
class DatasetBase(BaseModel):
name: str = "N/A"
description: Optional[str] = None
status: str = DatasetStatus.PRIVATE.name


class DatasetIn(DatasetBase):
Expand Down Expand Up @@ -65,7 +66,7 @@ class DatasetDBViewList(View, DatasetBase):
modified: datetime = Field(default_factory=datetime.utcnow)
auth: List[AuthorizationDB]
thumbnail_id: Optional[PydanticObjectId] = None
status: Optional[str]
status: str = DatasetStatus.PRIVATE.name

class Settings:
source = DatasetDB
Expand Down
16 changes: 15 additions & 1 deletion backend/app/models/files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from enum import Enum
from typing import Optional, List

from enum import Enum, auto
from beanie import Document, View, PydanticObjectId
from pydantic import Field, BaseModel

Expand All @@ -10,6 +10,19 @@
from app.models.users import UserOut


class AutoName(Enum):
def _generate_next_value_(name, start, count, last_values):
return name


class FileStatus(AutoName):
PRIVATE = auto()
PUBLIC = auto()
AUTHENTICATED = auto()
DEFAULT = auto()
TRIAL = auto()


class StorageType(str, Enum):
"""Depending on the StorageType,the file may need different properties such as local path or URL.
Also, some StorageTypes do not support versioning or anonymous sharing."""
Expand Down Expand Up @@ -47,6 +60,7 @@ class Settings:

class FileBase(BaseModel):
name: str = "N/A"
status: str = FileStatus.PRIVATE.name


class FileIn(FileBase):
Expand Down
1 change: 1 addition & 0 deletions backend/app/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ class ElasticsearchEntry(BaseModel):
bytes: Optional[int]
# metadata fields
metadata: Optional[List[dict]] = []
status: Optional[str]
7 changes: 6 additions & 1 deletion backend/app/routers/authorization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime
Copy link
Member

Choose a reason for hiding this comment

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

any reason you need date time?


from beanie import PydanticObjectId
from beanie.operators import Or, In
from bson import ObjectId
Expand Down Expand Up @@ -92,7 +94,10 @@ async def get_dataset_role(
if (
current_dataset := await DatasetDB.get(PydanticObjectId(dataset_id))
) is not None:
if current_dataset.status == DatasetStatus.AUTHENTICATED.name:
if (
current_dataset.status == DatasetStatus.AUTHENTICATED.name
or current_dataset.status == DatasetStatus.PUBLIC.name
):
public_authorization_in = {
"dataset_id": PydanticObjectId(dataset_id),
"role": RoleType.VIEWER,
Expand Down
Loading
Loading