Skip to content
Snippets Groups Projects
Unverified Commit 200d4d81 authored by adam-james's avatar adam-james Committed by GitHub
Browse files

Add :can_write to the :collection hydration for timelines (#21236)

parent 1061477b
Branches
Tags
No related merge requests found
......@@ -39,7 +39,7 @@
archived (s/maybe su/BooleanString)}
(let [archived? (Boolean/parseBoolean archived)
timelines (map timeline/hydrate-root-collection (db/select Timeline [:where [:= :archived archived?]]))]
(cond->> (hydrate timelines :creator :collection)
(cond->> (hydrate timelines :creator [:collection :can_write])
(= include "events")
(map #(timeline-event/include-events-singular % {:events/all? archived?})))))
......@@ -53,7 +53,7 @@
end (s/maybe su/TemporalString)}
(let [archived? (Boolean/parseBoolean archived)
timeline (api/read-check (Timeline id))]
(cond-> (hydrate timeline :creator :collection)
(cond-> (hydrate timeline :creator [:collection :can_write])
;; `collection_id` `nil` means we need to assoc 'root' collection
;; because hydrate `:collection` needs a proper `:id` to work.
(nil? (:collection_id timeline))
......
......@@ -44,7 +44,7 @@
:collection_id collection-id
:archived (boolean archived?))
:creator
:collection)
[:collection :can_write])
(nil? collection-id) (->> (map hydrate-root-collection))
events? (timeline-event/include-events options)))
......
......@@ -1285,6 +1285,10 @@
(->> (timelines-request card-a false)
(map #(get-in % [:collection :id]))
set))))
(testing "check that `:can_write` key is hydrated"
(is (every?
#(contains? % :can_write)
(map :collection (timelines-request card-a false)))))
(testing "Only un-archived timelines in the collection of the card are returned"
(is (= #{"Timeline B"}
(timeline-names (timelines-request card-b false)))))
......
......@@ -1486,6 +1486,10 @@
(->> (timelines-request coll-a false)
(map #(get-in % [:collection :id]))
set))))
(testing "check that `:can_write` key is hydrated"
(is (every?
#(contains? % :can_write)
(map :collection (timelines-request coll-a false)))))
(testing "Only un-archived timelines in the collection of the card are returned"
(is (= #{"Timeline B"}
(timeline-names (timelines-request coll-b false)))))
......
......@@ -20,15 +20,14 @@
(deftest list-timelines-test
(testing "GET /api/timeline"
(mt/with-temp Collection [collection {:name "Important Data"}]
(let [id (u/the-id collection)
events-of (fn [tls]
(into #{} (comp (filter (comp #{id} :collection_id))
(map :name))
tls))]
(let [id (u/the-id collection)
events-of (fn [tls]
(into #{} (comp (filter (comp #{id} :collection_id))
(map :name))
tls))]
(mt/with-temp* [Timeline [tl-a {:name "Timeline A", :collection_id id}]
Timeline [tl-b {:name "Timeline B", :collection_id id}]
Timeline [tl-c {:name "Timeline C", :collection_id id
:archived true}]]
Timeline [tl-c {:name "Timeline C", :collection_id id :archived true}]]
(testing "check that we only get un-archived timelines"
(is (= #{"Timeline A" "Timeline B"}
(events-of (mt/user-http-request :rasta :get 200 "timeline")))))
......@@ -40,7 +39,13 @@
(->> (mt/user-http-request :rasta :get 200 "timeline")
(filter (comp #{id} :collection_id))
(map #(get-in % [:collection :id]))
set)))))))))
set))))
(testing "check that `:can_write` key is hydrated"
(is (every?
#(contains? % :can_write)
(->> (mt/user-http-request :rasta :get 200 "timeline")
(filter (comp #{id} :collection_id))
:collection)))))))))
(deftest get-timeline-test
(testing "GET /api/timeline/:id"
......@@ -54,6 +59,11 @@
(is (= "root"
(-> (mt/user-http-request :rasta :get 200 (str "timeline/" (u/the-id tl-a)))
(get-in [:collection :id])))))
(testing "check that `:can_write` key is hydrated"
(is (contains?
(->> (mt/user-http-request :rasta :get 200 (str "timeline/" (u/the-id tl-a)))
:collection)
:can_write)))
(testing "check that we get the timeline with the id specified, even if the timeline is archived"
(is (= "Timeline B"
(->> (mt/user-http-request :rasta :get 200 (str "timeline/" (u/the-id tl-b)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment