diff --git a/backend/src/app/rpc/commands/profile.clj b/backend/src/app/rpc/commands/profile.clj index 221896f385..ba1af4a362 100644 --- a/backend/src/app/rpc/commands/profile.clj +++ b/backend/src/app/rpc/commands/profile.clj @@ -89,6 +89,12 @@ 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) @@ -106,9 +112,7 @@ (let [profile (-> (get-profile pool profile-id) (strip-private-attrs) (update :props filter-props))] - (if (contains? cf/flags :nitrate) - (nitrate/add-nitrate-licence-to-profile cfg profile) - profile)) + (with-nitrate-licence profile cfg)) (catch Throwable cause (if (= :not-found (-> cause ex-data :type)) @@ -137,7 +141,7 @@ ::sm/params schema:update-profile ::sm/result schema:profile ::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 ;; it or not for explicit locking and avoid concurrent updates of ;; the same row/object. @@ -158,6 +162,7 @@ (-> profile (strip-private-attrs) (d/without-nils) + (with-nitrate-licence cfg) (rph/with-meta {::audit/props (audit/profile->props profile)})))) diff --git a/backend/test/backend_tests/rpc_profile_test.clj b/backend/test/backend_tests/rpc_profile_test.clj index 5a4f94c0a3..7adc12d68e 100644 --- a/backend/test/backend_tests/rpc_profile_test.clj +++ b/backend/test/backend_tests/rpc_profile_test.clj @@ -12,6 +12,7 @@ [app.db :as db] [app.email.blacklist :as email.blacklist] [app.email.whitelist :as email.whitelist] + [app.nitrate :as nitrate] [app.rpc :as-alias rpc] [app.rpc.commands.profile :as profile] [app.tokens :as tokens] @@ -90,17 +91,26 @@ (t/is (not (contains? result :password)))))) (t/testing "update profile" - (let [data (assoc profile - ::th/type :update-profile - ::rpc/profile-id (:id profile) - :fullname "Full Name" - :lang "en" - :theme "dark") - out (th/command! data)] + (with-redefs [app.config/flags #{:nitrate}] + (with-redefs [nitrate/add-nitrate-licence-to-profile + (fn [_ profile] + (assoc profile :subscription {:plan :pro}))] + (let [data (assoc profile + ::th/type :update-profile + ::rpc/profile-id (:id profile) + :fullname "Full Name" + :lang "en" + :theme "dark") + out (th/command! data)] - ;; (th/print-result! out) - (t/is (nil? (:error out))) - (t/is (map? (:result out))))) + ;; (th/print-result! out) + (t/is (nil? (:error 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" (let [data {::th/type :get-profile diff --git a/frontend/src/app/main/ui/dashboard/sidebar.cljs b/frontend/src/app/main/ui/dashboard/sidebar.cljs index 5fb010fe25..eeda604490 100644 --- a/frontend/src/app/main/ui/dashboard/sidebar.cljs +++ b/frontend/src/app/main/ui/dashboard/sidebar.cljs @@ -1298,6 +1298,11 @@ (st/emit! (ev/event {::ev/name "explore-pricing-click" ::ev/origin "dashboard" :section "sidebar"})) (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?] (when-not show-profile-menu? (reset! sub-menu* nil))) diff --git a/frontend/src/app/main/ui/dashboard/subscription.cljs b/frontend/src/app/main/ui/dashboard/subscription.cljs index f207d735b2..6e1b5555ba 100644 --- a/frontend/src/app/main/ui/dashboard/subscription.cljs +++ b/frontend/src/app/main/ui/dashboard/subscription.cljs @@ -136,10 +136,12 @@ (some? days-until-expiry) (some? expiration-date-text)) subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type (-> profile :props :subscription))) + teams-loaded? (seq teams) no-orgs-created? (mf/with-memo [teams] - (->> teams - vals - (not-any? :organization))) + (and (seq teams) + (->> teams + vals + (not-any? :organization)))) handle-click (mf/use-fn @@ -163,7 +165,7 @@ [:* ;; 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 [:div {:class (stl/css :nitrate-banner :highlighted)} [:div {:class (stl/css :nitrate-content)}