     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]))

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

;; --- Helpers

(defn decode-row

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

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