Skip to content

Commit 02bea62

Browse files
committed
Fetch permissions from ACL doc
1 parent b0b2cea commit 02bea62

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

example-apps/internal-knowledge-search/app-ui/src/components/SearchApplicationSettings.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ const SearchApplicationSettings: React.FC = () => {
1515
const {showToast} = useToast();
1616

1717
const fetchPersonaOptions = async () => {
18-
const identitiesIndex = ".search-acl-filter-search-sharepoint" //TODO fix hardcoded
19-
const identitiesPath = searchEndpoint+"/"+identitiesIndex+"/_search"
20-
const response = await fetch(identitiesPath, {headers: {"Authorization": "ApiKey "+apiKey}});
21-
const jsonData = await response.json();
22-
const ids = jsonData.hits.hits.map((hit) => hit._id)
23-
return ids
18+
try {
19+
const identitiesIndex = ".search-acl-filter-search-sharepoint" //TODO fix hardcoded
20+
const identitiesPath = searchEndpoint + "/" + identitiesIndex + "/_search"
21+
const response = await fetch(identitiesPath, {headers: {"Authorization": "ApiKey " + apiKey}});
22+
const jsonData = await response.json();
23+
const ids = jsonData.hits.hits.map((hit) => hit._id)
24+
return ids
25+
} catch (e) {
26+
console.log("Something went wrong tying to fetch ACL identities")
27+
console.log(e)
28+
return ["admin"]
29+
}
2430
}
2531

26-
const [searchPersonaOptions, setSearchPersonaOptions] = useState(["admin", "user"]);
32+
const [searchPersonaOptions, setSearchPersonaOptions] = useState(["admin"]);
2733

2834
useEffect(()=>{
2935
(async()=>{
@@ -128,10 +134,11 @@ const SearchApplicationSettings: React.FC = () => {
128134
<div className="relative">
129135
<select
130136
onChange={(event) => handlePersonaChange(event.target.value)}
137+
value={searchPersona}
131138
className="flex items-center space-x-2 p-2 bg-white rounded border border-gray-300 focus:outline-none focus:border-blue-500"
132139
>
133140
{searchPersonaOptions.map((option, index) => (
134-
<option value={option} selected={option == searchPersona} className="block text-left p-2 hover:bg-gray-100 cursor-pointer">
141+
<option value={option} key={option} className="block text-left p-2 hover:bg-gray-100 cursor-pointer">
135142
{option}
136143
</option>
137144
))}

example-apps/internal-knowledge-search/app-ui/src/pages/SearchPage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@ export default function SearchPage() {
5252
return adminApiKey
5353
}
5454
else {
55-
const permissions = ['foo'] // todo
55+
const identitiesIndex = ".search-acl-filter-search-sharepoint" //TODO fix hardcoded
56+
const identityPath = searchEndpoint + "/" + identitiesIndex + "/_doc/" + searchPersona
57+
const response = await fetch(identityPath, {headers: {"Authorization": "ApiKey " + adminApiKey}});
58+
const jsonData = await response.json();
59+
console.log(jsonData)
60+
const permissions = jsonData._source.query.template.params.access_control
5661
const apiKeyRoleDescriptor = {
5762
name: searchPersona,
5863
role_descriptors: {
5964
"dls-role": {
6065
"cluster": ["all"],
6166
"indices": [
6267
{
63-
"names": ["search-sharepoint"],
68+
"names": ["search-sharepoint"],// TODO: hardcoded
6469
"privileges": ["read"],
6570
"query": {
6671
"template": {

0 commit comments

Comments
 (0)