1 (defn add-user [db-base-URL db-system-DIR]
3 ;; 1. check that there's not an existing user
5 (execute-http-call ;; TODO - put in 404 check
9 (working-dir-lookup (:tag (:previous @bkell/shell ))) ;; stringing together lookup URL leaf
12 (name (:tag (:previous @bkell/shell )))
14 (:id (:attrs (:previous @bkell/shell ))))
16 (str ;; repeating user name as leaf document
17 (name (:tag (:previous @bkell/shell )))
19 (:id (:attrs (:previous @bkell/shell )))))
21 {"Content-Type" "text/xml"}
26 (println "check-user[" check-user "]") ;; TODO - if <error/>, ADD user; user exists otherwise
28 (if (not (= (:msg check-user) "Error"))
30 (println "user ALREADY exists") ;; TODO - throw error to user
34 (println "ADDING user[" (:previous @bkell/shell ) "]")
36 ;; 2. add to aauth.groups and corresponding default group to the new user
37 (let [aauth-group (clojure.xml/parse "etc/xml/add.group.xml")]
39 (println "...loading add.group.xml[" aauth-group "]")
41 (name (:tag (:previous @bkell/shell )))
43 (:id (:attrs (:previous @bkell/shell ))))]
45 (let [db-group (assoc aauth-group
49 :owner (:id (:attrs (:previous @bkell/shell )))
53 :tag (keyword "user"),
55 :xmlns "com/interrupt/bookkeeping/users",
56 :id (:id (:attrs (:previous @bkell/shell )))
65 (println "CREATing group [" db-group "] / XML[" (with-out-str (clojure.xml/emit db-group)) "]" )
67 (str db-base-URL db-system-DIR (working-dir-lookup :group)
68 "/" "group." (:id (:attrs (:previous @bkell/shell )))
69 "/" "group." (:id (:attrs (:previous @bkell/shell ))))
71 { "Content-Type" "text/xml"
72 "Authorization" "Basic YWRtaW46"}
73 (with-out-str (clojure.xml/emit db-group))
78 ;; 3. add to aauth.users ... PUT to eXist
79 ;; 4. profile Details ... PUT to eXist ... TODO
80 (println "CREATing user [" (:previous @bkell/shell ) "] / XML[" (with-out-str (clojure.xml/emit (:previous @bkell/shell ))) "]" )
82 (str db-base-URL db-system-DIR (working-dir-lookup :user)
83 "/" "user." (:id (:attrs (:previous @bkell/shell )))
84 "/" "user." (:id (:attrs (:previous @bkell/shell ))))
86 { "Content-Type" "text/xml"
87 "Authorization" "Basic YWRtaW46"}
88 (with-out-str (clojure.xml/emit (:previous @bkell/shell )))
91 ;; 5. add associated Bookkeeping to Group ... PUT to eXist
93 (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping)
94 "/" "group." (:id (:attrs (:previous @bkell/shell )))
95 "/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping" )
97 { "Content-Type" "text/xml"
98 "Authorization" "Basic YWRtaW46"}
99 (slurp "etc/xml/default.bookkeeping.xml" )