Skip to content

Commit

Permalink
CMR-9190: PR comments
Browse files Browse the repository at this point in the history
CMR-9190 pr comments
  • Loading branch information
daniel-zamora authored and eudoroolivares2016 committed Oct 3, 2023
1 parent 9a2d377 commit 58154a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
good-page-num (str post-data-body "&page_num=2&page_size=2")
bad-page-size (str post-data-body "&page_num=2&page_size=-3")
bad-page-size2 (str post-data-body "&page_num=1&page_size=foo")
good-page-size (str post-data-body "&page_num=1&page_size=3")]
good-page-size (str post-data-body "&page_num=1&page_size=3")
zero-page-size (str post-data-body "&page_size=0")]

(are3
[post-data-body expected-response]
Expand Down Expand Up @@ -91,6 +92,10 @@
good-page-size
"{\"C1200000010-PROV1\":[],\"C1200000011-PROV1\":[],\"C1200000012-PROV1\":[]}"

"zero page_size"
zero-page-size
"{\"C1200000010-PROV1\":[],\"C1200000011-PROV1\":[],\"C1200000012-PROV1\":[],\"C1200000013-PROV1\":[]}"

"valid page_num"
good-page-num
"{\"C1200000012-PROV1\":[],\"C1200000013-PROV1\":[]}")))
Expand Down
6 changes: 3 additions & 3 deletions access-control-app/src/cmr/access_control/api/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
(defn get-permissions
"Formats a response for retrieving permissions based on the given parameters. When concept_id is present,
only a chunk of the concept_id vector will be processed according to page_size and page_num."
[context params headers]
[context params]
(-> params
(select-keys [:page_size :page_num :concept_id])
util/map-keys->kebab-case
Expand Down Expand Up @@ -420,11 +420,11 @@

(GET "/"
{ctx :request-context headers :headers params :params}
(get-permissions ctx params headers))
(get-permissions ctx params))

(POST "/"
{ctx :request-context headers :headers params :params}
(get-permissions ctx params headers)))
(get-permissions ctx params)))

(context "/current-sids" []
(OPTIONS "/" [] (common-routes/options-response))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,23 @@
[_ params]
(when-let [concept-ids (seq (:concept-id params))]
(try
(let [page-size (or (pv/get-ivalue-from-params params :page-size) pv/max-page-size)
valid-upper-bound (-> concept-ids
count
(/ page-size)
Math/ceil
int)]
(when-let [page-num-i (pv/get-ivalue-from-params params :page-num)]
(when-let [page-num-i (pv/get-ivalue-from-params params :page-num)]
(let [page-size (or (pv/get-ivalue-from-params params :page-size) pv/max-page-size)
page-size (if (= 0 page-size)
pv/max-page-size
page-size)
valid-upper-bound (-> concept-ids
count
(/ page-size)
Math/ceil
int)]
(when (and (> valid-upper-bound 0)
(< valid-upper-bound page-num-i))
[(format "page_num must be a number less than or equal to %s" valid-upper-bound)])))
(catch java.lang.ArithmeticException e
nil)
(catch NumberFormatException e
nil))))
nil))))

(def ^:private get-permissions-validations
"Defines validations for get permissions parameters and values"
Expand All @@ -134,11 +139,10 @@
(defn validate-page-size-and-num
"Validates the page size and page number parameters in the given request parameters map."
[params]
(let [params (util/map-keys->kebab-case params)]
(when-let [errors (seq (mapcat #(% nil params) [pv/page-size-validation
pv/page-num-validation
page-num-upper-bound-validation]))]
(errors/throw-service-errors :bad-request errors))))
(when-let [errors (seq (mapcat #(% nil params) [pv/page-size-validation
pv/page-num-validation
page-num-upper-bound-validation]))]
(errors/throw-service-errors :bad-request errors)))

(defn validate-get-permission-params
"Throws service errors if any invalid params or values are found."
Expand Down

0 comments on commit 58154a3

Please sign in to comment.