Add the ability to upload organization profile image

*  Upload org logo

* 📎 Code review

* 📎 Code review 2

* 📎 Code review 3
This commit is contained in:
María Valderrama 2026-04-22 09:37:09 +02:00 committed by GitHub
parent 534701f04f
commit b67394199b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 1 deletions

View File

@ -115,7 +115,8 @@
[:slug ::sm/text] [:slug ::sm/text]
[:is-your-penpot :boolean] [:is-your-penpot :boolean]
[:owner-id ::sm/uuid] [:owner-id ::sm/uuid]
[:avatar-bg-url [::sm/text]]]) [:avatar-bg-url [::sm/text]]
[:logo-id {:optional true} [:maybe ::sm/uuid]]])
(def ^:private schema:org-summary (def ^:private schema:org-summary
[:map [:map
@ -393,6 +394,8 @@
:organization-slug (:slug org) :organization-slug (:slug org)
:organization-owner-id (:owner-id org) :organization-owner-id (:owner-id org)
:organization-avatar-bg-url (:avatar-bg-url org) :organization-avatar-bg-url (:avatar-bg-url org)
:organization-custom-photo (when-let [logo-id (:logo-id org)]
(str (cf/get :public-uri) "/assets/by-id/" logo-id))
:is-default (or (:is-default team) (true? (:is-your-penpot org)))) :is-default (or (:is-default team) (true? (:is-your-penpot org))))
team)) team))
(catch Throwable cause (catch Throwable cause

View File

@ -15,6 +15,7 @@
[app.common.types.team :refer [schema:team]] [app.common.types.team :refer [schema:team]]
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
[app.media :as media]
[app.rpc :as-alias rpc] [app.rpc :as-alias rpc]
[app.rpc.commands.files :as files] [app.rpc.commands.files :as files]
[app.rpc.commands.nitrate :as cnit] [app.rpc.commands.nitrate :as cnit]
@ -23,6 +24,7 @@
[app.rpc.commands.teams-invitations :as ti] [app.rpc.commands.teams-invitations :as ti]
[app.rpc.doc :as doc] [app.rpc.doc :as doc]
[app.rpc.notifications :as notifications] [app.rpc.notifications :as notifications]
[app.storage :as sto]
[app.util.services :as sv])) [app.util.services :as sv]))
@ -81,6 +83,37 @@
(->> (db/exec! cfg [sql:get-teams current-user-id]) (->> (db/exec! cfg [sql:get-teams current-user-id])
(map #(select-keys % [:id :name]))))) (map #(select-keys % [:id :name])))))
;; ---- API: upload-org-logo
(def ^:private schema:upload-org-logo
[:map
[:content media/schema:upload]
[:organization-id ::sm/uuid]
[:previous-id {:optional true} ::sm/uuid]])
(def ^:private schema:upload-org-logo-result
[:map [:id ::sm/uuid]])
(sv/defmethod ::upload-org-logo
"Store an organization logo in penpot storage and return its ID.
Accepts an optional previous-id to mark the old logo for garbage
collection when replacing an existing one."
{::doc/added "2.16"
::sm/params schema:upload-org-logo
::sm/result schema:upload-org-logo-result}
[{:keys [::sto/storage]} {:keys [content organization-id previous-id]}]
(when previous-id
(sto/touch-object! storage previous-id))
(let [hash (sto/calculate-hash (:path content))
data (-> (sto/content (:path content))
(sto/wrap-with-hash hash))
obj (sto/put-object! storage {::sto/content data
::sto/deduplicate? true
:bucket "organization"
:content-type (:mtype content)
:organization-id organization-id})]
{:id (:id obj)}))
;; ---- API: notify-team-change ;; ---- API: notify-team-change
(def ^:private schema:notify-team-change (def ^:private schema:notify-team-change

View File

@ -44,6 +44,7 @@
"file-object-thumbnail" "file-object-thumbnail"
"file-thumbnail" "file-thumbnail"
"profile" "profile"
"organization"
"tempfile" "tempfile"
"file-data" "file-data"
"file-data-fragment" "file-data-fragment"

View File

@ -166,6 +166,7 @@
"profile" (process-objects! conn has-profile-refs? bucket objects) "profile" (process-objects! conn has-profile-refs? bucket objects)
"file-data" (process-objects! conn has-file-data-refs? bucket objects) "file-data" (process-objects! conn has-file-data-refs? bucket objects)
"tempfile" (process-objects! conn (constantly false) bucket objects) "tempfile" (process-objects! conn (constantly false) bucket objects)
"organization" (process-objects! conn (constantly false) bucket objects)
(ex/raise :type :internal (ex/raise :type :internal
:code :unexpected-unknown-reference :code :unexpected-unknown-reference
:hint (dm/fmt "unknown reference '%'" bucket)))) :hint (dm/fmt "unknown reference '%'" bucket))))