How to get the information of the current login user on the display database page?

DatabaseListApp.jsx

Can I get the login information of the current user in this file? For example, whether the current user is an administrator or the ID of the current user

Hi @zsk
All the user information comes from the API request /api/user/current - it contains the ID, if they’re Admin and much more.

I don’t want to call the back-end interface anymore. Can I get the user’s information at the front-end?

@zsk All information only comes from the backend. The frontend does not have any information, it gets all the data from the backend.

Well, thank you very much. Thank you for your help.

Hello, I have a new question for youHope to get your help.
In our metabase code, a large number of SQL statements are spliced as follows


I can understand SQL as follows:

But I want to write some more complex SQL statements, like the SQL statement below. How can I reflect it in the code? I tried many writing methods, but they were not implemented. I hope to get your help.

user_id_who_create_link is a field name I added to the table permission.

@zsk That’s called MBQL. You can read more about it here:
https://github.com/metabase/metabase/wiki/(Incomplete)-MBQL-Reference
I’m not sure how to do sub-query, but maybe you just add another {:select ...}

Hello, I read the relevant documents, and did not explain the sub query. I try to write like this, but it's still wrong

@zsk I’m not sure how to write a sub-query - there’s a couple of tests with ... (SELECT ..., but I don’t know how to write them in MBQL.
Looking through some files, it seems like you should be looking at {:source-query {:native ... }}
https://github.com/metabase/metabase/blob/master/test/metabase/driver/sql/query_processor_test.clj#L161-L170


Can I only write mbql in this place?
If not, which easier SQL language can I write. What kind of specification does this simple SQL language have?

@zsk If you change it to :native, then it has to be SQL syntax supported by your metadata database (H2, Postgres or MySQL). But I have no idea what other consequences that might have. I am not a Clojure developer.

To avoid unknown errors, I’d better try to write mbql.
Do you have Engineer clojure over there? Maybe we can get a better answer from him. After all, after reading some data, there is no sub-query about mbql

@zsk From what I can see, you should use :source-query for sub-queries, like I linked to.
Or you can try asking in the developer chat: https://gitter.im/metabase/metabase

@camsaul How do you make a sub-query in MBQL?


Maybe everyone is busy, there is no time to reply to me!

Hi @flamber @zsk. I’m not really active on the Gitter chat, this is a better place to reach me.

If you want to make a sub-query in MBQL you can use :source-query, which would look something like:

{:database 1
 :type     :query
 :query    {:source-query {:source-table 2
                           :aggregation  [[:stddev [:field-id 3]]]
                           :breakout     [[:field-id 4]]
                           :order-by     [[[:aggregation 0] :descending]]}
            :aggregation  [[:avg [:field-literal "stddev" :type/Integer]]]}}

The tests in this namespace have some more examples of how source queries should look in MBQL. The $field and similar symbols in that namespace are just a convenience macro for writing tests so we can write MBQL using table/field names instead of IDs, so replace them in your head with [:field-id ...] forms and the like.

2 Likes

@camsaul @flamber Thank you very much for your help

@flamber Hello, when I call the / api / database /: id interface (I use postman), if the session information I passed in is a normal user, the returned JSON does not have the details attribute, but the session information I passed in is an administrator, and the returned information has the details attribute

I want to know where this is controlled? What is the intention of doing so

@zsk The /api/database/:id is used in Admin > Databases, so that information is only for admins.
I would highly recommend that you use your browser developer Network-tab and browse around in the Metabase GUI. It’s the best way to learn the API.
You can also check the source for the APIs:
https://github.com/metabase/metabase/tree/master/src/metabase/api

@flamber Hello, I compiled and packaged based on this branchhttps://github.com/metabase/metabase/tree/release-0.33.x
But when I click the sign up button, an extra request is sent in the logI don’t think this request is necessary

1-28 20:43:09 DEBUG middleware.log :: DELETE /api/session 204 4.8 ms (3 DB calls) Jetty threads: 5/50 (1 idle, 0 queued) (379 total active threads) Queries in flight: 0
11-28 20:43:10 ERROR middleware.log :: GET /api/database 500 5.7 ms (1 DB calls)
{:value [nil #{"/db/2/"}],
:error [(named (not (set? nil)) permissions-set) nil],
:message “Input to set-has-partial-permissions-for-set? does not match schema: \n\n\t [(named (not (set? nil)) permissions-set) nil] \n\n”,
:type clojure.lang.ExceptionInfo,
:stacktrace
("–> models.permissions$fn__27148$set_has_partial_permissions_for_set_QMARK___27153.invoke(permissions.clj:232)"
“models.interface$make_perms_check_fn$_has_perms_QMARK___25924.invoke(interface.clj:252)”
“models.interface$make_perms_check_fn$_has_perms_QMARK___25924.invoke(interface.clj:250)”
“models.interface$fn__25847$fn__25856$G__25850__25865.invoke(interface.clj:184)”
“api.database$dbs_list.invokeStatic(database.clj:148)”
“api.database$dbs_list.invoke(database.clj:147)”
“api.database$fn__51530.invokeStatic(database.clj:160)”
“api.database$fn__51530.invoke(database.clj:153)”
“routes$fn__65543$fn__65544.doInvoke(routes.clj:56)”
“middleware.exceptions$catch_uncaught_exceptions$fn__64265.invoke(exceptions.clj:104)”
“middleware.exceptions$catch_api_exceptions$fn__64262.invoke(exceptions.clj:92)”
“middleware.log$log_api_call$fn__65917$fn__65918.invoke(log.clj:170)”
“middleware.log$log_api_call$fn__65917.invoke(log.clj:164)”
“middleware.security$add_security_headers$fn__64228.invoke(security.clj:122)”
“middleware.json$wrap_json_body$fn__65622.invoke(json.clj:61)”
“middleware.json$wrap_streamed_json_response$fn__65640.invoke(json.clj:97)”
“middleware.session$bind_current_user$fn__60792$fn__60793.invoke(session.clj:209)”
“middleware.session$do_with_current_user.invokeStatic(session.clj:184)”
“middleware.session$do_with_current_user.invoke(session.clj:177)”
“middleware.session$bind_current_user$fn__60792.invoke(session.clj:208)”
“middleware.session$wrap_current_user_id$fn__60777.invoke(session.clj:161)”
“middleware.session$wrap_session_id$fn__60762.invoke(session.clj:123)”
“middleware.auth$wrap_api_key$fn__64174.invoke(auth.clj:27)”
“middleware.misc$maybe_set_site_url$fn__65944.invoke(misc.clj:56)”
“middleware.misc$bind_user_locale$fn__65947.invoke(misc.clj:72)”
“middleware.misc$add_content_type$fn__65932.invoke(misc.clj:28)”
“middleware.misc$disable_streaming_buffering$fn__65955.invoke(misc.clj:87)”)}

11-28 20:43:11 WARN middleware.log :: GET /api/user/current 404 870.0 ”s (0 DB calls)

@zsk I do not understand what you are asking or trying to do. And I don’t know what “click the sign up button” means.
Besides that. Can you create a new topic? Since it sounds like whatever you’re asking now has nothing to do with the original topic.