Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
66ba9c23
Unverified
Commit
66ba9c23
authored
7 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Fix perms checking
parent
c408f605
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/public.clj
+7
-5
7 additions, 5 deletions
src/metabase/api/public.clj
src/metabase/models/params.clj
+25
-3
25 additions, 3 deletions
src/metabase/models/params.clj
with
32 additions
and
8 deletions
src/metabase/api/public.clj
+
7
−
5
View file @
66ba9c23
...
...
@@ -228,6 +228,8 @@
(
when-let
[
table-id
(
db/select-one-field
:table_id
Field
:id
field-id,
:special_type
(
mdb/isa
:type/PK
))]
(
db/exists?
Field
:id
search-field-id,
:table_id
table-id,
:special_type
(
mdb/isa
:type/Name
))))))
;; FIXME
(
defn-
check-field-is-referenced-by-dashboard
"Check that `field-id` belongs to a Field that is used as a parameter in a Dashboard with `dashboard-id`, or throw a
404 Exception."
...
...
@@ -238,7 +240,7 @@
(
defn
card-and-field-id->values
"Return the FieldValues for a Field with `field-id` that is referenced by Card with `card-id`."
[
card-id
field-id
]
;
(check-field-is-referenced-by-card field-id card-id)
(
check-field-is-referenced-by-card
field-id
card-id
)
(
field-api/field->values
(
Field
field-id
)))
(
api/defendpoint
GET
"/card/:uuid/field/:field-id/values"
...
...
@@ -277,8 +279,8 @@
"Wrapper for `metabase.api.field/search-values` for use with public/embedded Dashboards. See that functions
documentation for a more detailed explanation of exactly what this does."
[
dashboard-id
field-id
search-id
value
limit
]
;
(check-field-is-referenced-by-dashboard field-id dashboard-id)
;
(check-search-field-is-allowed field-id search-id)
(
check-field-is-referenced-by-dashboard
field-id
dashboard-id
)
(
check-search-field-is-allowed
field-id
search-id
)
(
field-api/search-values
(
Field
field-id
)
(
Field
search-id
)
value
limit
))
(
api/defendpoint
GET
"/card/:uuid/field/:field-id/search/:search-field-id"
...
...
@@ -303,9 +305,9 @@
;;; --------------------------------------------------- Remappings ---------------------------------------------------
(
defn-
field-remapped-values
[
field-id
remapped-field-id,
^
String
value-str
]
;; TODO - how do we check that `remapped-field` is allowed to be used here????????
(
let
[
field
(
api/check-404
(
Field
field-id
))
remapped-field
(
api/check-404
(
Field
remapped-field-id
))]
(
check-search-field-is-allowed
field
remapped-field
)
(
field-api/remapped-value
field
remapped-field
(
field-api/parse-query-param-value-for-field
field
value-str
))))
(
defn
card-field-remapped-values
...
...
@@ -319,7 +321,7 @@
"Return the reampped Field values for a Field referenced by a *Dashboard*. This explanation is almost useless, so see
the one in `metabase.api.field/remapped-value` if you would actually like to understand what is going on here."
[
dashboard-id
field-id
remapped-field-id,
^
String
value-str
]
;
(check-field-is-referenced-by-dashboard field-id dashboard-id)
(
check-field-is-referenced-by-dashboard
field-id
dashboard-id
)
(
field-remapped-values
field-id
remapped-field-id
value-str
))
(
api/defendpoint
GET
"/card/:uuid/field/:field-id/remapping/:remapped-id"
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/params.clj
+
25
−
3
View file @
66ba9c23
(
ns
metabase.models.params
"Utility functions for dealing with parameters for Dashboards and Cards."
(
:require
[
metabase.query-processor.middleware.expand
:as
ql
]
(
:require
[
clojure.set
:as
set
]
[
metabase.query-processor.middleware.expand
:as
ql
]
metabase.query-processor.interface
[
metabase
[
db
:as
mdb
]
...
...
@@ -146,8 +147,9 @@
;;; | DASHBOARD-SPECIFIC |
;;; +----------------------------------------------------------------------------------------------------------------+
(
defn
dashboard->param-field-ids
"Return a set of Field IDs referenced by parameters in Cards in this DASHBOARD, or `nil` if none are referenced."
(
defn-
dashboard->parameter-mapping-field-ids
"Return the IDs of any Fields referenced directly by the Dashboard's `:parameters` (i.e., 'explicit' parameters) by
looking at the appropriate `:parameter_mappings` entries for its Dashcards."
[
dashboard
]
(
when-let
[
ids
(
seq
(
for
[
dashcard
(
:ordered_cards
dashboard
)
param
(
:parameter_mappings
dashcard
)
...
...
@@ -156,6 +158,26 @@
field-id
))]
(
set
ids
)))
(
declare
card->template-tag-field-ids
)
(
defn-
dashboard->card-param-field-ids
"Return the IDs of any Fields referenced in the 'implicit' template tag field filter parameters for native queries in
the Cards in `dashboard`."
[
dashboard
]
(
reduce
set/union
(
for
[{
card
:card
}
(
:ordered_cards
dashboard
)]
(
card->template-tag-field-ids
card
))))
(
defn
dashboard->param-field-ids
"Return a set of Field IDs referenced by parameters in Cards in this DASHBOARD, or `nil` if none are referenced. This
also includes IDs of Fields that are to be found in the 'implicit' parameters for SQL template tag Field filters."
[
dashboard
]
(
let
[
dashboard
(
hydrate
dashboard
[
:ordered_cards
:card
])]
(
set/union
(
dashboard->parameter-mapping-field-ids
dashboard
)
(
dashboard->card-param-field-ids
dashboard
))))
(
defn-
dashboard->param-field-values
"Return a map of Field ID to FieldValues (if any) for any Fields referenced by Cards in DASHBOARD,
or `nil` if none are referenced or none of them have FieldValues."
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment