     inner join project_users as pu on (p.id = pu.project_id)
      left join project_pages as pp on (pf.id = pp.file_id)
     where pu.user_id = $1
-      and pu.project_id = $2
       and pu.can_edit = true
     group by pf.id
-    order by pf.created_at asc;")
+    order by pf.created_at asc")
+
+;; --- Query: Project Files
+
+(def ^:private sql:project-files
+  (str "with files as (" sql:generic-project-files ")"
+       " select * from files where project_id = $2"))
 
 (s/def ::project-files
   (s/keys :req-un [::user ::project-id]))

(s/def ::project-id ::us/uuid)
(s/def ::user ::us/uuid)

;; --- Query: Project Files

(def ^:private sql:project-files
  "select pf.*,
          array_agg(pp.id) as pages
     from project_files as pf

  (-> (db/query db/pool [sql:project-files user project-id])
      (p/then' (partial mapv decode-row))))

;; --- Query: Project File (By ID)

(def ^:private sql:project-file
  (str "with files as (" sql:generic-project-files ")"
       " select * from files where id = $2"))

(s/def ::project-file
  (s/keys :req-un [::user ::id]))

(sq/defquery ::project-file
  [{:keys [user id] :as params}]
  (-> (db/query-one db/pool [sql:project-file user id])
      (p/then' decode-row)))

;; --- Helpers

(defn decode-row
