mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
✨ Make the get-projects return deleted projects
And adapt the frontend code to properly filter deleted projects on appropriate pages
This commit is contained in:
@@ -70,7 +70,27 @@
|
|||||||
|
|
||||||
;; --- QUERY: Get projects
|
;; --- QUERY: Get projects
|
||||||
|
|
||||||
(declare get-projects)
|
(def ^:private sql:projects
|
||||||
|
"SELECT p.*,
|
||||||
|
coalesce(tpp.is_pinned, false) as is_pinned,
|
||||||
|
(SELECT count(*) FROM file AS f
|
||||||
|
WHERE f.project_id = p.id
|
||||||
|
AND f.deleted_at is null) AS count,
|
||||||
|
(SELECT count(*) FROM file AS f
|
||||||
|
WHERE f.project_id = p.id) AS total_count
|
||||||
|
FROM project AS p
|
||||||
|
INNER JOIN team AS t ON (t.id = p.team_id)
|
||||||
|
LEFT JOIN team_project_profile_rel AS tpp
|
||||||
|
ON (tpp.project_id = p.id AND
|
||||||
|
tpp.team_id = p.team_id AND
|
||||||
|
tpp.profile_id = ?)
|
||||||
|
WHERE p.team_id = ?
|
||||||
|
AND t.deleted_at is null
|
||||||
|
ORDER BY p.modified_at DESC")
|
||||||
|
|
||||||
|
(defn get-projects
|
||||||
|
[conn profile-id team-id]
|
||||||
|
(db/exec! conn [sql:projects profile-id team-id]))
|
||||||
|
|
||||||
(def ^:private schema:get-projects
|
(def ^:private schema:get-projects
|
||||||
[:map {:title "get-projects"}
|
[:map {:title "get-projects"}
|
||||||
@@ -78,32 +98,11 @@
|
|||||||
|
|
||||||
(sv/defmethod ::get-projects
|
(sv/defmethod ::get-projects
|
||||||
{::doc/added "1.18"
|
{::doc/added "1.18"
|
||||||
|
::doc/changes [["2.12" "This endpoint now return deleted but recoverable projects"]]
|
||||||
::sm/params schema:get-projects}
|
::sm/params schema:get-projects}
|
||||||
[{:keys [::db/pool]} {:keys [::rpc/profile-id team-id]}]
|
[cfg {:keys [::rpc/profile-id team-id]}]
|
||||||
(dm/with-open [conn (db/open pool)]
|
(teams/check-read-permissions! cfg profile-id team-id)
|
||||||
(teams/check-read-permissions! conn profile-id team-id)
|
(get-projects cfg profile-id team-id))
|
||||||
(get-projects conn profile-id team-id)))
|
|
||||||
|
|
||||||
(def sql:projects
|
|
||||||
"select p.*,
|
|
||||||
coalesce(tpp.is_pinned, false) as is_pinned,
|
|
||||||
(select count(*) from file as f
|
|
||||||
where f.project_id = p.id
|
|
||||||
and deleted_at is null) as count
|
|
||||||
from project as p
|
|
||||||
inner join team as t on (t.id = p.team_id)
|
|
||||||
left join team_project_profile_rel as tpp
|
|
||||||
on (tpp.project_id = p.id and
|
|
||||||
tpp.team_id = p.team_id and
|
|
||||||
tpp.profile_id = ?)
|
|
||||||
where p.team_id = ?
|
|
||||||
and p.deleted_at is null
|
|
||||||
and t.deleted_at is null
|
|
||||||
order by p.modified_at desc")
|
|
||||||
|
|
||||||
(defn get-projects
|
|
||||||
[conn profile-id team-id]
|
|
||||||
(db/exec! conn [sql:projects profile-id team-id]))
|
|
||||||
|
|
||||||
;; --- QUERY: Get all projects
|
;; --- QUERY: Get all projects
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,8 @@
|
|||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(let [result (:result out)]
|
(let [result (:result out)]
|
||||||
(t/is (= 1 (count result)))))))
|
(t/is (= 1 (count (remove :deleted-at result))))
|
||||||
|
(t/is (= 2 (count result)))))))
|
||||||
|
|
||||||
(t/deftest permissions-checks-create-project
|
(t/deftest permissions-checks-create-project
|
||||||
(let [profile1 (th/create-profile* 1)
|
(let [profile1 (th/create-profile* 1)
|
||||||
@@ -207,7 +208,8 @@
|
|||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(t/is (nil? (:error out)))
|
(t/is (nil? (:error out)))
|
||||||
(let [result (:result out)]
|
(let [result (:result out)]
|
||||||
(t/is (= 1 (count result)))))
|
(t/is (= 2 (count result)))
|
||||||
|
(t/is (= 1 (count (remove :deleted-at result))))))
|
||||||
|
|
||||||
;; run permanent deletion (should be noop)
|
;; run permanent deletion (should be noop)
|
||||||
(let [result (th/run-task! :objects-gc {})]
|
(let [result (th/run-task! :objects-gc {})]
|
||||||
|
|||||||
@@ -245,7 +245,10 @@
|
|||||||
[:div {:class (stl/css-case :project-actions true
|
[:div {:class (stl/css-case :project-actions true
|
||||||
:pinned-project (:is-pinned project))}
|
:pinned-project (:is-pinned project))}
|
||||||
(when-not (:is-default project)
|
(when-not (:is-default project)
|
||||||
[:> pin-button* {:class (stl/css :pin-button) :is-pinned (:is-pinned project) :on-click toggle-pin :tab-index 0}])
|
[:> pin-button* {:class (stl/css :pin-button)
|
||||||
|
:is-pinned (:is-pinned project)
|
||||||
|
:on-click toggle-pin
|
||||||
|
:tab-index 0}])
|
||||||
|
|
||||||
(when ^boolean can-edit
|
(when ^boolean can-edit
|
||||||
[:button {:class (stl/css :add-file-btn)
|
[:button {:class (stl/css :add-file-btn)
|
||||||
@@ -315,6 +318,7 @@
|
|||||||
(let [projects
|
(let [projects
|
||||||
(mf/with-memo [projects]
|
(mf/with-memo [projects]
|
||||||
(->> projects
|
(->> projects
|
||||||
|
(remove :deleted-at)
|
||||||
(sort-by :modified-at)
|
(sort-by :modified-at)
|
||||||
(reverse)))
|
(reverse)))
|
||||||
|
|
||||||
|
|||||||
@@ -688,6 +688,7 @@
|
|||||||
pinned-projects
|
pinned-projects
|
||||||
(mf/with-memo [projects]
|
(mf/with-memo [projects]
|
||||||
(->> projects
|
(->> projects
|
||||||
|
(remove :deleted-at)
|
||||||
(remove :is-default)
|
(remove :is-default)
|
||||||
(filter :is-pinned)
|
(filter :is-pinned)
|
||||||
(sort-by :name)
|
(sort-by :name)
|
||||||
|
|||||||
Reference in New Issue
Block a user