mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
✨ Add srepl helpers for delete/restore teams, projects, and files
This commit is contained in:
parent
c3c6879a2f
commit
761bbb7334
6 changed files with 143 additions and 113 deletions
|
@ -912,13 +912,19 @@
|
|||
|
||||
;; --- MUTATION COMMAND: delete-file
|
||||
|
||||
(defn- mark-file-deleted!
|
||||
(defn- mark-file-deleted
|
||||
[conn file-id]
|
||||
(db/update! conn :file
|
||||
{:deleted-at (dt/now)}
|
||||
{:id file-id}
|
||||
{::db/return-keys [:id :name :is-shared :deleted-at
|
||||
:project-id :created-at :modified-at]}))
|
||||
(let [file (db/update! conn :file
|
||||
{:deleted-at (dt/now)}
|
||||
{:id file-id}
|
||||
{::db/return-keys [:id :name :is-shared :deleted-at
|
||||
:project-id :created-at :modified-at]})]
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/conn conn
|
||||
:object :file
|
||||
:deleted-at (:deleted-at file)
|
||||
:id file-id})
|
||||
file))
|
||||
|
||||
(def ^:private
|
||||
schema:delete-file
|
||||
|
@ -929,14 +935,7 @@
|
|||
(defn- delete-file
|
||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id id] :as params}]
|
||||
(check-edition-permissions! conn profile-id id)
|
||||
(let [file (mark-file-deleted! conn id)]
|
||||
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/delay (dt/duration "1m")
|
||||
::wrk/conn conn
|
||||
:object :file
|
||||
:deleted-at (:deleted-at file)
|
||||
:id id})
|
||||
(let [file (mark-file-deleted conn id)]
|
||||
|
||||
;; NOTE: when a file is a shared library, then we proceed to load
|
||||
;; the whole file, proceed with feature checking and properly execute
|
||||
|
@ -951,8 +950,6 @@
|
|||
:profile-id profile-id
|
||||
:project-id (:project-id file))]
|
||||
|
||||
|
||||
|
||||
(-> (cfeat/get-team-enabled-features cf/flags team)
|
||||
(cfeat/check-client-features! (:features params))
|
||||
(cfeat/check-file-features! (:features file)))
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
(ns app.rpc.commands.projects
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.spec :as us]
|
||||
[app.db :as db]
|
||||
[app.db.sql :as-alias sql]
|
||||
|
@ -245,32 +246,37 @@
|
|||
|
||||
;; --- MUTATION: Delete Project
|
||||
|
||||
(defn- delete-project
|
||||
[conn project-id]
|
||||
(let [project (db/update! conn :project
|
||||
{:deleted-at (dt/now)}
|
||||
{:id project-id}
|
||||
{::db/return-keys true})]
|
||||
|
||||
(when (:is-default project)
|
||||
(ex/raise :type :validation
|
||||
:code :non-deletable-project
|
||||
:hint "impossible to delete default project"))
|
||||
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/conn conn
|
||||
:object :project
|
||||
:deleted-at (:deleted-at project)
|
||||
:id project-id})
|
||||
|
||||
project))
|
||||
|
||||
(s/def ::delete-project
|
||||
(s/keys :req [::rpc/profile-id]
|
||||
:req-un [::id]))
|
||||
|
||||
;; TODO: right now, we just don't allow delete default projects, in a
|
||||
;; future we need to ensure raise a correct exception signaling that
|
||||
;; this is not allowed.
|
||||
|
||||
(sv/defmethod ::delete-project
|
||||
{::doc/added "1.18"
|
||||
::webhooks/event? true}
|
||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
||||
(db/with-atomic [conn pool]
|
||||
(check-edition-permissions! conn profile-id id)
|
||||
(let [project (db/update! conn :project
|
||||
{:deleted-at (dt/now)}
|
||||
{:id id :is-default false}
|
||||
{::db/return-keys true})]
|
||||
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/delay (dt/duration "1m")
|
||||
::wrk/conn conn
|
||||
:object :project
|
||||
:deleted-at (:deleted-at project)
|
||||
:id id})
|
||||
|
||||
(let [project (delete-project conn id)]
|
||||
(rph/with-meta (rph/wrap)
|
||||
{::audit/props {:team-id (:team-id project)
|
||||
:name (:name project)
|
||||
|
|
|
@ -517,38 +517,44 @@
|
|||
|
||||
;; --- Mutation: Delete Team
|
||||
|
||||
(defn- delete-team
|
||||
"Mark a team for deletion"
|
||||
[conn team-id]
|
||||
|
||||
(let [deleted-at (dt/now)
|
||||
team (db/update! conn :team
|
||||
{:deleted-at deleted-at}
|
||||
{:id team-id}
|
||||
{::db/return-keys true})]
|
||||
|
||||
(when (:is-default team)
|
||||
(ex/raise :type :validation
|
||||
:code :non-deletable-team
|
||||
:hint "impossible to delete default team"))
|
||||
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/conn conn
|
||||
:object :team
|
||||
:deleted-at deleted-at
|
||||
:id team-id})
|
||||
team))
|
||||
|
||||
(s/def ::delete-team
|
||||
(s/keys :req [::rpc/profile-id]
|
||||
:req-un [::id]))
|
||||
|
||||
;; TODO: right now just don't allow delete default team, in future it
|
||||
;; should raise a specific exception for signal that this action is
|
||||
;; not allowed.
|
||||
|
||||
(sv/defmethod ::delete-team
|
||||
{::doc/added "1.17"}
|
||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
||||
(db/with-atomic [conn pool]
|
||||
(let [perms (get-permissions conn profile-id id)
|
||||
deleted-at (dt/now)]
|
||||
|
||||
(let [perms (get-permissions conn profile-id id)]
|
||||
(when-not (:is-owner perms)
|
||||
(ex/raise :type :validation
|
||||
:code :only-owner-can-delete-team))
|
||||
|
||||
(db/update! conn :team
|
||||
{:deleted-at deleted-at}
|
||||
{:id id :is-default false})
|
||||
|
||||
(wrk/submit! {::wrk/task :delete-object
|
||||
::wrk/delay (dt/duration "1m")
|
||||
::wrk/conn conn
|
||||
:object :team
|
||||
:deleted-at deleted-at
|
||||
:id id})
|
||||
(delete-team conn id)
|
||||
nil)))
|
||||
|
||||
|
||||
;; --- Mutation: Team Update Role
|
||||
|
||||
(s/def ::team-id ::us/uuid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue