Skip to content
Snippets Groups Projects
Unverified Commit 0b573e50 authored by Ngoc Khuat's avatar Ngoc Khuat Committed by GitHub
Browse files

add :updated-at-timestamped? property and use it on some models (#23220)

* add :updated-at-timestamped? property and use it on some models
parent bc1e7b54
No related branches found
No related tags found
No related merge requests found
......@@ -6,15 +6,12 @@
(models/defmodel ApplicationPermissionsRevision :application_permissions_revision)
(defn- pre-insert [revision]
(assoc revision :created_at :%now))
(u/strict-extend (class ApplicationPermissionsRevision)
models/IModel
(merge models/IModelDefaults
{:types (constantly {:before :json
:after :json})
:pre-insert pre-insert
:properties (constantly {:created-at-timestamped? true})
:pre-update (fn [& _] (throw (Exception. (tru "You cannot update a ApplicationPermissionsRevision!"))))}))
(defn latest-id
......
......@@ -6,18 +6,14 @@
(models/defmodel CollectionPermissionGraphRevision :collection_permission_graph_revision)
(defn- pre-insert [revision]
(assoc revision :created_at :%now))
(u/strict-extend (class CollectionPermissionGraphRevision)
models/IModel
(merge models/IModelDefaults
{:types (constantly {:before :json
:after :json})
:pre-insert pre-insert
:properties (constantly {:created-at-timestamped? true})
:pre-update (fn [& _] (throw (Exception. (tru "You cannot update a CollectionPermissionGraphRevision!"))))}))
(defn latest-id
"Return the ID of the newest `CollectionPermissionGraphRevision`, or zero if none have been made yet.
(This is used by the collection graph update logic that checks for changes since the original graph was fetched)."
......
......@@ -227,6 +227,10 @@
:insert (comp add-created-at-timestamp add-updated-at-timestamp)
:update add-updated-at-timestamp)
;; like `timestamped?`, but for models that only have an `:created_at` column
(models/add-property! :created-at-timestamped?
:insert add-created-at-timestamp)
;; like `timestamped?`, but for models that only have an `:updated_at` column
(models/add-property! :updated-at-timestamped?
:insert add-updated-at-timestamp
......
......@@ -6,15 +6,12 @@
(models/defmodel PermissionsRevision :permissions_revision)
(defn- pre-insert [revision]
(assoc revision :created_at :%now))
(u/strict-extend (class PermissionsRevision)
models/IModel
(merge models/IModelDefaults
{:types (constantly {:before :json
:after :json})
:pre-insert pre-insert
:properties (constantly {:created-at-timestamped? true})
:pre-update (fn [& _] (throw (Exception. (tru "You cannot update a PermissionsRevision!"))))}))
(defn latest-id
......
......@@ -17,7 +17,7 @@
(throw (RuntimeException. "You cannot update a Session.")))
(defn- pre-insert [session]
(cond-> (assoc session :created_at :%now)
(cond-> session
(some-> mw.misc/*request* request.u/embedded?) (assoc :anti_csrf_token (random-anti-csrf-token))))
(defn- post-insert [{anti-csrf-token :anti_csrf_token, :as session}]
......@@ -30,4 +30,5 @@
models/IModelDefaults
{:pre-insert pre-insert
:post-insert post-insert
:pre-update pre-update}))
:pre-update pre-update
:properties (constantly {:created-at-timestamped? true})}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment