Skip to content

Commit 4015c50

Browse files
committed
CMR-10430: fixes another possible autocomplete permission edge case
1 parent b5185dc commit 4015c50

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

indexer-app/src/cmr/indexer/services/autocomplete.clj

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,22 @@
164164
(anti-value? value)))
165165

166166
(defn- parse-collection
167-
"Parses collection into concepts. Returns nil on error."
168-
[context collection]
169-
(try
170-
(cp/parse-concept context collection)
171-
(catch Exception e
172-
(error (format "An error occurred while parsing collection for autocomplete with concept-id [%s]: %s"
173-
(:concept-id collection)
174-
(.getMessage e))))))
167+
"Parses collection into concepts. Returns a vector containing:
168+
1. A list of successfully parsed collections
169+
2. A list of concept IDs that failed to parse"
170+
[context collections]
171+
(let [results (map (fn [collection]
172+
(try
173+
[(cp/parse-concept context collection) nil]
174+
(catch Exception e
175+
(error (format "An error occurred while parsing collection for autocomplete with concept-id [%s]: %s"
176+
(:concept-id collection)
177+
(.getMessage e)))
178+
[nil (:concept-id collection)])))
179+
collections)
180+
parsed-collections (keep first results)
181+
failed-concept-ids (keep second results)]
182+
[parsed-collections failed-concept-ids]))
175183

176184
(defn- get-humanized-collections
177185
"Get the humanized fields for the passed in parsed-concept and remove the old flat platform
@@ -187,14 +195,14 @@
187195
index (get-in index-names [:autocomplete :autocomplete])
188196
humanized-fields-fn (partial get-humanized-collections context)
189197
existing-collections (remove :deleted collections)
190-
parsed-concepts (->> existing-collections
191-
(map #(parse-collection context %))
192-
(remove nil?))
198+
[parsed-concepts failed-concept-ids] (parse-collection context existing-collections)
199+
valid-collections (remove #(contains? (set failed-concept-ids) (:concept-id %))
200+
existing-collections)
193201
collection-permissions (map (fn [collection]
194202
(let [permissions (collection-util/get-coll-permitted-group-ids context provider-id collection)]
195203
{:id (:concept-id collection)
196204
:permissions permissions}))
197-
existing-collections)
205+
valid-collections)
198206
humanized-fields (map humanized-fields-fn parsed-concepts)
199207
humanized-fields-with-permissions (map merge collection-permissions humanized-fields)]
200208
(->> humanized-fields-with-permissions

system-int-test/test/cmr/system_int_test/search/autocomplete/suggestion_permissions_test.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"PROV1"
4343
(data-umm-spec/collection
4444
{:EntryTitle "Second Restricted Collection"
45-
:ShortName "SECOND RESTRICTED COLLECTION"
46-
:DataCenters [(data-umm-spec/data-center
45+
:ShortName "SECOND RESTRICTED COLLECTION"
46+
:DataCenters [(data-umm-spec/data-center
4747
{:Roles ["ARCHIVER"]
4848
:ShortName "RESTRICTED-ORG2"})]})
4949
{:format :umm-json
@@ -66,12 +66,12 @@
6666
"PROV1"
6767
(data-umm-spec/collection
6868
{:EntryTitle "Public Collection"
69-
:ShortName "PUBLIC"
70-
:DataCenters [(data-umm-spec/data-center
71-
{:Roles ["ARCHIVER"]
72-
:ShortName "PUBLIC-ORG"})]})
73-
{:format :umm-json
74-
:validate-keywords false})
69+
:ShortName "PUBLIC"
70+
:DataCenters [(data-umm-spec/data-center
71+
{:Roles ["ARCHIVER"]
72+
:ShortName "PUBLIC-ORG"})]})
73+
{:format :umm-json
74+
:validate-keywords false})
7575

7676
;; Grant explicit permission to only the authorized group for restricted collections
7777
_ (e/grant-group (s/context)

0 commit comments

Comments
 (0)