mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 10:38:13 -05:00
♻️ Refactor flags handling on frontend.
This commit is contained in:
parent
c9985121c4
commit
e587179359
9 changed files with 78 additions and 41 deletions
32
common/src/app/common/flags.cljc
Normal file
32
common/src/app/common/flags.cljc
Normal file
|
@ -0,0 +1,32 @@
|
|||
;; 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) UXBOX Labs SL
|
||||
|
||||
(ns app.common.flags
|
||||
"Flags parsing algorithm."
|
||||
(:require
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(defn parse
|
||||
[default flags]
|
||||
(loop [flags (seq flags)
|
||||
result default]
|
||||
(let [item (first flags)]
|
||||
(if (nil? item)
|
||||
result
|
||||
(let [sname (name item)]
|
||||
(cond
|
||||
(str/starts-with? sname "enable-")
|
||||
(recur (rest flags)
|
||||
(conj result (keyword (subs sname 7))))
|
||||
|
||||
(str/starts-with? sname "disable-")
|
||||
(recur (rest flags)
|
||||
(disj result (keyword (subs sname 8))))
|
||||
|
||||
:else
|
||||
(recur (rest flags) result)))))))
|
||||
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
[app.common.spec :as us]
|
||||
[app.common.uri :as u]
|
||||
[app.common.version :as v]
|
||||
[app.common.flags :as flags]
|
||||
[app.util.avatars :as avatars]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :refer [global location]]
|
||||
|
@ -53,10 +54,14 @@
|
|||
:browser
|
||||
:webworker))
|
||||
|
||||
(def default-flags
|
||||
#{:registration})
|
||||
|
||||
(defn- parse-flags
|
||||
[global]
|
||||
(let [flags (obj/get global "penpotFlags" "")]
|
||||
(into #{} (map keyword) (str/words flags))))
|
||||
(let [flags (obj/get global "penpotFlags" "")
|
||||
flags (into #{} (map keyword) (str/words flags))]
|
||||
(flags/parse default-flags flags)))
|
||||
|
||||
(defn- parse-version
|
||||
[global]
|
||||
|
@ -68,26 +73,27 @@
|
|||
(def default-theme "default")
|
||||
(def default-language "en")
|
||||
|
||||
(def demo-warning (obj/get global "penpotDemoWarning" false))
|
||||
(def feedback-enabled (obj/get global "penpotFeedbackEnabled" false))
|
||||
(def allow-demo-users (obj/get global "penpotAllowDemoUsers" true))
|
||||
(def google-client-id (obj/get global "penpotGoogleClientID" nil))
|
||||
(def gitlab-client-id (obj/get global "penpotGitlabClientID" nil))
|
||||
(def github-client-id (obj/get global "penpotGithubClientID" nil))
|
||||
(def oidc-client-id (obj/get global "penpotOIDCClientID" nil))
|
||||
(def login-with-ldap (obj/get global "penpotLoginWithLDAP" false))
|
||||
(def registration-enabled (obj/get global "penpotRegistrationEnabled" true))
|
||||
(def worker-uri (obj/get global "penpotWorkerURI" "/js/worker.js"))
|
||||
(def translations (obj/get global "penpotTranslations"))
|
||||
(def themes (obj/get global "penpotThemes"))
|
||||
(def analytics (obj/get global "penpotAnalyticsEnabled" false))
|
||||
|
||||
(def flags (delay (parse-flags global)))
|
||||
(def flags (atom (parse-flags global)))
|
||||
(def version (atom (parse-version global)))
|
||||
(def target (atom (parse-target global)))
|
||||
(def browser (atom (parse-browser)))
|
||||
(def platform (atom (parse-platform)))
|
||||
|
||||
(def version (delay (parse-version global)))
|
||||
(def target (delay (parse-target global)))
|
||||
(def browser (delay (parse-browser)))
|
||||
(def platform (delay (parse-platform)))
|
||||
;; mantain for backward compatibility
|
||||
(let [login-with-ldap (obj/get global "penpotLoginWithLDAP" false)
|
||||
registration (obj/get global "penpotRegistrationEnabled" true)]
|
||||
(when login-with-ldap
|
||||
(swap! flags conj :login-with-ldap))
|
||||
(when (false? registration)
|
||||
(swap! flags disj :registration)))
|
||||
|
||||
(def public-uri
|
||||
(let [uri (u/uri (or (obj/get global "penpotPublicURI")
|
||||
|
|
|
@ -242,6 +242,6 @@
|
|||
|
||||
(defmethod ptk/resolve ::initialize
|
||||
[_ params]
|
||||
(if cf/analytics
|
||||
(if (contains? @cf/flags :audit-log)
|
||||
(initialize)
|
||||
(ptk/data-event ::initialize params)))
|
||||
|
|
|
@ -55,11 +55,11 @@
|
|||
(def routes
|
||||
[["/auth"
|
||||
["/login" :auth-login]
|
||||
(when cf/registration-enabled
|
||||
(when (contains? @cf/flags :registration)
|
||||
["/register" :auth-register])
|
||||
(when cf/registration-enabled
|
||||
(when (contains? @cf/flags :registration)
|
||||
["/register/validate" :auth-register-validate])
|
||||
(when cf/registration-enabled
|
||||
(when (contains? @cf/flags :registration)
|
||||
["/register/success" :auth-register-success])
|
||||
["/recovery/request" :auth-recovery-request]
|
||||
["/recovery" :auth-recovery]
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
(ns app.main.ui.auth.login
|
||||
(:require
|
||||
[app.common.spec :as us]
|
||||
[app.config :as cfg]
|
||||
[app.config :as cf]
|
||||
[app.main.data.messages :as dm]
|
||||
[app.main.data.users :as du]
|
||||
[app.main.repo :as rp]
|
||||
|
@ -23,10 +23,10 @@
|
|||
[rumext.alpha :as mf]))
|
||||
|
||||
(def show-alt-login-buttons?
|
||||
(or cfg/google-client-id
|
||||
cfg/gitlab-client-id
|
||||
cfg/github-client-id
|
||||
cfg/oidc-client-id))
|
||||
(or cf/google-client-id
|
||||
cf/gitlab-client-id
|
||||
cf/github-client-id
|
||||
cf/oidc-client-id))
|
||||
|
||||
(s/def ::email ::us/email)
|
||||
(s/def ::password ::us/not-empty-string)
|
||||
|
@ -113,7 +113,7 @@
|
|||
[:& fm/submit-button
|
||||
{:label (tr "auth.login-submit")}]
|
||||
|
||||
(when cfg/login-with-ldap
|
||||
(when (contains? @cf/flags :login-with-ldap)
|
||||
[:& fm/submit-button
|
||||
{:label (tr "auth.login-with-ldap-submit")
|
||||
:on-click on-submit-ldap}])]]]))
|
||||
|
@ -121,26 +121,26 @@
|
|||
(mf/defc login-buttons
|
||||
[{:keys [params] :as props}]
|
||||
[:div.auth-buttons
|
||||
(when cfg/google-client-id
|
||||
(when cf/google-client-id
|
||||
[:a.btn-ocean.btn-large.btn-google-auth
|
||||
{:on-click #(login-with-oauth % :google params)}
|
||||
(tr "auth.login-with-google-submit")])
|
||||
|
||||
(when cfg/gitlab-client-id
|
||||
(when cf/gitlab-client-id
|
||||
[:a.btn-ocean.btn-large.btn-gitlab-auth
|
||||
{:on-click #(login-with-oauth % :gitlab params)}
|
||||
[:img.logo
|
||||
{:src "/images/icons/brand-gitlab.svg"}]
|
||||
(tr "auth.login-with-gitlab-submit")])
|
||||
|
||||
(when cfg/github-client-id
|
||||
(when cf/github-client-id
|
||||
[:a.btn-ocean.btn-large.btn-github-auth
|
||||
{:on-click #(login-with-oauth % :github params)}
|
||||
[:img.logo
|
||||
{:src "/images/icons/brand-github.svg"}]
|
||||
(tr "auth.login-with-github-submit")])
|
||||
|
||||
(when cfg/oidc-client-id
|
||||
(when cf/oidc-client-id
|
||||
[:a.btn-ocean.btn-large.btn-github-auth
|
||||
{:on-click #(login-with-oauth % :oidc params)}
|
||||
(tr "auth.login-with-oidc-submit")])])
|
||||
|
@ -166,14 +166,13 @@
|
|||
[:a {:on-click #(st/emit! (rt/nav :auth-recovery-request))}
|
||||
(tr "auth.forgot-password")]]
|
||||
|
||||
(when cfg/registration-enabled
|
||||
(when (contains? @cf/flags :registration)
|
||||
[:div.link-entry
|
||||
[:span (tr "auth.register") " "]
|
||||
[:a {:on-click #(st/emit! (rt/nav :auth-register {} params))}
|
||||
(tr "auth.register-submit")]])]
|
||||
|
||||
|
||||
(when cfg/allow-demo-users
|
||||
(when (contains? @cf/flags :demo-users)
|
||||
[:div.links.demo
|
||||
[:div.link-entry
|
||||
[:span (tr "auth.create-demo-profile") " "]
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
[:h1 (tr "auth.register-title")]
|
||||
[:div.subtitle (tr "auth.register-subtitle")]
|
||||
|
||||
(when cf/demo-warning
|
||||
(when (contains? @cf/flags :demo-warning)
|
||||
[:& demo-warning])
|
||||
|
||||
[:& register-form {:params params}]
|
||||
|
@ -135,7 +135,7 @@
|
|||
:tab-index "4"}
|
||||
(tr "auth.login-here")]]
|
||||
|
||||
(when cf/allow-demo-users
|
||||
(when (contains? @cf/flags :demo-users)
|
||||
[:div.link-entry
|
||||
[:span (tr "auth.create-demo-profile") " "]
|
||||
[:a {:on-click #(st/emit! (du/create-demo-profile))
|
||||
|
@ -216,7 +216,7 @@
|
|||
:label (tr "auth.terms-privacy-agreement")
|
||||
:type "checkbox"}]]
|
||||
|
||||
(when (contains? @cf/flags :show-newsletter-check-on-register-validation)
|
||||
(when (contains? @cf/flags :newsletter-registration-check)
|
||||
[:div.fields-row
|
||||
[:& fm/input {:name :accept-newsletter-subscription
|
||||
:class "check-primary"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.spec :as us]
|
||||
[app.config :as cfg]
|
||||
[app.config :as cf]
|
||||
[app.main.data.dashboard :as dd]
|
||||
[app.main.data.messages :as dm]
|
||||
[app.main.data.modal :as modal]
|
||||
|
@ -214,7 +214,7 @@
|
|||
[:* {:key (:id team)}
|
||||
[:li.team-name {:on-click (partial team-selected (:id team))}
|
||||
[:span.team-icon
|
||||
[:img {:src (cfg/resolve-team-photo-url team)}]]
|
||||
[:img {:src (cf/resolve-team-photo-url team)}]]
|
||||
[:span.team-text {:title (:name team)} (:name team)]]])
|
||||
|
||||
[:hr]
|
||||
|
@ -358,7 +358,7 @@
|
|||
[:span.team-text (tr "dashboard.default-team-name")]]
|
||||
[:div.team-name
|
||||
[:span.team-icon
|
||||
[:img {:src (cfg/resolve-team-photo-url team)}]]
|
||||
[:img {:src (cf/resolve-team-photo-url team)}]]
|
||||
[:span.team-text {:title (:name team)} (:name team)]])
|
||||
|
||||
[:span.switch-icon
|
||||
|
@ -468,7 +468,7 @@
|
|||
(mf/defc profile-section
|
||||
[{:keys [profile team] :as props}]
|
||||
(let [show (mf/use-state false)
|
||||
photo (cfg/resolve-profile-photo-url profile)
|
||||
photo (cf/resolve-profile-photo-url profile)
|
||||
|
||||
on-click
|
||||
(mf/use-callback
|
||||
|
@ -496,7 +496,7 @@
|
|||
[:span.icon i/exit]
|
||||
[:span.text (tr "labels.logout")]]
|
||||
|
||||
(when cfg/feedback-enabled
|
||||
(when (contains? @cf/flags :user-feedback)
|
||||
[:li.feedback {:on-click (partial on-click :settings-feedback)}
|
||||
[:span.icon i/msg-info]
|
||||
[:span.text (tr "labels.give-feedback")]
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
i/pencil
|
||||
[:span.element-title (tr "labels.release-notes")]]
|
||||
|
||||
(when cf/feedback-enabled
|
||||
(when (contains? @cf/flags :user-feedback)
|
||||
[:li {:class (when feedback? "current")
|
||||
:on-click go-settings-feedback}
|
||||
i/msg-info
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.math :as mth]
|
||||
[app.config :as cfg]
|
||||
[app.config :as cf]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.shortcuts :as sc]
|
||||
|
@ -259,7 +259,7 @@
|
|||
[:li.export-file {:on-click on-export-files}
|
||||
[:span (tr "dashboard.export-single")]]
|
||||
|
||||
(when cfg/feedback-enabled
|
||||
(when (contains? @cf/flags :user-feedback)
|
||||
[:li.feedback {:on-click (st/emitf (rt/nav :settings-feedback))}
|
||||
[:span (tr "labels.give-feedback")]
|
||||
[:span.primary-badge "ALPHA"]])
|
||||
|
|
Loading…
Add table
Reference in a new issue