Repository: CSCfi/rems
Pull request #1124 (2019-04-15 13:23:05)

Small fixes
Small fixes to issues found after testing the latest version or based on discussions.


Patch:
diff --git a/src/clj/rems/application/model.clj b/src/clj/rems/application/model.clj
index e4df42158..fc697ac99 100644
--- a/src/clj/rems/application/model.clj
+++ b/src/clj/rems/application/model.clj
@@ -196,7 +196,6 @@
 (defmethod event-type-specific-application-view :application.event/licenses-accepted
   [application event]
   (-> application
-      (assoc :application/modified (:event/time event))
       (assoc-in [:application/accepted-licenses (:event/actor event)] (:application/accepted-licenses event))))
 
 (defmethod event-type-specific-application-view :application.event/licenses-added
@@ -207,8 +206,8 @@
               (fn [licenses]
                 (-> licenses
                     (into (:application/licenses event))
-                     distinct
-                     vec)))))
+                    distinct
+                    vec)))))
 
 (defmethod event-type-specific-application-view :application.event/member-invited
   [application event]
diff --git a/src/cljs/rems/actions/accept_invitation.cljs b/src/cljs/rems/actions/accept_invitation.cljs
index bd2bccb99..6f1e5184d 100644
--- a/src/cljs/rems/actions/accept_invitation.cljs
+++ b/src/cljs/rems/actions/accept_invitation.cljs
@@ -10,7 +10,7 @@
  (fn [{:keys [db]} [_ token]]
    (status-modal/common-pending-handler! (text :t.actions/accept-invitation))
    {:db (assoc db ::token token)
-    ::accept-invitation [(get-in db [:identity :user]) token]}))
+    ::accept-invitation token}))
 
 (rf/reg-sub ::token (fn [db] (::token db "")))
 
@@ -41,12 +41,11 @@
 
 (rf/reg-fx
  ::accept-invitation
- (fn [[user token]]
+ (fn [token]
    (post! "/api/applications/accept-invitation"
           {:url-params {:invitation-token token}
            :handler success-handler
-           :error-handler error-handler
-           :headers {"x-rems-user-id" (:eppn user)}})))
+           :error-handler error-handler})))
 
 (defn accept-invitation-page []
   (let [token @(rf/subscribe [::token])]
diff --git a/src/cljs/rems/actions/add_licenses.cljs b/src/cljs/rems/actions/add_licenses.cljs
index 164b74ad4..1682ff134 100644
--- a/src/cljs/rems/actions/add_licenses.cljs
+++ b/src/cljs/rems/actions/add_licenses.cljs
@@ -9,10 +9,8 @@
 
 (rf/reg-fx
  ::fetch-licenses
- (fn [[user on-success]]
-   (fetch "/api/licenses"
-          {:handler on-success
-           :headers {"x-rems-user-id" (:eppn user)}})))
+ (fn [on-success]
+   (fetch "/api/licenses" {:handler on-success})))
 
 (rf/reg-event-fx
  ::open-form
@@ -22,14 +20,13 @@
                ::comment ""
                ::potential-licenses #{}
                ::selected-licenses #{})
-    ::fetch-licenses [(get-in db [:identity :user])
-                      #(rf/dispatch [::set-potential-licenses %])]}))
+    ::fetch-licenses #(rf/dispatch [::set-potential-licenses %])}))
 
 (defn- assoc-all-titles
   "Prepopulate `:all-titles` property to facilitate searching with localized names and unlocalized title"
   [license]
   (assoc license :all-titles (str/join "" (conj (mapcat :title (vals (:localizations license)))
-                                                 (:title license)))))
+                                                (:title license)))))
 
 (rf/reg-sub ::potential-licenses (fn [db _] (::potential-licenses db)))
 (rf/reg-event-db
diff --git a/src/cljs/rems/actions/add_member.cljs b/src/cljs/rems/actions/add_member.cljs
index ac9ada1a1..3ee1a369d 100644
--- a/src/cljs/rems/actions/add_member.cljs
+++ b/src/cljs/rems/actions/add_member.cljs
@@ -11,10 +11,8 @@
 
 (rf/reg-fx
  ::fetch-potential-members
- (fn [[user on-success]]
-   (fetch "/api/applications/members"
-          {:handler on-success
-           :headers {"x-rems-user-id" (:eppn user)}})))
+ (fn [on-success]
+   (fetch "/api/applications/members" {:handler on-success})))
 
 (rf/reg-event-fx
  ::open-form
@@ -22,8 +20,7 @@
    {:db (assoc db
                ::potential-members #{}
                ::selected-member nil)
-    ::fetch-potential-members [(get-in db [:identity :user])
-                               #(rf/dispatch [::set-potential-members %])]}))
+    ::fetch-potential-members #(rf/dispatch [::set-potential-members %])}))
 
 (rf/reg-sub ::potential-members (fn [db _] (::potential-members db)))
 (rf/reg-event-db
diff --git a/src/cljs/rems/actions/request_comment.cljs b/src/cljs/rems/actions/request_comment.cljs
index 4dd519669..2d9372413 100644
--- a/src/cljs/rems/actions/request_comment.cljs
+++ b/src/cljs/rems/actions/request_comment.cljs
@@ -9,10 +9,8 @@
 
 (rf/reg-fx
  ::fetch-potential-commenters
- (fn [[user on-success]]
-   (fetch "/api/applications/commenters"
-          {:handler on-success
-           :headers {"x-rems-user-id" (:eppn user)}})))
+ (fn [on-success]
+   (fetch "/api/applications/commenters" {:handler on-success})))
 
 (rf/reg-event-fx
  ::open-form
@@ -22,8 +20,7 @@
                ::comment ""
                ::potential-commenters #{}
                ::selected-commenters #{})
-    ::fetch-potential-commenters [(get-in db [:identity :user])
-                                  #(rf/dispatch [::set-potential-commenters %])]}))
+    ::fetch-potential-commenters #(rf/dispatch [::set-potential-commenters %])}))
 
 (rf/reg-sub ::potential-commenters (fn [db _] (::potential-commenters db)))
 (rf/reg-event-db
diff --git a/src/cljs/rems/actions/request_decision.cljs b/src/cljs/rems/actions/request_decision.cljs
index 3c8f46f7f..5fa45ee46 100644
--- a/src/cljs/rems/actions/request_decision.cljs
+++ b/src/cljs/rems/actions/request_decision.cljs
@@ -9,10 +9,8 @@
 
 (rf/reg-fx
  ::fetch-potential-deciders
- (fn [[user on-success]]
-   (fetch "/api/applications/deciders"
-          {:handler on-success
-           :headers {"x-rems-user-id" (:eppn user)}})))
+ (fn [on-success]
+   (fetch "/api/applications/deciders" {:handler on-success})))
 
 (rf/reg-event-fx
  ::open-form
@@ -21,8 +19,7 @@
                ::comment ""
                ::potential-deciders #{}
                ::selected-deciders #{})
-    ::fetch-potential-deciders [(get-in db [:identity :user])
-                                #(rf/dispatch [::set-potential-deciders %])]}))
+    ::fetch-potential-deciders #(rf/dispatch [::set-potential-deciders %])}))
 
 (rf/reg-sub ::potential-deciders (fn [db _] (::potential-deciders db)))
 (rf/reg-event-db


Test patch:
diff --git a/test/clj/rems/application/test_model.clj b/test/clj/rems/application/test_model.clj
index d2a00b042..d0008c5e3 100644
--- a/test/clj/rems/application/test_model.clj
+++ b/test/clj/rems/application/test_model.clj
@@ -295,8 +295,7 @@
                                          :application/id 1
                                          :application/accepted-licenses #{30 31 32}})
                     expected-application (deep-merge expected-application
-                                                     {:application/modified (DateTime. 2500)
-                                                      :application/last-activity (DateTime. 2500)
+                                                     {:application/last-activity (DateTime. 2500)
                                                       :application/events events
                                                       :application/accepted-licenses {"applicant" #{30 31 32}}})]
                 (is (= expected-application (apply-events events)))
@@ -395,21 +394,21 @@
                                                          :application/modified (DateTime. 3500)
                                                          :application/events events
                                                          :application/licenses (conj (:application/licenses expected-application)
-                                                                                {:license/id 33
-                                                                                 :license/type :attachment
-                                                                                 :license/title {:en "en title"
-                                                                                                 :fi "fi title"
-                                                                                                 :default "non-localized title"}
-                                                                                 :license/attachment-id {:en 3301
-                                                                                                         :fi 3302
-                                                                                                         :default 3300}
-                                                                                 :license/attachment-filename {:en "en filename"
-                                                                                                               :fi "fi filename"
-                                                                                                               :default "non-localized filename"}
-                                                                                 :license/start (DateTime. 100)
-                                                                                 :license/end nil
-                                                                                 :license/expired false
-                                                                                 :license/enabled true
+                                                                                     {:license/id 33
+                                                                                      :license/type :attachment
+                                                                                      :license/title {:en "en title"
+                                                                                                      :fi "fi title"
+                                                                                                      :default "non-localized title"}
+                                                                                      :license/attachment-id {:en 3301
+                                                                                                              :fi 3302
+                                                                                                              :default 3300}
+                                                                                      :license/attachment-filename {:en "en filename"
+                                                                                                                    :fi "fi filename"
+                                                                                                                    :default "non-localized filename"}
+                                                                                      :license/start (DateTime. 100)
+                                                                                      :license/end nil
+                                                                                      :license/expired false
+                                                                                      :license/enabled true
                                                                                       :license/archived false})})]
                         (is (= expected-application (apply-events events)))
 
@@ -434,8 +433,7 @@
                                                   :application/id 1
                                                   :application/accepted-licenses #{30 31 32 33}})
                                     expected-application (merge expected-application
-                                                                {:application/modified (DateTime. 4500)
-                                                                 :application/last-activity (DateTime. 4500)
+                                                                {:application/last-activity (DateTime. 4500)
                                                                  :application/events events
                                                                  :application/accepted-licenses {"applicant" #{30 31 32 33}}})]
                                 (is (= expected-application (apply-events events)))
@@ -443,25 +441,24 @@
                                 (testing "> member added"
                                   (let [events (conj events
                                                      {:event/type :application.event/member-added
-                                                      :event/time (DateTime. 4000)
+                                                      :event/time (DateTime. 4600)
                                                       :event/actor "handler"
                                                       :application/id 1
                                                       :application/member {:userid "member"}})
                                         expected-application (merge expected-application
-                                                                    {:application/last-activity (DateTime. 4000)
+                                                                    {:application/last-activity (DateTime. 4600)
                                                                      :application/events events
                                                                      :application/members #{{:userid "member"}}})]
                                     (is (= expected-application (apply-events events)))
                                     (testing "> licenses accepted for new member"
                                       (let [events (conj events
                                                          {:event/type :application.event/licenses-accepted
-                                                          :event/time (DateTime. 4500)
+                                                          :event/time (DateTime. 4700)
                                                           :event/actor "member"
                                                           :application/id 1
                                                           :application/accepted-licenses #{30 33}})
                                             expected-application (merge expected-application
-                                                                        {:application/modified (DateTime. 4500)
-                                                                         :application/last-activity (DateTime. 4500)
+                                                                        {:application/last-activity (DateTime. 4700)
                                                                          :application/events events
                                                                          :application/accepted-licenses {"applicant" #{30 31 32 33}
                                                                                                          "member" #{30 33}}})]
@@ -469,13 +466,12 @@
                                         (testing "> licenses accepted overwrites previous"
                                           (let [events (conj events
                                                              {:event/type :application.event/licenses-accepted
-                                                              :event/time (DateTime. 4500)
+                                                              :event/time (DateTime. 4800)
                                                               :event/actor "member"
                                                               :application/id 1
                                                               :application/accepted-licenses #{31 32}})
                                                 expected-application (merge expected-application
-                                                                            {:application/modified (DateTime. 4500)
-                                                                             :application/last-activity (DateTime. 4500)
+                                                                            {:application/last-activity (DateTime. 4800)
                                                                              :application/events events
                                                                              :application/accepted-licenses {"applicant" #{30 31 32 33}
                                                                                                              "member" #{31 32}}})]