Skip to content

Commit 877b664

Browse files
authoredMay 23, 2018
Merge pull request #549 from CSCfi/filter-event-comments
Filter event comments
2 parents da6678b + 15fac4d commit 877b664

File tree

4 files changed

+72
-17
lines changed

4 files changed

+72
-17
lines changed
 

‎src/clj/rems/api/application.clj

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[rems.db.core :as db]
88
[rems.db.users :as users]
99
[rems.form :as form]
10+
[rems.util :refer [get-user-id]]
1011
[ring.util.http-response :refer :all]
1112
[schema.core :as s]))
1213

@@ -84,9 +85,24 @@
8485
(update-in [:items] longify-keys)
8586
(update-in [:licenses] longify-keys)))
8687

88+
(defn- hide-sensitive-comments [events]
89+
(map (fn [event]
90+
(if (contains? #{"third-party-review" "review-request"} (:event event))
91+
(assoc event :comment nil) ; remove sensitive comment
92+
event))
93+
events))
94+
95+
(defn hide-event-comments [application user]
96+
(let [events (get-in application [:application :events])
97+
can-see-comments? (contains? (set (applications/get-handlers application)) (get-user-id))]
98+
(if can-see-comments?
99+
application
100+
(update-in application [:application :events] hide-sensitive-comments))))
101+
87102
(defn api-get-application [application-id]
88103
(when (not (empty? (db/get-applications {:id application-id})))
89-
(applications/get-form-for application-id)))
104+
(-> (applications/get-form-for application-id)
105+
(hide-event-comments (get-user-id)))))
90106

91107
(def application-api
92108
(context "/application" []

‎src/clj/rems/db/applications.clj

+17-3
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,24 @@
120120
(and (= "applied" (:state application))
121121
(is-third-party-reviewer? (get-user-id) (:curround application) application)))
122122

123+
(defn get-approvers [application]
124+
(actors/get-by-role (:id application) "approver"))
125+
126+
(defn get-reviewers [application]
127+
(actors/get-by-role (:id application) "reviewer"))
128+
123129
(defn get-third-party-reviewers
124-
"Takes as an argument a structure containing application information and a workflow round. Then returns userids for all users that have been requested to review for the given round."
125-
[application round]
126-
(set (map :userid (get-events-of-type application round "review-request"))))
130+
"Takes as an argument a structure containing application information and a optionally the workflow round. Then returns userids for all users that have been requested to review for the given round or all rounds if not given."
131+
([application]
132+
(set (map :userid (get-events-of-type application "review-request"))))
133+
([application round]
134+
(set (map :userid (get-events-of-type application round "review-request")))))
135+
136+
(defn get-handlers [application]
137+
(let [approvers (get-approvers application)
138+
reviewers (get-reviewers application)
139+
third-party-reviewers (get-third-party-reviewers application)]
140+
(union approvers reviewers third-party-reviewers)))
127141

128142
(defn is-applicant? [application]
129143
(= (:applicantuserid application) (get-user-id)))

‎test/clj/rems/test/api/application.clj

+37-13
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,12 @@
336336

337337
(deftest application-api-third-party-review-test
338338
(let [api-key "42"
339-
user "developer"
340-
reviewer "alice"
339+
applicant "alice"
340+
approver "developer"
341+
reviewer "bob"
341342
catid 2
342343
app-id (-> (request :put (str "/api/application/save"))
343-
(authenticate api-key user)
344+
(authenticate api-key applicant)
344345
(json-body {:command "submit"
345346
:catalogue-items [catid]
346347
:items {1 "x" 2 "y" 3 "z"}
@@ -351,7 +352,7 @@
351352
(testing "send review request"
352353
(is (= 200
353354
(-> (request :put (str "/api/application/review_request"))
354-
(authenticate api-key user)
355+
(authenticate api-key approver)
355356
(json-body {:application-id app-id
356357
:round 0
357358
:comment "pls revu"
@@ -360,13 +361,13 @@
360361
:status))))
361362
(testing "check review event"
362363
(let [events (-> (request :get (str "/api/application/" app-id))
363-
(authenticate api-key user)
364+
(authenticate api-key reviewer)
364365
app
365366
read-body
366367
:application
367368
:events)]
368-
(is (= [{:userid "developer" :comment nil :event "apply"}
369-
{:userid "alice" :comment "pls revu" :event "review-request"}]
369+
(is (= [{:userid applicant :comment nil :event "apply"}
370+
{:userid reviewer :comment "pls revu" :event "review-request"}]
370371
(map #(select-keys % [:userid :comment :event]) events)))))
371372
(testing "send review"
372373
(is (= 200
@@ -378,17 +379,40 @@
378379
:comment "is ok"})
379380
app
380381
:status))))
381-
(testing "check events"
382+
(testing "events of approver"
382383
(let [events (-> (request :get (str "/api/application/" app-id))
383-
(authenticate api-key user)
384+
(authenticate api-key approver)
385+
app
386+
read-body
387+
:application
388+
:events)]
389+
(is (= [{:userid applicant :comment nil :event "apply"}
390+
{:userid reviewer :comment "pls revu" :event "review-request"}
391+
{:userid reviewer :comment "is ok" :event "third-party-review"}]
392+
(map #(select-keys % [:userid :comment :event]) events)))))
393+
(testing "events of reviewer"
394+
(let [events (-> (request :get (str "/api/application/" app-id))
395+
(authenticate api-key reviewer)
396+
app
397+
read-body
398+
:application
399+
:events)]
400+
(is (= [{:userid applicant :comment nil :event "apply"}
401+
{:userid reviewer :comment "pls revu" :event "review-request"}
402+
{:userid reviewer :comment "is ok" :event "third-party-review"}]
403+
(map #(select-keys % [:userid :comment :event]) events)))))
404+
(testing "events of applicant"
405+
(let [events (-> (request :get (str "/api/application/" app-id))
406+
(authenticate api-key applicant)
384407
app
385408
read-body
386409
:application
387410
:events)]
388-
(is (= [{:userid "developer" :comment nil :event "apply"}
389-
{:userid "alice" :comment "pls revu" :event "review-request"}
390-
{:userid "alice" :comment "is ok" :event "third-party-review"}]
391-
(map #(select-keys % [:userid :comment :event]) events)))))))
411+
(is (= [{:userid applicant :comment nil :event "apply"}
412+
{:userid reviewer :comment nil :event "review-request"}
413+
{:userid reviewer :comment nil :event "third-party-review"}]
414+
(map #(select-keys % [:userid :comment :event]) events))
415+
"does not see review event comments")))))
392416
;; TODO non-happy path tests for review?
393417

394418
;; TODO test for event filtering when it gets implemented

‎test/clj/rems/test/api/applications.clj

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
app
1919
read-body)]
2020
(is (= [1 2 3 4 5 6 7] (map :id (sort-by :id data)))))))
21+
2122
(deftest applications-api-security-test
2223
(testing "listing without authentication"
2324
(let [response (-> (request :get (str "/api/applications"))

0 commit comments

Comments
 (0)
Please sign in to comment.