0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

🎉 Test A/B for start in workspace

This commit is contained in:
Pablo Alba 2024-08-19 10:47:25 +02:00
parent bf60bf1848
commit 3f7b852672
10 changed files with 195 additions and 73 deletions

View file

@ -36,4 +36,7 @@
:file-uri "https://github.com/penpot/penpot-files/raw/binary-files/Open-Color-Scheme.penpot"}
{:id "flex-layout-playground"
:name "Flex Layout Playground"
:file-uri "https://github.com/penpot/penpot-files/raw/binary-files/Flex-Layout-Playground.penpot"}]
:file-uri "https://github.com/penpot/penpot-files/raw/binary-files/Flex-Layout-Playground.penpot"}
{:id "welcome"
:name "Welcome"
:file-uri "https://github.com/penpot/penpot-files/raw/binary-files/welcome.penpot"}]

View file

@ -27,9 +27,11 @@
[app.rpc.doc :as-alias doc]
[app.rpc.helpers :as rph]
[app.setup :as-alias setup]
[app.setup.welcome-file :as welcome-file]
[app.tokens :as tokens]
[app.util.services :as sv]
[app.util.time :as dt]
[app.worker :as-alias wrk]
[cuerdas.core :as str]))
(def schema:password
@ -350,7 +352,7 @@
:extra-data ptoken})))
(defn register-profile
[{:keys [::db/conn] :as cfg} {:keys [token fullname theme] :as params}]
[{:keys [::db/conn] :as cfg} {:keys [token fullname theme welcome-file] :as params}]
(let [theme (when (= theme "light") theme)
claims (tokens/verify (::setup/props cfg) {:token token :iss :prepared-register})
params (-> claims
@ -380,7 +382,11 @@
invitation (when-let [token (:invitation-token params)]
(tokens/verify (::setup/props cfg) {:token token :iss :team-invitation}))
props (audit/profile->props profile)]
props (audit/profile->props profile)
create-welcome-file-when-needed
(when (some? welcome-file)
(partial welcome-file/create-welcome-file cfg profile))]
(cond
;; When profile is blocked, we just ignore it and return plain data
@ -421,7 +427,8 @@
(rph/with-meta
{::audit/replace-props props
::audit/context {:action "login"}
::audit/profile-id (:id profile)}))
::audit/profile-id (:id profile)
::before-complete-fns [create-welcome-file-when-needed]}))
(do
(when-not (eml/has-reports? conn (:email profile))
@ -430,7 +437,8 @@
(rph/with-meta {:email (:email profile)}
{::audit/replace-props props
::audit/context {:action "email-verification"}
::audit/profile-id (:id profile)})))
::audit/profile-id (:id profile)
::rpc/before-complete-fns [create-welcome-file-when-needed]})))
:else
(let [elapsed? (elapsed-verify-threshold? profile)
@ -462,7 +470,8 @@
[:map {:title "register-profile"}
[:token schema:token]
[:fullname [::sm/word-string {:max 100}]]
[:theme {:optional true} [:string {:max 10}]]])
[:theme {:optional true} [:string {:max 10}]]
[:welcome-file {:optional true} [:boolean]]])
(sv/defmethod ::register-profile
{::rpc/auth false

View file

@ -397,8 +397,8 @@
;; --- COMMAND: Clone Template
(defn- clone-template
[cfg {:keys [project-id ::rpc/profile-id] :as params} template]
(defn clone-template
[cfg {:keys [project-id profile-id] :as params} template]
(db/tx-run! cfg (fn [{:keys [::db/conn ::wrk/executor] :as cfg}]
;; NOTE: the importation process performs some operations that
;; are not very friendly with virtual threads, and for avoid
@ -439,7 +439,8 @@
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id template-id] :as params}]
(let [project (db/get-by-id pool :project project-id {:columns [:id :team-id]})
_ (teams/check-edition-permissions! pool profile-id (:team-id project))
template (tmpl/get-template-stream cfg template-id)]
template (tmpl/get-template-stream cfg template-id)
params (assoc params :profile-id profile-id)]
(when-not template
(ex/raise :type :not-found

View file

@ -361,27 +361,31 @@
[:map {:title "update-profile-props"}
[:props [:map-of :keyword :any]]]))
(defn update-profile-props
[{:keys [::db/conn] :as cfg} profile-id props]
(let [profile (get-profile conn profile-id ::sql/for-update true)
props (reduce-kv (fn [props k v]
;; We don't accept namespaced keys
(if (simple-ident? k)
(if (nil? v)
(dissoc props k)
(assoc props k v))
props))
(:props profile)
props)]
(db/update! conn :profile
{:props (db/tjson props)}
{:id profile-id})
(filter-props props)))
(sv/defmethod ::update-profile-props
{::doc/added "1.0"
::sm/params schema:update-profile-props}
[{:keys [::db/pool]} {:keys [::rpc/profile-id props]}]
(db/with-atomic [conn pool]
(let [profile (get-profile conn profile-id ::sql/for-update true)
props (reduce-kv (fn [props k v]
;; We don't accept namespaced keys
(if (simple-ident? k)
(if (nil? v)
(dissoc props k)
(assoc props k v))
props))
(:props profile)
props)]
(db/update! conn :profile
{:props (db/tjson props)}
{:id profile-id})
(filter-props props))))
[cfg {:keys [::rpc/profile-id props]}]
(db/tx-run! cfg (fn [cfg]
(update-profile-props cfg profile-id props))))
;; --- MUTATION: Delete Profile

View file

@ -0,0 +1,77 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.setup.welcome-file
(:require
[app.common.logging :as l]
[app.common.types.pages-list :as ctpl]
[app.db :as db]
[app.features.fdata :as feat.fdata]
[app.rpc :as-alias rpc]
[app.rpc.climit :as-alias climit]
[app.rpc.commands.management :as management]
[app.rpc.commands.profile :as profile]
[app.rpc.doc :as-alias doc]
[app.setup :as-alias setup]
[app.setup.templates :as tmpl]
[app.util.blob :as blob]
[app.util.pointer-map :as pmap]
[app.worker :as-alias wrk]))
(defn- decode-row
"A generic decode row helper"
[{:keys [data features] :as row}]
(cond-> row
features (assoc :features (db/decode-pgarray features #{}))
data (assoc :data (blob/decode data))))
(defn- update-welcome-text
[conn file name]
(let [page-id #uuid "2c6952ee-d00e-8160-8004-d2250b7210cb"
text-id #uuid "765e9f82-c44e-802e-8004-d72a10b7b445"
fdata (:data file)
page (ctpl/get-page fdata page-id)
objects (:objects page)
text (-> (get objects text-id)
(assoc :name "Welcome to Penpot" :position-data nil)
(assoc-in [:content :children 0 :children 0 :children 0 :text] (str "Welcome to Penpot, " name "!")))
fdata (assoc-in fdata [:pages-index page-id :objects text-id] text)]
(db/update! conn :file
{:data (blob/encode fdata)}
{:id (:id file)})))
(defn- update-welcome-file
[{:keys [::db/conn] :as cfg} file-id name]
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
(when-let [file (db/get* conn :file {:id file-id}
{::db/remove-deleted false})]
(let [file (-> file
(decode-row)
(update :data feat.fdata/process-pointers deref)
(update :data feat.fdata/process-objects (partial into {})))]
(update-welcome-text conn file name)))))
(defn create-welcome-file
[cfg profile]
(try
(let [cfg (dissoc cfg ::db/conn)
params {:profile-id (:id profile)
:project-id (:default-project-id profile)}
template-stream (tmpl/get-template-stream cfg "welcome")
file-id (-> (management/clone-template cfg params template-stream)
first)]
(db/tx-run! cfg (fn [cfg]
(update-welcome-file cfg file-id (:fullname profile))
(profile/update-profile-props cfg (:id profile) {:welcome-file-id file-id}))))
(catch Throwable cause
(l/error :hint "unexpected error on create welcome file " :cause cause))))

View file

@ -25,6 +25,8 @@
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
(declare update-profile-props)
;; --- SCHEMAS
(def ^:private
@ -152,14 +154,20 @@
profile. The profile can proceed from standard login or from
accepting invitation, or third party auth signup or singin."
[profile]
(letfn [(get-redirect-event []
(letfn [(get-redirect-events []
(let [team-id (get-current-team-id profile)
redirect-url (:redirect-url @storage)]
redirect-url (:redirect-url @storage)
welcome-file-id (get-in profile [:props :welcome-file-id])]
(if (some? redirect-url)
(do
(swap! storage dissoc :redirect-url)
(.replace js/location redirect-url))
(rt/nav' :dashboard-projects {:team-id team-id}))))]
(if (some? welcome-file-id)
(rx/of
(rt/nav' :workspace {:project-id (:default-project-id profile)
:file-id welcome-file-id})
(update-profile-props {:welcome-file-id nil}))
(rx/of (rt/nav' :dashboard-projects {:team-id team-id}))))))]
(ptk/reify ::logged-in
ev/Event
@ -176,10 +184,11 @@
ptk/WatchEvent
(watch [_ _ _]
(when (is-authenticated? profile)
(->> (rx/of (profile-fetched profile)
(fetch-teams)
(get-redirect-event)
(ws/initialize))
(->> (rx/concat
(rx/of (profile-fetched profile)
(fetch-teams)
(ws/initialize))
(get-redirect-events))
(rx/observe-on :async)))))))
(declare login-from-register)

View file

@ -53,7 +53,30 @@
{::mf/wrap [#(mf/catch % {:fallback on-main-error})]
::mf/props :obj}
[{:keys [route profile]}]
(let [{:keys [data params]} route]
(let [{:keys [data params]} route
props (get profile :props)
show-question-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :onboarding-questions)))
show-newsletter-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :newsletter-updates))
(contains? props :onboarding-questions))
show-team-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :onboarding-team-id))
(contains? props :newsletter-updates))
show-release-modal?
(and (contains? cf/flags :onboarding)
(:onboarding-viewed props)
(not= (:release-notes-viewed props) (:main cf/version))
(not= "0.0" (:main cf/version)))]
[:& (mf/provider ctx/current-route) {:value route}
(case (:name data)
(:auth-login
@ -97,42 +120,19 @@
#_[:& app.main.ui.onboarding/onboarding-templates-modal]
#_[:& app.main.ui.onboarding/onboarding-modal]
#_[:& app.main.ui.onboarding.team-choice/onboarding-team-modal]
(when-let [props (get profile :props)]
(let [show-question-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :onboarding-questions)))
show-newsletter-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :newsletter-updates))
(contains? props :onboarding-questions))
(cond
show-question-modal?
[:& questions-modal]
show-team-modal?
(and (contains? cf/flags :onboarding)
(not (:onboarding-viewed props))
(not (contains? props :onboarding-team-id))
(contains? props :newsletter-updates))
show-newsletter-modal?
[:& onboarding-newsletter]
show-release-modal?
(and (contains? cf/flags :onboarding)
(:onboarding-viewed props)
(not= (:release-notes-viewed props) (:main cf/version))
(not= "0.0" (:main cf/version)))]
show-team-modal?
[:& onboarding-team-modal {:go-to-team? true}]
(cond
show-question-modal?
[:& questions-modal]
show-newsletter-modal?
[:& onboarding-newsletter]
show-team-modal?
[:& onboarding-team-modal]
show-release-modal?
[:& release-notes-modal {:version (:main cf/version)}])))
show-release-modal?
[:& release-notes-modal {:version (:main cf/version)}])
[:& dashboard-page {:route route :profile profile}]]
:viewer
@ -166,6 +166,19 @@
page-id (some-> params :query :page-id uuid)
layout (some-> params :query :layout keyword)]
[:? {}
(cond
show-question-modal?
[:& questions-modal]
show-newsletter-modal?
[:& onboarding-newsletter]
show-team-modal?
[:& onboarding-team-modal {:go-to-team? false}]
show-release-modal?
[:& release-notes-modal {:version (:main cf/version)}])
[:& workspace-page {:project-id project-id
:file-id file-id
:page-id page-id

View file

@ -227,6 +227,8 @@
:validators validators
:initial params)
welcome-file? (cf/external-feature-flag "onboarding-03" "test")
submitted? (mf/use-state false)
on-success
@ -246,7 +248,8 @@
(mf/use-fn
(fn [form _]
(reset! submitted? true)
(let [params (:clean-data @form)]
(let [params (cond-> (:clean-data @form)
welcome-file? (assoc :welcome-file true))]
(->> (rp/cmd! :register-profile params)
(rx/finalize #(reset! submitted? false))
(rx/subs! on-success on-error)))))]

View file

@ -168,7 +168,9 @@
[{:keys [default-project-id profile project-id team-id]}]
(let [templates (mf/deref builtin-templates)
templates (mf/with-memo [templates]
(filterv #(not= (:id %) "tutorial-for-beginners") templates))
(filterv #(and
(not= (:id %) "welcome")
(not= (:id %) "tutorial-for-beginners")) templates))
route (mf/deref refs/route)
route-name (get-in route [:data :name])

View file

@ -68,7 +68,7 @@
(mf/defc team-form-step-2
{::mf/props :obj}
[{:keys [name on-back]}]
[{:keys [name on-back go-to-team?]}]
(let [initial (mf/use-memo
#(do {:role "editor"
:name name}))
@ -87,7 +87,8 @@
(let [team-id (:id response)]
(st/emit! (du/update-profile-props {:onboarding-team-id team-id
:onboarding-viewed true})
(rt/nav :dashboard-projects {:team-id team-id})))))
(when go-to-team?
(rt/nav :dashboard-projects {:team-id team-id}))))))
on-error
(mf/use-fn
@ -248,7 +249,7 @@
(mf/defc onboarding-team-modal
{::mf/props :obj}
[]
[{:keys [go-to-team?]}]
(let [name* (mf/use-state nil)
name (deref name*)
@ -270,6 +271,6 @@
[:& left-sidebar]
[:div {:class (stl/css :separator)}]
(if name
[:& team-form-step-2 {:name name :on-back on-back}]
[:& team-form-step-2 {:name name :on-back on-back :go-to-team? go-to-team?}]
[:& team-form-step-1 {:on-submit on-submit}])]]))