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

Timeline and bookmark to toucan2 (#30688)

* Bookmarks to toucan2

* Timeline and TimelineEvent to toucan2
parent c94f66d4
No related branches found
No related tags found
No related merge requests found
......@@ -39,10 +39,10 @@
:model/QueryAction
:metabase.models.activity/Activity
:metabase.models.application-permissions-revision/ApplicationPermissionsRevision
:metabase.models.bookmark/BookmarkOrdering
:metabase.models.bookmark/CardBookmark
:metabase.models.bookmark/CollectionBookmark
:metabase.models.bookmark/DashboardBookmark
:model/BookmarkOrdering
:model/CardBookmark
:model/CollectionBookmark
:model/DashboardBookmark
:metabase.models.collection.root/RootCollection
:metabase.models.collection-permission-graph-revision/CollectionPermissionGraphRevision
:model/DashboardCardSeries
......@@ -67,7 +67,7 @@
:metabase.models.secret/Secret
:metabase.models.session/Session
:metabase.models.task-history/TaskHistory
:metabase.models.timeline-event/TimelineEvent
:model/TimelineEvent
:metabase.models.user/User
:metabase.models.view-log/ViewLog
:metabase-enterprise.sandbox.models.group-table-access-policy/GroupTableAccessPolicy})
......
......@@ -8,15 +8,27 @@
[metabase.models.dashboard :refer [Dashboard]]
[metabase.util.honey-sql-2 :as h2x]
[metabase.util.schema :as su]
[methodical.core :as methodical]
[schema.core :as s]
[toucan.db :as db]
[toucan.models :as models]
[toucan2.core :as t2]))
(models/defmodel CardBookmark :card_bookmark)
(models/defmodel DashboardBookmark :dashboard_bookmark)
(models/defmodel CollectionBookmark :collection_bookmark)
(models/defmodel BookmarkOrdering :bookmark_ordering)
;; Used to be the toucan1 model name defined using [[toucan.models/defmodel]], now it's a reference to the toucan2 model name.
;; We'll keep this till we replace all the symbols in our codebase."
(def CardBookmark "CardBookmark model" :model/CardBookmark)
(def DashboardBookmark "DashboardBookmark model" :model/DashboardBookmark)
(def CollectionBookmark "CollectionBookmark model" :model/CollectionBookmark)
(def BookmarkOrdering "BookmarkOrdering model" :model/BookmarkOrdering)
(methodical/defmethod t2/table-name :model/CardBookmark [_model] :card_bookmark)
(methodical/defmethod t2/table-name :model/DashboardBookmark [_model] :dashboard_bookmark)
(methodical/defmethod t2/table-name :model/CollectionBookmark [_model] :collection_bookmark)
(methodical/defmethod t2/table-name :model/BookmarkOrdering [_model] :bookmark_ordering)
(derive :model/CardBookmark :metabase/model)
(derive :model/DashboardBookmark :metabase/model)
(derive :model/CollectionBookmark :metabase/model)
(derive :model/BookmarkOrdering :metabase/model)
(defn- unqualify-key
[k]
......
......@@ -2,19 +2,27 @@
(:require
[java-time :as t]
[metabase.models.collection :as collection]
[metabase.models.interface :as mi]
[metabase.models.permissions :as perms]
[metabase.models.serialization :as serdes]
[metabase.models.timeline-event :as timeline-event]
[metabase.util.date-2 :as u.date]
[methodical.core :as methodical]
[schema.core :as s]
[toucan.hydrate :refer [hydrate]]
[toucan.models :as models]
[toucan2.core :as t2]))
(models/defmodel Timeline :timeline)
(def Timeline
"Used to be the toucan1 model name defined using [[toucan.models/defmodel]], now it's a reference to the toucan2 model name.
We'll keep this till we replace all the symbols in our codebase."
:model/Timeline)
(derive Timeline ::perms/use-parent-collection-perms)
(methodical/defmethod t2/table-name :model/Timeline [_model] :timeline)
(doto :model/Timeline
(derive :metabase/model)
(derive ::perms/use-parent-collection-perms)
(derive :hook/timestamped?)
(derive :hook/entity-id))
;;;; schemas
......@@ -52,12 +60,7 @@
(nil? collection-id) (->> (map hydrate-root-collection))
events? (timeline-event/include-events options)))
(mi/define-methods
Timeline
{:properties (constantly {::mi/timestamped? true
::mi/entity-id true})})
(defmethod serdes/hash-fields Timeline
(defmethod serdes/hash-fields :model/Timeline
[_timeline]
[:name (serdes/hydrated-hash :collection) :created_at])
......
......@@ -4,14 +4,21 @@
[metabase.models.serialization :as serdes]
[metabase.util.date-2 :as u.date]
[metabase.util.honey-sql-2 :as h2x]
[methodical.core :as methodical]
[schema.core :as s]
[toucan.hydrate :refer [hydrate]]
[toucan.models :as models]
[toucan2.core :as t2]))
(models/defmodel TimelineEvent :timeline_event)
(def TimelineEvent
"Used to be the toucan1 model name defined using [[toucan.models/defmodel]], now it's a reference to the toucan2 model name.
We'll keep this till we replace all the symbols in our codebase."
:model/TimelineEvent)
(methodical/defmethod t2/table-name :model/TimelineEvent [_model] :timeline_event)
(doto TimelineEvent
(derive :metabase/model)
(derive :hook/timestamped?)
(derive ::mi/read-policy.full-perms-for-perms-set)
(derive ::mi/write-policy.full-perms-for-perms-set))
......@@ -24,7 +31,7 @@
;;;; permissions
(defmethod mi/perms-objects-set TimelineEvent
(defmethod mi/perms-objects-set :model/TimelineEvent
[event read-or-write]
(let [timeline (or (:timeline event)
(t2/select-one 'Timeline :id (:timeline_id event)))]
......@@ -88,11 +95,7 @@
;;;; model
(mi/define-methods
TimelineEvent
{:properties (constantly {::mi/timestamped? true})})
(defmethod serdes/hash-fields TimelineEvent
(defmethod serdes/hash-fields :model/TimelineEvent
[_timeline-event]
[:name :timestamp (serdes/hydrated-hash :timeline) :created_at])
......
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