diff --git a/backend/src/app/rpc/commands/projects.clj b/backend/src/app/rpc/commands/projects.clj index 3684824bc5..c99c4f27d7 100644 --- a/backend/src/app/rpc/commands/projects.clj +++ b/backend/src/app/rpc/commands/projects.clj @@ -70,7 +70,27 @@ ;; --- 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 [:map {:title "get-projects"} @@ -78,32 +98,11 @@ (sv/defmethod ::get-projects {::doc/added "1.18" + ::doc/changes [["2.12" "This endpoint now return deleted but recoverable projects"]] ::sm/params schema:get-projects} - [{:keys [::db/pool]} {:keys [::rpc/profile-id team-id]}] - (dm/with-open [conn (db/open pool)] - (teams/check-read-permissions! conn 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])) + [cfg {:keys [::rpc/profile-id team-id]}] + (teams/check-read-permissions! cfg profile-id team-id) + (get-projects cfg profile-id team-id)) ;; --- QUERY: Get all projects diff --git a/backend/test/backend_tests/rpc_project_test.clj b/backend/test/backend_tests/rpc_project_test.clj index 652894aa47..6f4704e973 100644 --- a/backend/test/backend_tests/rpc_project_test.clj +++ b/backend/test/backend_tests/rpc_project_test.clj @@ -104,7 +104,8 @@ ;; (th/print-result! out) (t/is (nil? (:error 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 (let [profile1 (th/create-profile* 1) @@ -207,7 +208,8 @@ ;; (th/print-result! out) (t/is (nil? (:error 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) (let [result (th/run-task! :objects-gc {})] diff --git a/frontend/src/app/main/ui/dashboard/projects.cljs b/frontend/src/app/main/ui/dashboard/projects.cljs index fd6470893f..472ed76ff8 100644 --- a/frontend/src/app/main/ui/dashboard/projects.cljs +++ b/frontend/src/app/main/ui/dashboard/projects.cljs @@ -245,7 +245,10 @@ [:div {:class (stl/css-case :project-actions true :pinned-project (:is-pinned 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 [:button {:class (stl/css :add-file-btn) @@ -315,6 +318,7 @@ (let [projects (mf/with-memo [projects] (->> projects + (remove :deleted-at) (sort-by :modified-at) (reverse))) diff --git a/frontend/src/app/main/ui/dashboard/sidebar.cljs b/frontend/src/app/main/ui/dashboard/sidebar.cljs index d73ea8faae..8e7ccae588 100644 --- a/frontend/src/app/main/ui/dashboard/sidebar.cljs +++ b/frontend/src/app/main/ui/dashboard/sidebar.cljs @@ -688,6 +688,7 @@ pinned-projects (mf/with-memo [projects] (->> projects + (remove :deleted-at) (remove :is-default) (filter :is-pinned) (sort-by :name)