Skip to content
Snippets Groups Projects
Unverified Commit 4dcd413f authored by bryan's avatar bryan Committed by GitHub
Browse files

add skip_graph to coll perm PUT (#45438)

* add skip_graph to coll perm PUT

- also no longer ignores revision and groups
  so we don't print this warning:
  2024-07-11 16:17:32,293 WARN api.common :: Unexpected parameters at [:put "/api/collection/graph"]: [:revision :groups]

* namespace should be a keyword

* decode the keyword

* add a typehint to avoid reflection

* Adds test for skip_graph

* handle revision 0 :face_palm:
parent 51bec614
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@
[metabase.legacy-mbql.normalize :as mbql.normalize]
[metabase.models.card :as card :refer [Card]]
[metabase.models.collection :as collection :refer [Collection]]
[metabase.models.collection-permission-graph-revision :as c-perm-revision]
[metabase.models.collection.graph :as graph]
[metabase.models.collection.root :as collection.root]
[metabase.models.interface :as mi]
......@@ -1246,16 +1247,30 @@
;; TODO: should use a coercer for this?
(graph-decoder permission-graph))
(defn- update-graph!
"Handles updating the graph for a given namespace."
[namespace graph skip_graph]
(graph/update-graph! namespace graph)
(if skip_graph
{:revision (c-perm-revision/latest-id)}
(graph/graph namespace)))
(api/defendpoint PUT "/graph"
"Do a batch update of Collections Permissions by passing in a modified graph.
Will overwrite parts of the graph that are present in the request, and leave the rest unchanged."
[:as {{:keys [namespace], :as body} :body}]
{body :map
namespace [:maybe ms/NonBlankString]}
Will overwrite parts of the graph that are present in the request, and leave the rest unchanged.
If the `skip_graph` query parameter is true, it will only return the current revision"
[:as {{:keys [namespace revision groups]} :body
{:strs [skip_graph]} :query-params}]
{namespace [:maybe ms/NonBlankString]
revision ms/Int
groups :map
skip_graph [:maybe ms/BooleanValue]}
(api/check-superuser)
(->> (dissoc body :namespace)
decode-graph
(graph/update-graph! namespace))
(graph/graph namespace))
(update-graph!
namespace
(decode-graph {:revision revision :groups groups})
skip_graph))
(api/define-routes)
......@@ -11,6 +11,7 @@
NativeQuerySnippet PermissionsGroup PermissionsGroupMembership Pulse
PulseCard PulseChannel PulseChannelRecipient Revision Timeline TimelineEvent User]]
[metabase.models.collection :as collection]
[metabase.models.collection-permission-graph-revision :as c-perm-revision]
[metabase.models.collection-test :as collection-test]
[metabase.models.collection.graph :as graph]
[metabase.models.collection.graph-test :as graph.test]
......@@ -2262,3 +2263,16 @@
(testing "Cards can't be moved to the trash"
(mt/user-http-request :crowberto :put 400 (str "card/" (u/the-id card)) {:collection_id (collection/trash-collection-id)})
(is (not (t2/exists? :model/Card :collection_id (collection/trash-collection-id)))))))
(deftest skip-graph-skips-graph-on-graph-PUT
(is (malli= [:map [:revision :int] [:groups :map]]
(mt/user-http-request :crowberto
:put 200
"collection/graph"
{:revision (c-perm-revision/latest-id) :groups {}})))
(is (malli= [:map {:closed true} [:revision :int]]
(mt/user-http-request :crowberto
:put 200
"collection/graph?skip_graph=true"
{:revision (c-perm-revision/latest-id) :groups {}}))
"PUTs with skip_graph should not return the coll permission graph."))
......@@ -390,7 +390,7 @@
upload/max-bytes (constantly max-bytes)]
(doseq [c ["a" "出"]]
(let [long-csv-file-prefix (apply str (repeat (inc max-bytes) c))
char-size (count (.getBytes c "UTF-8"))]
char-size (count (.getBytes ^String c "UTF-8"))]
(with-upload-table! [table (card->table (upload-example-csv! :csv-file-prefix long-csv-file-prefix))]
(testing "The card name should be truncated to max bytes with UTF-8 encoding"
(is (= (str/capitalize (apply str (repeat (quot max-bytes char-size) c)))
......
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