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


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:
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 ... }}

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:

@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.


@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:

@flamber Hello, I compiled and packaged based on this branch(
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,
("–> models.permissions$fn__27148$set_has_partial_permissions_for_set_QMARK___27153.invoke(permissions.clj:232)"

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.