Skip to content
Snippets Groups Projects
Commit 0a1a82f7 authored by Cam Saul's avatar Cam Saul
Browse files

GET emailreport handles filtering correctly

parent 2936217c
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@
[lein-ancient "0.6.5"] ; Check project for outdated dependencies + plugins w/ 'lein ancient'
[lein-bikeshed "0.2.0"] ; Linting
[lein-expectations "0.0.8"] ; run unit tests with 'lein expectations'
[lein-instant-cheatsheet "2.1.0"] ; use awesome instant cheatsheet created by yours truly w/ 'lein instant-cheatsheet'
[lein-instant-cheatsheet "2.1.1"] ; use awesome instant cheatsheet created by yours truly w/ 'lein instant-cheatsheet'
[lein-marginalia "0.8.0"]] ; generate documentation with 'lein marg'
:jvm-opts ["-Dlogfile.path=target/log"
"-Xms1024m" ; give JVM a decent heap size to start with
......
......@@ -34,20 +34,27 @@
:databases dbs
:users users}))
(defendpoint GET "/"
"Fetch `EmailReports` for ORG. With filter option F (default: `:all`):
(defendpoint GET "/" [org f]
;; TODO - filter by f == "mine"
;; TODO - filter by creator == self OR public_perms > 0
* `all` - return reports created by current user + any other publicly visible reports
* `mine` - return reports created by current user"
[org f]
{org Required, f FilterOptionAllOrMine}
(read-check Org org)
(-> (sel :many EmailReport
(where {:organization_id org})
(where {:public_perms [> common/perms-none]})
(order :name :ASC))
(hydrate :creator :organization :can_read :can_write :recipients)))
(defendpoint POST "/" [:as {{:keys [dataset_query description email_addresses mode name organization public_perms schedule] :as body} :body}]
(let [all? (= (or (keyword f) :all) :all)]
(-> (sel :many EmailReport
(where {:organization_id org})
(where (or {:creator_id *current-user-id*}
(when all?
{:public_perms [> common/perms-none]})))
(order :name :ASC))
(hydrate :creator :organization :can_read :can_write :recipients))))
(defendpoint POST "/"
"Create a new `EmailReport`."
[:as {{:keys [dataset_query description email_addresses mode name organization public_perms schedule] :as body} :body}]
{dataset_query Required
name Required
organization Required
......
......@@ -155,7 +155,8 @@
Returns true if update modified rows, false otherwise."
[entity entity-id & {:as kwargs}]
(let [obj (pre-update entity kwargs)
(let [obj (-> (pre-update entity (assoc kwargs :id entity-id))
(dissoc :id))
result (-> (update entity (set-fields obj) (where {:id entity-id}))
(> 0))]
(when result
......
......@@ -91,12 +91,14 @@
(assoc :dataset_query (json/write-str dataset_query)
:schedule (json/write-str schedule)))))
(defmethod pre-update EmailReport [_ {:keys [version dataset_query schedule] :as report}]
(assoc report
:updated_at (util/new-sql-timestamp)
:dataset_query (json/write-str dataset_query)
:schedule (json/write-str schedule)
:version (inc version)))
(defmethod pre-update EmailReport [_ {:keys [version dataset_query schedule id] :as report}]
(let [version (or version
(sel :one :field [EmailReport :version] :id id))]
(assoc report
:updated_at (util/new-sql-timestamp)
:dataset_query (json/write-str dataset_query)
:schedule (json/write-str schedule)
:version (inc version))))
(defmethod post-select EmailReport [_ {:keys [id creator_id organization_id] :as report}]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment