Skip to content

Commit

Permalink
Added the /paths-contain-space endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnworth committed Mar 25, 2013
1 parent 7a94c64 commit 1a5d98c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/paths-contain-space.md
@@ -0,0 +1,36 @@
Checking For Spaces in Paths and/or Directories
-----------------------------------------------

__URL Path__: /paths-contain-space

__HTTP Method__: POST

__Action__: "paths-contain-space"

__Error codes__: ERR_BAD_OR_MISSING_FIELD

__Request Body__:

{
"paths" : [
"/this/is/a/path/",
"/this/is another/path"
]
}

"paths" can actually contain any string. File or directory existence is not checked. iRODS is never hit during the execution of this endpoint.

__Response__:

{
"action" : "paths-contain-space",
"status" : "success",
"paths" : {
"\/this\/is\/a\/path\/" : false,
"\/this\/is another\/path" : true,
}
}

__Curl Command__:

curl -H "Content-Type:application/json" -d '{"paths":["/this/is/a/path/","/this/is another/path"]}' http://127.0.0.1:3000/paths-contain-space
13 changes: 13 additions & 0 deletions src/nibblonian/controllers.clj
Expand Up @@ -684,3 +684,16 @@
(let [user (query-param request "user")
paths (:paths (:body request))]
(irods-actions/list-tickets-for-paths user paths)))

(defn do-paths-contain-space
[request]
(log/debug "do-path-contain-space")

(when-not (valid-body? request {:paths sequential?})
(bad-body request {:paths sequential?}))

(when-not (every? true? (mapv string? (:paths (:body request))))
(throw+ {:error_code ERR_BAD_OR_MISSING_FIELD :field "paths"}))

(let [paths (:paths (:body request))]
{:paths (irods-actions/paths-contain-char paths " ")}))
3 changes: 3 additions & 0 deletions src/nibblonian/core.clj
Expand Up @@ -126,6 +126,9 @@
(GET "/user-trash-dir" request
(trap "user-trash-dir" do-user-trash request))

(POST "/paths-contain-space" request
(trap "paths-contain-space" do-paths-contain-space request))

(DELETE "/trash" request
(trap "delete-trash" do-delete-trash request))

Expand Down
8 changes: 8 additions & 0 deletions src/nibblonian/irods_actions.clj
Expand Up @@ -955,3 +955,11 @@

{:tickets
(apply merge (mapv #(hash-map %1 (ticket-ids-for-path cm user %1)) paths))}))

(defn paths-contain-char
[paths char]
(when-not (good-string? char)
(throw+ {:error_code ERR_BAD_OR_MISSING_FIELD
:character char}))

(apply merge (map #(hash-map %1 (not (nil? (re-seq (re-pattern char) %1)))) paths)))

0 comments on commit 1a5d98c

Please sign in to comment.