🐛 Fix license not loading in theme change

This commit is contained in:
María Valderrama 2026-06-12 11:27:34 +02:00
parent f5874e159e
commit 68d4238277
4 changed files with 40 additions and 18 deletions

View File

@ -89,6 +89,12 @@
email)] email)]
email)) email))
(defn- with-nitrate-licence
[profile cfg]
(if (contains? cf/flags :nitrate)
(nitrate/add-nitrate-licence-to-profile cfg profile)
profile))
;; --- QUERY: Get profile (own) ;; --- QUERY: Get profile (own)
@ -106,9 +112,7 @@
(let [profile (-> (get-profile pool profile-id) (let [profile (-> (get-profile pool profile-id)
(strip-private-attrs) (strip-private-attrs)
(update :props filter-props))] (update :props filter-props))]
(if (contains? cf/flags :nitrate) (with-nitrate-licence profile cfg))
(nitrate/add-nitrate-licence-to-profile cfg profile)
profile))
(catch Throwable cause (catch Throwable cause
(if (= :not-found (-> cause ex-data :type)) (if (= :not-found (-> cause ex-data :type))
@ -137,7 +141,7 @@
::sm/params schema:update-profile ::sm/params schema:update-profile
::sm/result schema:profile ::sm/result schema:profile
::db/transaction true} ::db/transaction true}
[{:keys [::db/conn]} {:keys [::rpc/profile-id fullname lang theme] :as params}] [{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id fullname lang theme] :as params}]
;; NOTE: we need to retrieve the profile independently if we use ;; NOTE: we need to retrieve the profile independently if we use
;; it or not for explicit locking and avoid concurrent updates of ;; it or not for explicit locking and avoid concurrent updates of
;; the same row/object. ;; the same row/object.
@ -158,6 +162,7 @@
(-> profile (-> profile
(strip-private-attrs) (strip-private-attrs)
(d/without-nils) (d/without-nils)
(with-nitrate-licence cfg)
(rph/with-meta {::audit/props (audit/profile->props profile)})))) (rph/with-meta {::audit/props (audit/profile->props profile)}))))

View File

@ -12,6 +12,7 @@
[app.db :as db] [app.db :as db]
[app.email.blacklist :as email.blacklist] [app.email.blacklist :as email.blacklist]
[app.email.whitelist :as email.whitelist] [app.email.whitelist :as email.whitelist]
[app.nitrate :as nitrate]
[app.rpc :as-alias rpc] [app.rpc :as-alias rpc]
[app.rpc.commands.profile :as profile] [app.rpc.commands.profile :as profile]
[app.tokens :as tokens] [app.tokens :as tokens]
@ -90,17 +91,26 @@
(t/is (not (contains? result :password)))))) (t/is (not (contains? result :password))))))
(t/testing "update profile" (t/testing "update profile"
(let [data (assoc profile (with-redefs [app.config/flags #{:nitrate}]
::th/type :update-profile (with-redefs [nitrate/add-nitrate-licence-to-profile
::rpc/profile-id (:id profile) (fn [_ profile]
:fullname "Full Name" (assoc profile :subscription {:plan :pro}))]
:lang "en" (let [data (assoc profile
:theme "dark") ::th/type :update-profile
out (th/command! data)] ::rpc/profile-id (:id profile)
:fullname "Full Name"
:lang "en"
:theme "dark")
out (th/command! data)]
;; (th/print-result! out) ;; (th/print-result! out)
(t/is (nil? (:error out))) (t/is (nil? (:error out)))
(t/is (map? (:result out))))) (t/is (map? (:result out)))
(t/is (= "Full Name" (get-in out [:result :fullname])))
(t/is (= "en" (get-in out [:result :lang])))
(t/is (= "dark" (get-in out [:result :theme])))
(t/is (= {:plan :pro}
(:subscription (:result out))))))))
(t/testing "query profile after update" (t/testing "query profile after update"
(let [data {::th/type :get-profile (let [data {::th/type :get-profile

View File

@ -1298,6 +1298,11 @@
(st/emit! (ev/event {::ev/name "explore-pricing-click" ::ev/origin "dashboard" :section "sidebar"})) (st/emit! (ev/event {::ev/name "explore-pricing-click" ::ev/origin "dashboard" :section "sidebar"}))
(dom/open-new-window "https://penpot.app/pricing")))] (dom/open-new-window "https://penpot.app/pricing")))]
(mf/with-effect [teams]
(when (and (contains? cf/flags :nitrate)
(empty? teams))
(st/emit! (dtm/fetch-teams))))
(mf/with-effect [show-profile-menu?] (mf/with-effect [show-profile-menu?]
(when-not show-profile-menu? (when-not show-profile-menu?
(reset! sub-menu* nil))) (reset! sub-menu* nil)))

View File

@ -136,10 +136,12 @@
(some? days-until-expiry) (some? days-until-expiry)
(some? expiration-date-text)) (some? expiration-date-text))
subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type (-> profile :props :subscription))) subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type (-> profile :props :subscription)))
teams-loaded? (seq teams)
no-orgs-created? (mf/with-memo [teams] no-orgs-created? (mf/with-memo [teams]
(->> teams (and (seq teams)
vals (->> teams
(not-any? :organization))) vals
(not-any? :organization))))
handle-click handle-click
(mf/use-fn (mf/use-fn
@ -163,7 +165,7 @@
[:* [:*
;; TODO add translations for this texts when we have the definitive ones ;; TODO add translations for this texts when we have the definitive ones
(if (and nitrate? no-orgs-created? (not show-subscription-warning?)) (if (and nitrate? teams-loaded? no-orgs-created? (not show-subscription-warning?))
;; Banner for users with active nitrate license but no organizations created ;; Banner for users with active nitrate license but no organizations created
[:div {:class (stl/css :nitrate-banner :highlighted)} [:div {:class (stl/css :nitrate-banner :highlighted)}
[:div {:class (stl/css :nitrate-content)} [:div {:class (stl/css :nitrate-content)}