Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bbc9ddf
the issue is that on this branch the status is not indexed
tcnichol Jan 16, 2024
80c6693
Merge branch 'main' into 836-public-search-option
tcnichol Feb 5, 2024
ad4d58c
Merge branch 'main' into 836-public-search-option
tcnichol Feb 26, 2024
0e12d5f
working on putting public search in
tcnichol Feb 26, 2024
060d507
search not hidden
tcnichol Feb 26, 2024
1877c98
use public search endpoint, still need to remove cookie and authentic…
tcnichol Feb 26, 2024
aee8489
trying to use name
tcnichol Mar 6, 2024
d9f193b
lowerecase matches
tcnichol Mar 7, 2024
186b9d0
lowerecase matches
tcnichol Mar 7, 2024
ae8b023
indexing for file status was wrong
tcnichol Mar 7, 2024
6e54315
error in public search because of admin mode, not sure why its still …
tcnichol Mar 7, 2024
e1d0a8b
public layout not layout
tcnichol Mar 7, 2024
5780c23
public search is not commented out
tcnichol Mar 8, 2024
d4ec27c
formatting, fix test for search
tcnichol Mar 8, 2024
824a28c
need a public search result with public routes
tcnichol Mar 11, 2024
585e534
removing creator filter
tcnichol Mar 13, 2024
ee26a54
Merge branch 'main' into 836-public-search-option
tcnichol Apr 11, 2024
f64ff8c
added missing import
tcnichol Apr 15, 2024
7975453
Merge branch 'main' into 836-public-search-option
tcnichol Apr 15, 2024
5e33165
inconsistent use of public/datasets and public_datasets fixed
tcnichol Apr 16, 2024
99ba123
Merge remote-tracking branch 'origin/836-public-search-option' into 8…
tcnichol Apr 16, 2024
fd1d71a
Merge branch 'main' into 836-public-search-option
tcnichol May 14, 2024
6e2f35d
_ for public files instead of /
tcnichol May 14, 2024
2d3ca91
_ for public datasets instead of /
tcnichol May 14, 2024
b76b4a8
file status should be fixed now
tcnichol May 14, 2024
265ac91
Merge branch 'main' into 836-public-search-option
tcnichol May 16, 2024
9c0abb8
formatting
tcnichol May 16, 2024
604dc73
fixing the link for public file result
tcnichol May 31, 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
12 changes: 11 additions & 1 deletion backend/app/routers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,15 @@ async def save_file(
raise HTTPException(
status_code=404, detail=f"Folder {folder_id} not found"
)

file_public = False
file_authenticated = False
file_private = False
if dataset.status == DatasetStatus.PUBLIC:
file_public = True
elif dataset.status == DatasetStatus.AUTHENTICATED:
file_authenticated = True
else:
file_private = True
await add_file_entry(
new_file,
user,
Expand All @@ -690,6 +698,8 @@ async def save_file(
rabbitmq_client,
file.file,
content_type=file.content_type,
authenticated=file_authenticated,
public=file_public,
)
return new_file.dict()
raise HTTPException(status_code=404, detail=f"Dataset {dataset_id} not found")
Expand Down
4 changes: 2 additions & 2 deletions backend/app/routers/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def _add_permissions_clause(
"should": [
{"term": {"creator": username}},
{"term": {"user_ids": username}},
{"term": {"status": "AUTHENTICATED"}},
{"term": {"status": "PUBLIC"}},
{"term": {"status": "authenticated"}},
{"term": {"status": "public"}},
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routers/public_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def _add_public_clause(query):
"""Append filter to Elasticsearch object that restricts permissions based on the requesting user."""
# TODO: Add public filter once added
public_clause = {"bool": {"should": [{"term": {"public": True}}]}}
public_clause = {"bool": {"should": [{"term": {"status": "public"}}]}}

updated_query = ""
for content in query.decode().split("\n"):
Expand Down
10 changes: 2 additions & 8 deletions backend/app/search/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ async def index_file(
file: FileOut,
user_ids: Optional[List[str]] = None,
update: bool = False,
public: bool = False,
authenticated: bool = False,
):
"""Create or update an Elasticsearch entry for the file. user_ids is the list of users
with permission to at least view the file's dataset, it will be queried if not provided.
Expand All @@ -89,11 +87,7 @@ async def index_file(
):
metadata.append(md.content)

status = None
if authenticated:
status = "AUTHENTICATED"
if public:
status = "PUBLIC"
status = file.status

# Add en entry to the file index
doc = ElasticsearchEntry(
Expand All @@ -109,7 +103,7 @@ async def index_file(
folder_id=str(file.folder_id),
bytes=file.bytes,
metadata=metadata,
status=status,
status=file.status,
).dict()
if update:
try:
Expand Down
7 changes: 4 additions & 3 deletions backend/app/tests/test_elastic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ async def test_public_files():
time.sleep(1)
dummy_file_query = []

query_body = {"query": {"match": {"creator": "xyz"}}}

user_public_clause = {
"bool": {
"should": [
{"term": {"creator": "xyz"}},
{"term": {"status": "PUBLIC"}},
{"term": {"status": "public"}},
]
}
}
Expand Down Expand Up @@ -252,7 +253,7 @@ async def test_public_datasets():
"bool": {
"should": [
{"term": {"creator": "abcd"}},
{"term": {"status": "PUBLIC"}},
{"term": {"status": "public"}},
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Config {
KeycloakRefresh: string;
KeycloakRegister: string;
searchEndpoint: string;
publicSearchEndpoint: string;
refreshTokenInterval: number;
extractorStatusInterval: number;
extractorLivelihoodInterval: number;
Expand Down Expand Up @@ -61,6 +62,7 @@ config["KeycloakRegister"] = `${config.KeycloakBaseURL}/register`;

// elasticsearch
config["searchEndpoint"] = `${hostname}/api/v2/elasticsearch`;
config["publicSearchEndpoint"] = `${hostname}/api/v2/public_elasticsearch`;

// refresh token time interval
config["refreshTokenInterval"] = 1000 * 60; // 1 minute
Expand Down
29 changes: 22 additions & 7 deletions frontend/src/components/PublicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Explore } from "@material-ui/icons";
import PersonIcon from "@mui/icons-material/Person";
import VpnKeyIcon from "@mui/icons-material/VpnKey";
import LogoutIcon from "@mui/icons-material/Logout";
import { EmbeddedPublicSearch } from "./search/EmbeddedPublicSearch";
import { AppVersion } from "./versions/AppVersion";
import SearchDatasetIcon from "@mui/icons-material/Search";
import { EmbeddedSearch } from "./search/EmbeddedSearch";
import { Footer } from "./navigation/Footer";

Expand All @@ -46,7 +49,7 @@ const Main = styled("main", { shouldForwardProp: (prop) => prop !== "open" })<{
}),
}));

const SearchDiv = styled("div")(({ theme }) => ({
const PublicSearchDiv = styled("div")(({ theme }) => ({
position: "relative",
marginLeft: theme.spacing(3),
marginBottom: "-5px", // to compoensate the tags div
Expand Down Expand Up @@ -94,7 +97,7 @@ export default function PersistentDrawerLeft(props) {
const { children } = props;
const theme = useTheme();
const [open, setOpen] = React.useState(false);
const [embeddedSearchHidden, setEmbeddedSearchHidden] = React.useState(false);
const [embeddedPublicSearchHidden, setEmbeddedPublicSearchHidden] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState(null);
const isMenuOpen = Boolean(anchorEl);

Expand All @@ -114,9 +117,9 @@ export default function PersistentDrawerLeft(props) {

useEffect(() => {
if (location.pathname.includes("search")) {
setEmbeddedSearchHidden(true);
setEmbeddedPublicSearchHidden(true);
} else {
setEmbeddedSearchHidden(false);
setEmbeddedPublicSearchHidden(false);
}
}, [location]);

Expand Down Expand Up @@ -151,10 +154,10 @@ export default function PersistentDrawerLeft(props) {
</Link>

{/*for searching*/}
<SearchDiv hidden={true}>
<PublicSearchDiv hidden={embeddedPublicSearchHidden}>
{/* <InputSearchBox />*/}
<EmbeddedSearch />
</SearchDiv>
<EmbeddedPublicSearch />
</PublicSearchDiv>
<Box sx={{ flexGrow: 1 }} />
<Box sx={{ marginLeft: "auto" }}>
<Link href="/auth/register" sx={link}>
Expand Down Expand Up @@ -233,6 +236,18 @@ export default function PersistentDrawerLeft(props) {
</ListItemButton>
</ListItem>
</List>
<Divider/>
<List>
<ListItem key={"public_search"} disablePadding>
<ListItemButton component={RouterLink} to="/public_search">
<ListItemIcon>
<SearchDatasetIcon />
</ListItemIcon>
<ListItemText primary={"Public Search"} />
</ListItemButton>
</ListItem>
</List>
{/*<Divider />*/}
<Divider />
</Drawer>
<Main open={open}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/datasets/DatasetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function DatasetCard(props: DatasetCardProps) {
{publicView ? (
<CardActionArea
component={Link}
to={`/public/datasets/${id}`}
to={`/public_datasets/${id}`}
sx={{ height: "100%" }}
>
<CardHeader title={name} subheader={subheader} />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/datasets/PublicDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ export const PublicDataset = (): JSX.Element => {
const tmpPaths = [
{
name: about["name"],
url: `/public/datasets/${datasetId}`,
url: `/public_datasets/${datasetId}`,
},
];

if (publicFolderPath != null) {
for (const folderBread of publicFolderPath) {
tmpPaths.push({
name: folderBread["folder_name"],
url: `/public/datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
url: `/public_datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
});
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/datasets/PublicDatasetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function PublicDatasetCard(props: PublicDatasetCardProps) {
{publicView ? (
<CardActionArea
component={Link}
to={`/public/datasets/${id}`}
to={`/public_datasets/${id}`}
sx={{ height: "100%" }}
>
<CardHeader title={name} subheader={subheader} />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/files/FilesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function FilesTable(props: FilesTableProps) {
setCurrPageNum(1);
// Redirect to file route with file Id and dataset id and folderId
history(
`/public/files/${selectedFileId}?dataset=${props.datasetId}&folder=${folderId}&verNum=${selectedFileId}`
`/public_files/${selectedFileId}?dataset=${props.datasetId}&folder=${folderId}&verNum=${selectedFileId}`
);
};
const selectFolder = (selectedFolderId: string | undefined) => {
Expand All @@ -70,7 +70,7 @@ export default function FilesTable(props: FilesTableProps) {
// reset page number to 1
setCurrPageNum(1);
// Redirect to file route with file Id and dataset id
history(`/public/datasets/${datasetId}?folder=${selectedFolderId}`);
history(`/public_datasets/${datasetId}?folder=${selectedFolderId}`);
};

const datasetRole = useSelector(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/files/PublicFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ export const PublicFile = (): JSX.Element => {
const tmpPaths = [
{
name: about["name"],
url: `/public/datasets/${datasetId}`,
url: `/public_datasets/${datasetId}`,
},
];

if (folderPath != null) {
for (const folderBread of folderPath) {
tmpPaths.push({
name: folderBread["folder_name"],
url: `/public/datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
url: `/public_datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
});
}
} else {
Expand Down
67 changes: 67 additions & 0 deletions frontend/src/components/search/EmbeddedPublicSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useEffect, useState } from "react";
import { DataSearch, ReactiveBase } from "@appbaseio/reactivesearch";

import { useNavigate } from "react-router-dom";
import config from "../../app.config";
import { searchTheme } from "../../theme";
import Cookies from "universal-cookie";

export function EmbeddedPublicSearch() {
const history = useNavigate();
const cookies = new Cookies();
const [authorizationHeader, setAuthorizationHeader] = useState({
Authorization: cookies.get("Authorization"),
});
const getUpdatedCookie = () => {
const cookies = new Cookies();
setAuthorizationHeader({ Authorization: cookies.get("Authorization") });
};

// Pulling latest cookie
useEffect(() => {
const intervalId = setInterval(
getUpdatedCookie,
config.refreshTokenInterval
);
return () => clearInterval(intervalId);
}, []);

// @ts-ignore
return (
<ReactiveBase
url={config.publicSearchEndpoint}
app="all"
headers={authorizationHeader}
theme={searchTheme}
>
<DataSearch
componentId="searchbox"
autosuggest={true}
highlight={true}
queryFormat="or"
fuzziness={0}
debounce={100}
// apply react to the filter
URLParams={true}
showFilter={true}
showClear
renderNoSuggestion="No suggestions found."
dataField={["name", "description"]}
// placeholder="Search for Dataset"
innerClass={{
title: "search-title",
input: "embedded-search-input",
}}
onValueSelected={function (value, cause, _) {
if (
cause === "SUGGESTION_SELECT" ||
cause === "ENTER_PRESS" ||
cause === "SEARCH_ICON_CLICK"
) {
history(`/public_search?searchbox="${value}"`);
}
}}
/>
</ReactiveBase>
);
}
Loading