Skip to content

Commit 2380be5

Browse files
authored
836 public search option (#964)
* the issue is that on this branch the status is not indexed * working on putting public search in * search not hidden * use public search endpoint, still need to remove cookie and authentication * trying to use name * lowerecase matches * lowerecase matches * indexing for file status was wrong * error in public search because of admin mode, not sure why its still happening * public layout not layout * public search is not commented out * formatting, fix test for search * need a public search result with public routes * removing creator filter unused imports * added missing import * inconsistent use of public/datasets and public_datasets fixed * _ for public files instead of / * _ for public datasets instead of / * file status should be fixed now * formatting * fixing the link for public file result
1 parent ce978cf commit 2380be5

File tree

15 files changed

+435
-30
lines changed

15 files changed

+435
-30
lines changed

backend/app/routers/datasets.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,15 @@ async def save_file(
681681
raise HTTPException(
682682
status_code=404, detail=f"Folder {folder_id} not found"
683683
)
684-
684+
file_public = False
685+
file_authenticated = False
686+
file_private = False
687+
if dataset.status == DatasetStatus.PUBLIC:
688+
file_public = True
689+
elif dataset.status == DatasetStatus.AUTHENTICATED:
690+
file_authenticated = True
691+
else:
692+
file_private = True
685693
await add_file_entry(
686694
new_file,
687695
user,
@@ -690,6 +698,8 @@ async def save_file(
690698
rabbitmq_client,
691699
file.file,
692700
content_type=file.content_type,
701+
authenticated=file_authenticated,
702+
public=file_public,
693703
)
694704
return new_file.dict()
695705
raise HTTPException(status_code=404, detail=f"Dataset {dataset_id} not found")

backend/app/routers/elasticsearch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def _add_permissions_clause(
2323
"should": [
2424
{"term": {"creator": username}},
2525
{"term": {"user_ids": username}},
26-
{"term": {"status": "AUTHENTICATED"}},
27-
{"term": {"status": "PUBLIC"}},
26+
{"term": {"status": "authenticated"}},
27+
{"term": {"status": "public"}},
2828
]
2929
}
3030
}

backend/app/routers/public_elasticsearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def _add_public_clause(query):
1111
"""Append filter to Elasticsearch object that restricts permissions based on the requesting user."""
1212
# TODO: Add public filter once added
13-
public_clause = {"bool": {"should": [{"term": {"public": True}}]}}
13+
public_clause = {"bool": {"should": [{"term": {"status": "public"}}]}}
1414

1515
updated_query = ""
1616
for content in query.decode().split("\n"):

backend/app/search/index.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ async def index_file(
6666
file: FileOut,
6767
user_ids: Optional[List[str]] = None,
6868
update: bool = False,
69-
public: bool = False,
70-
authenticated: bool = False,
7169
):
7270
"""Create or update an Elasticsearch entry for the file. user_ids is the list of users
7371
with permission to at least view the file's dataset, it will be queried if not provided.
@@ -89,11 +87,7 @@ async def index_file(
8987
):
9088
metadata.append(md.content)
9189

92-
status = None
93-
if authenticated:
94-
status = "AUTHENTICATED"
95-
if public:
96-
status = "PUBLIC"
90+
status = file.status
9791

9892
# Add en entry to the file index
9993
doc = ElasticsearchEntry(
@@ -109,7 +103,7 @@ async def index_file(
109103
folder_id=str(file.folder_id),
110104
bytes=file.bytes,
111105
metadata=metadata,
112-
status=status,
106+
status=file.status,
113107
).dict()
114108
if update:
115109
try:

backend/app/tests/test_elastic_search.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ async def test_public_files():
193193
time.sleep(1)
194194
dummy_file_query = []
195195

196+
query_body = {"query": {"match": {"creator": "xyz"}}}
197+
196198
user_public_clause = {
197199
"bool": {
198200
"should": [
199-
{"term": {"creator": "xyz"}},
200-
{"term": {"status": "PUBLIC"}},
201+
{"term": {"status": "public"}},
201202
]
202203
}
203204
}
@@ -252,7 +253,7 @@ async def test_public_datasets():
252253
"bool": {
253254
"should": [
254255
{"term": {"creator": "abcd"}},
255-
{"term": {"status": "PUBLIC"}},
256+
{"term": {"status": "public"}},
256257
]
257258
}
258259
}

frontend/src/app.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Config {
1515
KeycloakRefresh: string;
1616
KeycloakRegister: string;
1717
searchEndpoint: string;
18+
publicSearchEndpoint: string;
1819
refreshTokenInterval: number;
1920
extractorStatusInterval: number;
2021
extractorLivelihoodInterval: number;
@@ -61,6 +62,7 @@ config["KeycloakRegister"] = `${config.KeycloakBaseURL}/register`;
6162

6263
// elasticsearch
6364
config["searchEndpoint"] = `${hostname}/api/v2/elasticsearch`;
65+
config["publicSearchEndpoint"] = `${hostname}/api/v2/public_elasticsearch`;
6466

6567
// refresh token time interval
6668
config["refreshTokenInterval"] = 1000 * 60; // 1 minute

frontend/src/components/PublicLayout.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import { Explore } from "@material-ui/icons";
2222
import PersonIcon from "@mui/icons-material/Person";
2323
import VpnKeyIcon from "@mui/icons-material/VpnKey";
2424
import LogoutIcon from "@mui/icons-material/Logout";
25+
import { EmbeddedPublicSearch } from "./search/EmbeddedPublicSearch";
26+
import { AppVersion } from "./versions/AppVersion";
27+
import SearchDatasetIcon from "@mui/icons-material/Search";
2528
import { EmbeddedSearch } from "./search/EmbeddedSearch";
2629
import { Footer } from "./navigation/Footer";
2730

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

49-
const SearchDiv = styled("div")(({ theme }) => ({
52+
const PublicSearchDiv = styled("div")(({ theme }) => ({
5053
position: "relative",
5154
marginLeft: theme.spacing(3),
5255
marginBottom: "-5px", // to compoensate the tags div
@@ -94,7 +97,7 @@ export default function PersistentDrawerLeft(props) {
9497
const { children } = props;
9598
const theme = useTheme();
9699
const [open, setOpen] = React.useState(false);
97-
const [embeddedSearchHidden, setEmbeddedSearchHidden] = React.useState(false);
100+
const [embeddedPublicSearchHidden, setEmbeddedPublicSearchHidden] = React.useState(false);
98101
const [anchorEl, setAnchorEl] = React.useState(null);
99102
const isMenuOpen = Boolean(anchorEl);
100103

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

115118
useEffect(() => {
116119
if (location.pathname.includes("search")) {
117-
setEmbeddedSearchHidden(true);
120+
setEmbeddedPublicSearchHidden(true);
118121
} else {
119-
setEmbeddedSearchHidden(false);
122+
setEmbeddedPublicSearchHidden(false);
120123
}
121124
}, [location]);
122125

@@ -151,10 +154,10 @@ export default function PersistentDrawerLeft(props) {
151154
</Link>
152155

153156
{/*for searching*/}
154-
<SearchDiv hidden={true}>
157+
<PublicSearchDiv hidden={embeddedPublicSearchHidden}>
155158
{/* <InputSearchBox />*/}
156-
<EmbeddedSearch />
157-
</SearchDiv>
159+
<EmbeddedPublicSearch />
160+
</PublicSearchDiv>
158161
<Box sx={{ flexGrow: 1 }} />
159162
<Box sx={{ marginLeft: "auto" }}>
160163
<Link href="/auth/register" sx={link}>
@@ -233,6 +236,18 @@ export default function PersistentDrawerLeft(props) {
233236
</ListItemButton>
234237
</ListItem>
235238
</List>
239+
<Divider/>
240+
<List>
241+
<ListItem key={"public_search"} disablePadding>
242+
<ListItemButton component={RouterLink} to="/public_search">
243+
<ListItemIcon>
244+
<SearchDatasetIcon />
245+
</ListItemIcon>
246+
<ListItemText primary={"Public Search"} />
247+
</ListItemButton>
248+
</ListItem>
249+
</List>
250+
{/*<Divider />*/}
236251
<Divider />
237252
</Drawer>
238253
<Main open={open}>

frontend/src/components/datasets/DatasetCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function DatasetCard(props: DatasetCardProps) {
5252
{publicView ? (
5353
<CardActionArea
5454
component={Link}
55-
to={`/public/datasets/${id}`}
55+
to={`/public_datasets/${id}`}
5656
sx={{ height: "100%" }}
5757
>
5858
<CardHeader title={name} subheader={subheader} />

frontend/src/components/datasets/PublicDataset.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ export const PublicDataset = (): JSX.Element => {
133133
const tmpPaths = [
134134
{
135135
name: about["name"],
136-
url: `/public/datasets/${datasetId}`,
136+
url: `/public_datasets/${datasetId}`,
137137
},
138138
];
139139

140140
if (publicFolderPath != null) {
141141
for (const folderBread of publicFolderPath) {
142142
tmpPaths.push({
143143
name: folderBread["folder_name"],
144-
url: `/public/datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
144+
url: `/public_datasets/${datasetId}?folder=${folderBread["folder_id"]}`,
145145
});
146146
}
147147
} else {

frontend/src/components/datasets/PublicDatasetCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function PublicDatasetCard(props: PublicDatasetCardProps) {
5252
{publicView ? (
5353
<CardActionArea
5454
component={Link}
55-
to={`/public/datasets/${id}`}
55+
to={`/public_datasets/${id}`}
5656
sx={{ height: "100%" }}
5757
>
5858
<CardHeader title={name} subheader={subheader} />

0 commit comments

Comments
 (0)