mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 20:26:10 +02:00
♻️ Add admin facilities on the code base
- Fix bugs related to orphan teams on profile deletion - Separate session based profile-id param from api user provided
This commit is contained in:
parent
53d9b547c3
commit
b929564fa7
53 changed files with 872 additions and 468 deletions
40
backend/src/app/setup/initial_user.clj
Normal file
40
backend/src/app/setup/initial_user.clj
Normal file
|
@ -0,0 +1,40 @@
|
|||
;; 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.initial-user
|
||||
"Initial data setup of instance."
|
||||
(:require
|
||||
[app.auth :as auth]
|
||||
[app.common.logging :as l]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.setup :as-alias setup]
|
||||
[clojure.spec.alpha :as s]
|
||||
[integrant.core :as ig]))
|
||||
|
||||
(def ^:private sql:insert-profile
|
||||
"insert into profile (id, fullname, email, password, is_active, is_admin, created_at, modified_at)
|
||||
values ('00000000-0000-0000-0000-000000000000', 'Admin', ?, ?, true, true, now(), now())
|
||||
on conflict (id)
|
||||
do update set email = ?, password = ?")
|
||||
|
||||
(defmethod ig/pre-init-spec ::setup/initial-profile [_]
|
||||
(s/keys :req [::db/pool]))
|
||||
|
||||
(defmethod ig/init-key ::setup/initial-profile
|
||||
[_ {:keys [::db/pool]}]
|
||||
(let [email (cf/get :setup-admin-email)
|
||||
password (cf/get :setup-admin-password)]
|
||||
(when (and email password)
|
||||
(db/with-atomic [conn pool]
|
||||
(let [pwd (auth/derive-password password)]
|
||||
(db/exec-one! conn [sql:insert-profile email pwd email pwd])
|
||||
(l/info :hint "setting initial user (admin)"
|
||||
:email email
|
||||
:password "********"))))
|
||||
nil))
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue