Revert "Revert "Enabling signature editing.""
This reverts commit b52f3231e8.
This commit is contained in:
@@ -67,6 +67,7 @@
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:code {:type 'String}
|
||||
:signature_file {:type 'String}
|
||||
:week_a_debits {:type :money}
|
||||
:week_a_credits {:type :money}
|
||||
:week_b_debits {:type :money}
|
||||
@@ -651,6 +652,7 @@
|
||||
:edit_client {:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:code {:type 'String}
|
||||
:signature_data {:type 'String}
|
||||
:email {:type 'String}
|
||||
:week_a_credits {:type :money}
|
||||
:week_a_debits {:type :money}
|
||||
|
||||
@@ -3,9 +3,14 @@
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client?]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[config.core :refer [env]]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]))
|
||||
[datomic.api :as d]
|
||||
[clojure.java.io :as io]
|
||||
[amazonica.aws.s3 :as s3])
|
||||
(:import [org.apache.commons.codec.binary Base64]
|
||||
java.util.UUID))
|
||||
|
||||
(defn assert-client-code-is-unique [code]
|
||||
(when (seq (d/query {:query {:find '[?id]
|
||||
@@ -14,6 +19,21 @@
|
||||
:args [(d/db conn) code]}))
|
||||
(throw (ex-info "Client is not unique" {:validation-error (str "Client code '" code "' is not unique.")}))))
|
||||
|
||||
(defn upload-signature-data [signature-data]
|
||||
(let [prefix "data:image/jpeg;base64,"]
|
||||
(when signature-data
|
||||
(when-not (str/starts-with? signature-data prefix)
|
||||
(throw (ex-info "Invalid signature image" {:validation-error (str "Invalid signature image.")})))
|
||||
(let [signature-id (str (UUID/randomUUID))
|
||||
raw-bytes (Base64/decodeBase64 (subs signature-data (count prefix)))]
|
||||
(s3/put-object :bucket-name "integreat-signature-images" #_(:data-bucket env)
|
||||
:key (str signature-id ".jpg")
|
||||
:input-stream (io/make-input-stream raw-bytes {})
|
||||
:metadata {:content-type "image/jpeg"}
|
||||
:canned-acl "public-read")
|
||||
(str "https://integreat-signature-images.s3.amazonaws.com/" signature-id ".jpg")
|
||||
))))
|
||||
|
||||
(defn edit-client [context {:keys [edit_client new_bank_accounts] :as args} value]
|
||||
(assert-admin (:id context))
|
||||
(when-not (:id edit_client)
|
||||
@@ -21,6 +41,7 @@
|
||||
|
||||
(let [client (when (:id edit_client) (d-clients/get-by-id (:id edit_client)))
|
||||
id (or (:db/id client) "new-client")
|
||||
signature-file (upload-signature-data (:signature_data edit_client))
|
||||
_ (when client
|
||||
(audit-transact (into
|
||||
(mapv (fn [lm] [:db/retractEntity (:db/id lm)]) (:client/location-matches client))
|
||||
@@ -36,6 +57,7 @@
|
||||
(:client/code client))
|
||||
:client/name (:name edit_client)
|
||||
:client/matches (:matches edit_client)
|
||||
:client/signature-file signature-file
|
||||
:client/email (:email edit_client)
|
||||
:client/locations (filter identity (:locations edit_client))
|
||||
:client/week-a-debits (:week_a_debits edit_client)
|
||||
|
||||
Reference in New Issue
Block a user