Skip to content

Commit

Permalink
Merge pull request #3205 from CSCfi/3204/no-spam
Browse files Browse the repository at this point in the history
Limit repeated action clicking
  • Loading branch information
aatkin authored Oct 31, 2023
2 parents e6a2634 + 8666dfc commit bbadb16
Show file tree
Hide file tree
Showing 29 changed files with 300 additions and 219 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Changes since v2.33
- The tables take advantage of a new paging feature. Especially, the handler Actions page and its handled applications table uses paging and only fetches handled applications when so requested. The first 50 rows are only fetched by default. Paging can be also configured per table, if the default is not good (page size 50 rows). (#3191)
- If reminder email is configured for the, expirer bot, it will delete an old draft application if and only if the reminder email is sent and the specified amount of time has passed. Previously it would just delete if the application was very old (esp. when enabling expiry for the first time).
- Allow leaving `:form` field away from catalogue item creation API calls. Previously the value was optional but now the key too.
- Application action buttons now wait until request has completed. This should prevent duplicate concurrent requests caused by repeated clicking. (#3204)

### Additions
- (Experimental) Workflow can be configured to enable voting for the approval. Currently all handlers can vote (including bots). Use `:enable-voting`. (#3174)
Expand Down
14 changes: 7 additions & 7 deletions src/cljs/rems/actions/accept_licenses.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.accept-licenses
(:require [re-frame.core :as rf]
[rems.actions.components :refer [button-wrapper]]
[rems.actions.components :refer [perform-action-button]]
[rems.flash-message :as flash-message]
[rems.text :refer [text]]
[rems.util :refer [post!]]))
Expand All @@ -18,9 +18,9 @@
{}))

(defn accept-licenses-action-button [application-id licenses on-finished]
[button-wrapper {:id "accept-licenses-button"
:text (text :t.actions/accept-licenses)
:class "btn-primary"
:on-click #(rf/dispatch [::send-accept-licenses {:application-id application-id
:licenses licenses
:on-finished on-finished}])}])
[perform-action-button {:id "accept-licenses-button"
:text (text :t.actions/accept-licenses)
:class "btn-primary"
:on-click #(rf/dispatch [::send-accept-licenses {:application-id application-id
:licenses licenses
:on-finished on-finished}])}])
10 changes: 5 additions & 5 deletions src/cljs/rems/actions/add_licenses.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns rems.actions.add-licenses
(:require [clojure.string :as str]
[re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view comment-field button-wrapper collapse-action-form]]
[rems.actions.components :refer [action-button action-form-view comment-field collapse-action-form perform-action-button]]
[rems.dropdown :as dropdown]
[rems.flash-message :as flash-message]
[rems.text :refer [text get-localized-title]]
Expand Down Expand Up @@ -74,10 +74,10 @@
[{:keys [selected-licenses potential-licenses language on-set-licenses on-send]}]
[action-form-view action-form-id
(text :t.actions/add-licenses)
[[button-wrapper {:id "add-licenses"
:text (text :t.actions/add-licenses)
:class "btn-primary"
:on-click on-send}]]
[[perform-action-button {:id "add-licenses"
:text (text :t.actions/add-licenses)
:class "btn-primary"
:on-click on-send}]]
[:div
[comment-field {:field-key action-form-id
:label (text :t.form/add-comments-shown-to-applicant)}]
Expand Down
12 changes: 5 additions & 7 deletions src/cljs/rems/actions/add_member.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(ns rems.actions.add-member
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view button-wrapper collapse-action-form]]
[rems.actions.components :refer [action-button action-form-view collapse-action-form perform-action-button]]
[rems.atoms :as atoms]
[rems.dropdown :as dropdown]
[rems.flash-message :as flash-message]
[rems.text :refer [text]]
[rems.util :refer [fetch post!]]))



(rf/reg-fx
::fetch-potential-members
(fn [on-success]
Expand Down Expand Up @@ -63,10 +61,10 @@
[{:keys [selected-member potential-members on-set-member on-send]}]
[action-form-view action-form-id
(text :t.actions/add-member)
[[button-wrapper {:id "add-member-submit"
:text (text :t.actions/add-member)
:class "btn-primary"
:on-click on-send}]]
[[perform-action-button {:id "add-member-submit"
:text (text :t.actions/add-member)
:class "btn-primary"
:on-click on-send}]]
[:div
[:div.form-group
[:label {:for dropdown-id} (text :t.actions/member)]
Expand Down
24 changes: 12 additions & 12 deletions src/cljs/rems/actions/approve_reject.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[cljs-time.core :as time]
[cljs-time.format :as time-format]
[re-frame.core :as rf]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view button-wrapper command!]]
[rems.atoms :refer [close-symbol]]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view command! perform-action-button]]
[rems.atoms :as atoms]
[rems.text :refer [text localize-utc-date]]))

(def ^:private action-form-id "approve-reject")
Expand Down Expand Up @@ -64,14 +64,14 @@
[{:keys [application-id end on-set-entitlement-end on-approve on-reject]}]
[action-form-view action-form-id
(text :t.actions/approve-reject)
[[button-wrapper {:id "reject"
:text (text :t.actions/reject)
:class "btn-danger"
:on-click on-reject}]
[button-wrapper {:id "approve"
:text (text :t.actions/approve)
:class "btn-success"
:on-click on-approve}]]
[[perform-action-button {:id "reject"
:text (text :t.actions/reject)
:class "btn-danger"
:on-click on-reject}]
[perform-action-button {:id "approve"
:text (text :t.actions/approve)
:class "btn-success"
:on-click on-approve}]]
[:<>
[comment-field {:field-key action-form-id
:label (text :t.form/add-comments-shown-to-applicant)}]
Expand All @@ -94,7 +94,7 @@
[:button.btn.btn-outline-secondary
{:on-click #(on-set-entitlement-end nil)
:aria-label (text :t.actions/clear)}
[close-symbol]]])]]]])
[atoms/close-symbol]]])]]]])

(defn approve-reject-form [application-id on-finished]
(let [comment @(rf/subscribe [:rems.actions.components/comment action-form-id])
Expand All @@ -111,4 +111,4 @@
:on-reject #(rf/dispatch [::send-reject {:application-id application-id
:comment comment
:attachments attachments
:on-finished on-finished}])}]))
:on-finished on-finished}])}]))
10 changes: 5 additions & 5 deletions src/cljs/rems/actions/assign_external_id.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns rems.actions.assign-external-id
(:require [clojure.string :as str]
[re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view button-wrapper command!]]
[rems.actions.components :refer [action-button action-form-view command! perform-action-button]]
[rems.text :refer [text]]))

(rf/reg-event-fx
Expand Down Expand Up @@ -34,10 +34,10 @@
[{:keys [external-id on-set-external-id on-send]}]
[action-form-view action-form-id
(text :t.actions/assign-external-id)
[[button-wrapper {:id "assign-external-id-button"
:text (text :t.actions/assign-external-id)
:class "btn-primary"
:on-click on-send}]]
[[perform-action-button {:id "assign-external-id-button"
:text (text :t.actions/assign-external-id)
:class "btn-primary"
:on-click on-send}]]
(let [id (str action-form-id "-field")]
[:div.form-group
[:label {:for id}
Expand Down
10 changes: 5 additions & 5 deletions src/cljs/rems/actions/change_applicant.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.change-applicant
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view comment-field button-wrapper collapse-action-form]]
[rems.actions.components :refer [action-button action-form-view comment-field collapse-action-form perform-action-button]]
[rems.flash-message :as flash-message]
[rems.text :refer [text]]
[rems.util :refer [post!]]))
Expand Down Expand Up @@ -43,10 +43,10 @@
(let [element-id (qualify-parent-id parent-id)]
[action-form-view element-id
(text :t.actions/change-applicant)
[[button-wrapper {:id (str element-id "-submit")
:text (text :t.actions/change-applicant)
:class "btn-primary"
:on-click on-send}]]
[[perform-action-button {:id (str element-id "-submit")
:text (text :t.actions/change-applicant)
:class "btn-primary"
:on-click on-send}]]
[comment-field {:field-key (str element-id "-comment")
:label (text :t.form/add-comments-shown-to-applicant)}]
{:collapse-id parent-id}]))
Expand Down
14 changes: 7 additions & 7 deletions src/cljs/rems/actions/change_resources.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.change-resources
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view comment-field button-wrapper collapse-action-form]]
[rems.actions.components :refer [action-button action-form-view comment-field collapse-action-form perform-action-button]]
[rems.dropdown :as dropdown]
[rems.flash-message :as flash-message]
[medley.core :refer [distinct-by]]
Expand Down Expand Up @@ -83,12 +83,12 @@
config @(rf/subscribe [:rems.config/config])]
[action-form-view action-form-id
(text :t.actions/change-resources)
[[button-wrapper {:id "change-resources"
:text (text :t.actions/change-resources)
:class "btn-primary"
:disabled (or (empty? selected-resources)
(= selected-resources initial-resources))
:on-click on-send}]]
[[perform-action-button {:id "change-resources"
:text (text :t.actions/change-resources)
:class "btn-primary"
:disabled (or (empty? selected-resources)
(= selected-resources initial-resources))
:on-click on-send}]]
(if (empty? catalogue)
[spinner/big]
;; TODO: Nowadays the user cannot select resources that have an
Expand Down
10 changes: 5 additions & 5 deletions src/cljs/rems/actions/close.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.close
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view button-wrapper command!]]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view command! perform-action-button]]
[rems.text :refer [text]]))

(def ^:private action-form-id "close")
Expand Down Expand Up @@ -32,10 +32,10 @@
[{:keys [application-id show-comment-field? on-send]}]
[action-form-view action-form-id
(text :t.actions/close)
[[button-wrapper {:id "close"
:text (text :t.actions/close)
:class "btn-danger"
:on-click on-send}]]
[[perform-action-button {:id "close"
:text (text :t.actions/close)
:class "btn-danger"
:on-click on-send}]]
[:div
(text :t.actions/close-intro)
(when show-comment-field?
Expand Down
18 changes: 9 additions & 9 deletions src/cljs/rems/actions/components.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.components
(:require [re-frame.core :as rf]
[rems.atoms :refer [attachment-link checkbox enrich-user textarea]]
[rems.atoms :as atoms :refer [attachment-link checkbox enrich-user textarea]]
[rems.common.attachment-util :as attachment-util]
[rems.dropdown :as dropdown]
[rems.fetcher :as fetcher]
Expand All @@ -15,13 +15,6 @@
(defn- action-button-id [action-id]
(str action-id "-action-button"))

(defn button-wrapper [{:keys [text class] :as props}]
[:button.btn
(merge {:type :button
:class (or class :btn-secondary)}
(dissoc props :class :text))
text])

(defn collapse-action-form [id]
(.collapse (js/$ (str "#" (action-collapse-id id))) "hide"))

Expand Down Expand Up @@ -232,7 +225,8 @@
(assert (qualified-keyword? command)
(pr-str command))
(post! (str "/api/applications/" (name command))
{:params params
{:request-id command
:params params
:handler (flash-message/default-success-handler
:actions
description
Expand All @@ -241,5 +235,11 @@
(on-finished)))
:error-handler (flash-message/default-error-handler :actions description)}))

(defn perform-action-button [{:keys [loading?] :as props}]
[atoms/rate-limited-button
(-> props
(dissoc (when (or loading? @(rf/subscribe [:rems.spa/any-pending-request?]))
:on-click)))])

(defn guide []
[:div])
18 changes: 9 additions & 9 deletions src/cljs/rems/actions/decide.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.decide
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view button-wrapper command!]]
[rems.actions.components :refer [action-attachment action-button comment-field action-form-view command! perform-action-button]]
[rems.text :refer [text]]))

(def ^:private action-form-id "decide")
Expand Down Expand Up @@ -34,14 +34,14 @@
[{:keys [application-id on-send]}]
[action-form-view action-form-id
(text :t.actions/decide)
[[button-wrapper {:id "decide-reject"
:text (text :t.actions/reject)
:class "btn-danger"
:on-click #(on-send :rejected)}]
[button-wrapper {:id "decide-approve"
:text (text :t.actions/approve)
:class "btn-success"
:on-click #(on-send :approved)}]]
[[perform-action-button {:id "decide-reject"
:text (text :t.actions/reject)
:class "btn-danger"
:on-click #(on-send :rejected)}]
[perform-action-button {:id "decide-approve"
:text (text :t.actions/approve)
:class "btn-success"
:on-click #(on-send :approved)}]]
[:<>
[comment-field {:field-key action-form-id
:label (text :t.form/add-comments-not-shown-to-applicant)}]
Expand Down
12 changes: 6 additions & 6 deletions src/cljs/rems/actions/delete.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rems.actions.delete
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-button action-form-view button-wrapper command!]]
[rems.actions.components :refer [action-button action-form-view command! perform-action-button]]
[rems.text :refer [text]]))

(def ^:private action-form-id "delete")
Expand All @@ -22,10 +22,10 @@
(defn delete-form [application-id on-finished]
[action-form-view action-form-id
(text :t.actions/delete)
[[button-wrapper {:id "delete"
:text (text :t.actions/delete)
:class "btn-danger"
:on-click #(rf/dispatch [::send-delete {:application-id application-id
:on-finished on-finished}])}]]
[[perform-action-button {:id "delete"
:text (text :t.actions/delete)
:class "btn-danger"
:on-click #(rf/dispatch [::send-delete {:application-id application-id
:on-finished on-finished}])}]]
[:div
(text :t.actions/delete-intro)]])
24 changes: 11 additions & 13 deletions src/cljs/rems/actions/invite_decider_reviewer.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(ns rems.actions.invite-decider-reviewer
(:require [re-frame.core :as rf]
[rems.actions.components :refer [action-attachment action-link action-form-view button-wrapper command!
comment-field email-field name-field]]
[rems.actions.components :refer [action-attachment action-link action-form-view command! comment-field email-field name-field perform-action-button]]
[rems.flash-message :as flash-message]
[rems.text :refer [text]]))


(rf/reg-event-fx
::open-form
(fn [{:keys [db]} [_ field-key]]
Expand Down Expand Up @@ -71,11 +69,11 @@
[action-form-view
decider-form-id
(text :t.actions/request-decision-via-email)
[[button-wrapper {:id "invite-decider"
:text (text :t.actions/request-decision)
:class "btn-primary"
:on-click on-send
:disabled disabled}]]
[[perform-action-button {:id "invite-decider"
:text (text :t.actions/request-decision)
:class "btn-primary"
:on-click on-send
:disabled disabled}]]
[:<>
[name-field {:field-key decider-form-id}]
[email-field {:field-key decider-form-id}]
Expand All @@ -89,11 +87,11 @@
[action-form-view
reviewer-form-id
(text :t.actions/request-review-via-email)
[[button-wrapper {:id "invite-reviewer"
:text (text :t.actions/request-review)
:class "btn-primary"
:on-click on-send
:disabled disabled}]]
[[perform-action-button {:id "invite-reviewer"
:text (text :t.actions/request-review)
:class "btn-primary"
:on-click on-send
:disabled disabled}]]
[:<>
[name-field {:field-key reviewer-form-id}]
[email-field {:field-key reviewer-form-id}]
Expand Down
Loading

0 comments on commit bbadb16

Please sign in to comment.