Skip to content
Snippets Groups Projects
Unverified Commit a68e9880 authored by Case Nelson's avatar Case Nelson Committed by GitHub
Browse files

[Apps] Scaffold implicit actions (#25815)


When scaffolding, we should be automatically adding the
insert,update,delete implicit actions.

* Add order by on test

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
parent f1eb2772
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@
[metabase.api.collection :as api.collection]
[metabase.api.common :as api]
[metabase.mbql.schema :as mbql.s]
[metabase.models :refer [App Collection Dashboard Table]]
[metabase.models :refer [App Collection Dashboard ModelAction Table]]
[metabase.models.app.graph :as app.graph]
[metabase.models.collection :as collection]
[metabase.models.dashboard :as dashboard]
......@@ -108,6 +108,10 @@
(cond-> ;; card
(not (:dataset card))
(update-in [:dataset_query :query :source_table] #(str "card__" %)))))]
(when (:dataset card)
(db/insert-many! ModelAction [{:card_id (:id card) :slug "insert" :requires_pk false}
{:card_id (:id card) :slug "update" :requires_pk true}
{:card_id (:id card) :slug "delete" :requires_pk true}]))
(assoc accum (into ["scaffold-target-id"] scaffold-target) (:id card))))
{}
cards)]
......
......@@ -2,7 +2,12 @@
(:require
[clojure.test :refer [deftest is testing]]
[medley.core :as m]
[metabase.models :refer [App Card Collection Dashboard Permissions]]
[metabase.models :refer [App
Card
Collection
Dashboard
ModelAction
Permissions]]
[metabase.models.collection.graph :as graph]
[metabase.models.permissions :as perms]
[metabase.models.permissions-group :as perms-group]
......@@ -150,9 +155,9 @@
(testing "Golden path"
(mt/with-temporary-setting-values [all-users-app-permission :read]
(let [app (mt/user-http-request
:crowberto :post 200 "app/scaffold"
{:table-ids [(data/id :venues)]
:app-name "My test app"})
:crowberto :post 200 "app/scaffold"
{:table-ids [(data/id :venues)]
:app-name "My test app"})
pages (m/index-by :name (hydrate (db/select Dashboard :collection_id (:collection_id app)) :ordered_cards))
list-page (get pages "Venues List")
detail-page (get pages "Venues Detail")]
......@@ -166,6 +171,18 @@
:targetId (:id detail-page)}}}
{}]}
list-page))
(testing "Implicit actions are created"
(is (partial=
[{:slug "insert"}
{:slug "update"}
{:slug "delete"}]
(db/select ModelAction {:where [:= :model_action.card_id
{:select [:id]
:from [Card]
:where [:and
[:= :collection_id (:collection_id app)]
[:= :dataset true]]}]
:order-by [:id]}))))
(is (partial= {:groups {(:id (perms-group/all-users)) {(:collection_id app) :read}}}
(graph/graph))
"''All Users'' should have the default permission on the app collection"))))
......
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