Skip to content

Commit

Permalink
CMR-4913 EDSC shows 0 granules for public collection when user isn't …
Browse files Browse the repository at this point in the history
…logged in (#512)

* CMR-4913 adds trim to entry titles to solve issue when daacs add preceeding whitespace

* CMR-4913 adds test coverage

* CMR-4913 fixes test coverage
  • Loading branch information
daniel-zamora authored May 12, 2018
1 parent 99e379e commit eaa45ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
6 changes: 3 additions & 3 deletions search-app/src/cmr/search/services/acls/granule_acls.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Contains functions for manipulating granule acls"
(:require
[clojure.set :as set]
[clojure.string :as string]
[cmr.common-app.services.search.group-query-conditions :as gc]
[cmr.common-app.services.search.query-execution :as qe]
[cmr.common-app.services.search.query-model :as cqm]
Expand Down Expand Up @@ -50,7 +51,7 @@
[context coll-ids-by-prov _ acls]
(filter (fn [acl]
(let [{{:keys [provider-id] :as cii} :catalog-item-identity} acl
entry-titles (get-in cii [:collection-identifier :entry-titles])
entry-titles (map string/trim (get-in cii [:collection-identifier :entry-titles]))
acl-coll-ids (->> entry-titles
(map (partial coll-cache/get-collection context provider-id))
;; It's possible an ACL refers to an entry title that doesn't exist
Expand Down Expand Up @@ -141,7 +142,7 @@
(reduce (fn [condition-map entry-title]
(if-let [{:keys [concept-id]} (coll-cache/get-collection context provider-id entry-title)]
(update-in condition-map [:concept-ids] conj concept-id)
(update-in condition-map [:entry-titles] conj entry-title)))
(update-in condition-map [:entry-titles] conj (string/trim entry-title))))
{:concept-ids nil
:entry-titles nil}
entry-titles)
Expand Down Expand Up @@ -230,7 +231,6 @@
provider-ids
(acl-helper/get-acls-applicable-to-token context))
acl-cond (acls->query-condition context coll-ids-by-prov acls)]

(r/resolve-collection-queries
context
(update-in query [:condition] #(gc/and-conds [acl-cond %])))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
[cmr.common-app.services.search.messages :as vmsg]
[cmr.common.services.messages :as msg]
[cmr.common.util :refer [are3]]
[cmr.mock-echo.client.echo-util :as e]
[cmr.search.services.messages.common-messages :as smsg]
[cmr.system-int-test.data2.core :as d]
[cmr.system-int-test.data2.granule :as dg]
[cmr.system-int-test.data2.umm-spec-collection :as data-umm-c]
[cmr.system-int-test.system :as int-s]
[cmr.system-int-test.utils.dev-system-util :as dev-sys-util]
[cmr.system-int-test.utils.index-util :as index]
[cmr.system-int-test.utils.ingest-util :as ingest]
Expand All @@ -28,11 +30,11 @@

(deftest search-by-native-id
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "E1"
:ShortName "S1"
:Version "V1"}))
:ShortName "S1"
:Version "V1"}))
coll2 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "E2"
:ShortName "S2"
:Version "V2"}))
:ShortName "S2"
:Version "V2"}))
coll1-cid (get-in coll1 [:concept-id])
coll2-cid (get-in coll2 [:concept-id])
gran1 (d/ingest "PROV1" (dg/granule-with-umm-spec-collection coll1 coll1-cid {:granule-ur "Granule1"}))
Expand Down Expand Up @@ -68,11 +70,11 @@

(deftest search-by-provider-id
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "E1"
:ShortName "S1"
:Version "V1"}))
:ShortName "S1"
:Version "V1"}))
coll2 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "E2"
:ShortName "S2"
:Version "V2"}))
:ShortName "S2"
:Version "V2"}))
coll1-cid (get-in coll1 [:concept-id])
coll2-cid (get-in coll2 [:concept-id])
gran1 (d/ingest "PROV1" (dg/granule-with-umm-spec-collection coll1 coll1-cid {:granule-ur "Granule1"}))
Expand Down Expand Up @@ -119,17 +121,17 @@

(deftest search-by-dataset-id
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "OneCollectionV1"
:ShortName "S1"
:Version "V1"}))
:ShortName "S1"
:Version "V1"}))
coll2 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "AnotherCollectionV1"
:ShortName "S2"
:Version "V2"}))
:ShortName "S2"
:Version "V2"}))
coll3 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "OneCollectionV1"
:ShortName "S3"
:Version "V3"}))
:ShortName "S3"
:Version "V3"}))
coll4 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "OtherCollectionV1"
:ShortName "S4"
:Version "V4"}))
:ShortName "S4"
:Version "V4"}))
coll1-cid (get-in coll1 [:concept-id])
coll2-cid (get-in coll2 [:concept-id])
coll3-cid (get-in coll3 [:concept-id])
Expand Down Expand Up @@ -216,11 +218,11 @@

(deftest search-by-granule-ur
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "E1"
:ShortName "S1"
:Version "V1"}))
:ShortName "S1"
:Version "V1"}))
coll2 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "E2"
:ShortName "S2"
:Version "V2"}))
:ShortName "S2"
:Version "V2"}))
coll1-cid (get-in coll1 [:concept-id])
coll2-cid (get-in coll2 [:concept-id])
gran1 (d/ingest "PROV1" (dg/granule-with-umm-spec-collection coll1 coll1-cid {:granule-ur "Granule1"}))
Expand Down Expand Up @@ -297,11 +299,11 @@

(deftest search-by-cloud-cover
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle "E1"
:ShortName "S1"
:Version "V1"}))
:ShortName "S1"
:Version "V1"}))
coll2 (d/ingest-umm-spec-collection "PROV2" (data-umm-c/collection {:EntryTitle "E2"
:ShortName "S2"
:Version "V2"}))
:ShortName "S2"
:Version "V2"}))
coll1-cid (get-in coll1 [:concept-id])
coll2-cid (get-in coll2 [:concept-id])
gran1 (d/ingest "PROV1" (dg/granule-with-umm-spec-collection coll1 coll1-cid {:cloud-cover 0.8}))
Expand Down Expand Up @@ -540,3 +542,14 @@
(is (= {:status 429
:errors ["Excessive query rate. Please contact [email protected]."]}
(search/make-raw-search-query :granule ".json?short_name=MCD43A4&&page_size=5")))))

(deftest entry-title-with-preceeding-succeeding-whitespace-test
(e/ungrant (int-s/context) "ACL1200000001-CMR")
(let [coll1 (d/ingest-umm-spec-collection "PROV1" (data-umm-c/collection {:EntryTitle " E1 "
:ShortName "S1"
:Version "V1"}))
coll1-cid (get-in coll1 [:concept-id])
gran1 (d/ingest "PROV1" (dg/granule-with-umm-spec-collection coll1 coll1-cid))]
(e/grant-guest (int-s/context) (e/gran-catalog-item-id "PROV1" (e/coll-id [" E1 "])))
(index/wait-until-indexed)
(d/refs-match? [gran1] (search/find-refs :granule (merge {:concept_id coll1-cid})))))

0 comments on commit eaa45ae

Please sign in to comment.