mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Add correct assertion on create-invitation fn
This commit is contained in:
@@ -351,19 +351,31 @@
|
|||||||
(on-success))))
|
(on-success))))
|
||||||
(rx/catch on-error))))))
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
|
|
||||||
|
(def ^:private schema:create-invitation
|
||||||
|
[:and
|
||||||
|
[:map
|
||||||
|
[:emails {:optional true} [::sm/set ::sm/email]]
|
||||||
|
[:invitations {:optional true}
|
||||||
|
[:vector
|
||||||
|
[:map
|
||||||
|
[:email ::sm/email]
|
||||||
|
[:role [::sm/one-of ctt/valid-roles]]]]]
|
||||||
|
[:team-id ::sm/uuid]
|
||||||
|
[:resend? ::sm/boolean]]
|
||||||
|
[:fn (fn [attrs]
|
||||||
|
(or (contains? attrs :emails)
|
||||||
|
(contains? attrs :invitations)))]])
|
||||||
|
|
||||||
|
(def ^:private check-create-invitations-params
|
||||||
|
(sm/check-fn schema:create-invitation))
|
||||||
|
|
||||||
(defn create-invitations
|
(defn create-invitations
|
||||||
"Unified function to create invitations. Supports two parameter formats:
|
"Unified function to create invitations. Supports two parameter formats:
|
||||||
1. {:emails #{...} :role :admin :team-id uuid} - single role for all emails
|
1. {:emails #{...} :role :admin :team-id uuid} - single role for all emails
|
||||||
2. {:invitations [{:email ... :role ...}] :team-id uuid} - individual roles per email"
|
2. {:invitations [{:email ... :role ...}] :team-id uuid} - individual roles per email"
|
||||||
[{:keys [emails role team-id invitations resend?] :as params}]
|
[{:keys [emails role team-id invitations resend?] :as params}]
|
||||||
|
(check-create-invitations-params params)
|
||||||
(assert (uuid? team-id))
|
|
||||||
;; Validate input format - must have either emails+role OR invitations
|
|
||||||
(assert (or (and emails role (sm/check-set-of-emails emails) (keyword? role))
|
|
||||||
(and invitations
|
|
||||||
(sm/check-set-of-emails (map :email invitations))
|
|
||||||
(every? #(contains? ctt/valid-roles (:role %)) invitations)))
|
|
||||||
"Must provide either emails+role or invitations with individual roles")
|
|
||||||
|
|
||||||
(ptk/reify ::create-invitations
|
(ptk/reify ::create-invitations
|
||||||
ev/Event
|
ev/Event
|
||||||
|
|||||||
Reference in New Issue
Block a user