diff --git a/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj b/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj index 76b2bf5642e223f896487e1f12b90dc06a3e6656..77abc35f48e74f8ac89c40b7a8c35a8ce3f5e3ae 100644 --- a/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj +++ b/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj @@ -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}) diff --git a/src/metabase/models/bookmark.clj b/src/metabase/models/bookmark.clj index 13cc3a16bb558f1d6312d38701510c9d668d803f..bbcd4e80ee0ddfa11e9ef0df834bd5e34d9efb70 100644 --- a/src/metabase/models/bookmark.clj +++ b/src/metabase/models/bookmark.clj @@ -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] diff --git a/src/metabase/models/timeline.clj b/src/metabase/models/timeline.clj index aa4a51bb802acf282d92e43f7beee168ce6346d7..f0fe1b31846f71d83798bb8b0f3fcc02560ab82f 100644 --- a/src/metabase/models/timeline.clj +++ b/src/metabase/models/timeline.clj @@ -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]) diff --git a/src/metabase/models/timeline_event.clj b/src/metabase/models/timeline_event.clj index 2c8b5906b9181813d53affd3173b5b6e243e4106..2551db523f04b2edaac198de97605cb40430c657 100644 --- a/src/metabase/models/timeline_event.clj +++ b/src/metabase/models/timeline_event.clj @@ -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])