Skip to content

Commit

Permalink
Update stakeholder API to use picture key instead of photo
Browse files Browse the repository at this point in the history
[Re #1543]

* We should always use the same name for properties in both BE and
FE. In this case BE and DB uses picture while FE photo in some
ocasions. So we should stick to a single name.
* Frontend will do the necessary changes to update this as well.
  • Loading branch information
lucassousaf committed Aug 16, 2023
1 parent 6ce0cf8 commit 68f6c22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
23 changes: 11 additions & 12 deletions backend/src/gpml/handler/stakeholder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
public_email affiliation
job_title twitter
country about
cv photo
org tags]}]
cv picture org tags]}]
{:title title
:first_name first_name
:last_name last_name
Expand All @@ -74,7 +73,7 @@
:affiliation affiliation
:job_title job_title
:cv cv
:photo photo
:picture picture
:org org
:tags tags})

Expand Down Expand Up @@ -161,8 +160,8 @@
:affiliation (:id org)
:email (:email jwt-claims)
:idp_usernames [(:sub jwt-claims)]
:photo {:payload (:photo body)
:user-agent (get headers "user-agent")}
:picture {:payload (:picture body)
:user-agent (get headers "user-agent")}
:tags tags
:org org))
old-sth (db.stakeholder/stakeholder-by-email conn {:email (:email new-sth)})
Expand All @@ -179,7 +178,7 @@
;; stakeholder fields. We would need to sync with FE to change
;; this.
(r/created (-> (merge body new-sth)
(dissoc :affiliation :picture :cv :photo)
(dissoc :affiliation :picture :cv)
(assoc :org (db.organisation/organisation-by-id
conn
{:id (:affiliation new-sth)})))))
Expand All @@ -205,8 +204,8 @@
(let [tags (handler.stakeholder.tag/api-stakeholder-tags->stakeholder-tags body-params)]
(update-stakeholder config (assoc body-params
:id (:id user)
:photo {:payload (:photo body-params)
:user-agent (get headers "user-agent")}
:picture {:payload (:picture body-params)
:user-agent (get headers "user-agent")}
:tags tags))
(resp/status {:success? true} 204))
(catch Exception e
Expand Down Expand Up @@ -330,7 +329,7 @@
[:last_name string?]
[:linked_in {:optional true} string?]
[:twitter {:optional true} string?]
[:photo {:optional true} string?]
[:picture {:optional true} string?]
[:cv {:optional true} string?]
[:about {:optional true} string?]
[:country {:optional true} int?]
Expand Down Expand Up @@ -423,8 +422,8 @@
(update-stakeholder config (assoc body
:id (:id path)
:tags tags
:photo {:payload (:photo body)
:user-agent (get-in req [:headers "user-agent"])}))
:picture {:payload (:picture body)
:user-agent (get-in req [:headers "user-agent"])}))
(resp/status {:success? true} 204))
(catch Exception e
(log logger :error ::failed-to-update-stakeholder {:exception-message (.getMessage e)})
Expand All @@ -446,7 +445,7 @@
[:job_title {:optional true} string?]
[:linked_in {:optional true} string?]
[:twitter {:optional true} string?]
[:photo {:optional true} string?]
[:picture {:optional true} string?]
[:cv {:optional true} string?]
[:about {:optional true} string?]
[:country {:optional true} int?]
Expand Down
12 changes: 6 additions & 6 deletions backend/src/gpml/service/stakeholder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
transactions
[{:txn-fn
(fn create-picture-file
[{{:keys [photo]} :stakeholder :as context}]
(if-not (:payload photo)
[{{:keys [picture]} :stakeholder :as context}]
(if-not (:payload picture)
context
(let [{:keys [payload user-agent]} photo
(let [{:keys [payload user-agent]} picture
picture (if (util/try-url-str payload)
(util.image/download-image logger payload {:headers {:user-agent user-agent}})
payload)
Expand Down Expand Up @@ -208,8 +208,8 @@
:error-details {:result result}))))}
{:txn-fn
(fn update-picture-file
[{{:keys [photo]} :stakeholder old-stakeholder :old-stakeholder :as context}]
(if-not (:payload photo)
[{{:keys [picture]} :stakeholder old-stakeholder :old-stakeholder :as context}]
(if-not (:payload picture)
context
(let [old-picture-id (:picture-id old-stakeholder)
result (if (:picture-id old-stakeholder)
Expand All @@ -220,7 +220,7 @@
:success? false
:reason :failed-to-delete-old-picture
:error-details {:result result})
(let [{:keys [payload user-agent]} photo
(let [{:keys [payload user-agent]} picture
new-picture (if (util/try-url-str payload)
(util.image/download-image logger payload {:headers {:user-agent user-agent}})
payload)
Expand Down
15 changes: 7 additions & 8 deletions backend/test/gpml/handler/profile_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
body-params (assoc (new-profile 1)
:org (:org data)
:country (-> (:countries data) first :id)
:photo picture)
:picture picture)
{:keys [status body]}
(handler (-> (mock/request :post "/")
(assoc :jwt-claims {:email "john@org" :picture "test.jpg" :sub "auth0|123"})
Expand Down Expand Up @@ -133,7 +133,7 @@
:type "Company"
:url "mycompany.org"}
:country (-> (:countries data) first :id)
:photo picture)
:picture picture)
resp (handler (-> (mock/request :post "/")
(assoc :jwt-claims {:email "john@org" :picture "test.jpg" :sub "auth0|123"})
(assoc :parameters {:body body-params})))]
Expand Down Expand Up @@ -172,10 +172,10 @@
body-params (assoc (new-profile 1)
:org nil
:country (-> (:countries data) first :id))
;; John trying to sign up without any organisation and leave photo, twitter, and linkedin blank
;; John trying to sign up without any organisation and leave picture, twitter, and linkedin blank
resp (handler (-> (mock/request :post "/")
(assoc :jwt-claims {:email "john@org"})
(assoc :parameters {:body (dissoc body-params :twitter :linkedin :photo)})))]
(assoc :parameters {:body (dissoc body-params :twitter :linkedin :picture)})))]
(is (= 201 (:status resp)))
(is (= "John" (-> (:body resp) :first_name)))
(is (= "Doe" (-> (:body resp) :last_name)))
Expand Down Expand Up @@ -210,7 +210,7 @@
:first_name "Mark"
:org {:id 1 :name "Akvo" :url "https://akvo.org"}
:job_title "Developer"
:photo picture
:picture picture
:cv picture
:public_email true))))
profile (db.stakeholder/stakeholder-by-id conn {:id 10001})]
Expand Down Expand Up @@ -259,9 +259,8 @@
:first_name "Mark"
:org {:id 1 :name "Akvo" :url "https://akvo.org"}
:job_title "Developer"
:photo "https://ui-avatars.com/api/?size=480&name=John+Doe"
:cv nil
:picture nil))))
:picture "https://ui-avatars.com/api/?size=480&name=John+Doe"
:cv nil))))
profile (db.stakeholder/stakeholder-by-id db {:id 10001})]
(is (= 204 (:status resp)))
(is (= {:id 10001,
Expand Down

0 comments on commit 68f6c22

Please sign in to comment.