# Plugin Development: List a user’s groups without making a request

**URL:** https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710
**Category:** Development
**Created:** [December 7, 2018, 2:52pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710 "2018-12-07T14:52:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [December 7, 2018, 2:52pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/1 "2018-12-07T14:52:37Z")

</div>

As per “[https://meta.discourse.org/t/getting-users-custom-groups-problems/37792](https://meta.discourse.org/t/getting-users-custom-groups-problems/37792)”, the property `Discourse.User.current().groups` isn’t exposed to all pages.

As per “[Discourse docs: Get a single user by username](https://docs.discourse.org/#tag/Users%2Fpaths%2F~1users~1%7Busername%7D.json%2Fget)”, the response payload includes a `groups` array which would be sufficient.

However, I would prefer to not send a request for this information if I can get it without. Is there a way to list a user’s groups without sending a request?

I need to access a user’s group within my plugins Ember route.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [December 7, 2018, 3:25pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/2 "2018-12-07T15:25:13Z")

</div>

You can add custom plugin code to achieve this. Something similar to below code (unverified). Then you can access it like `Discourse.User.current().groups`

```plaintext
  add_to_serializer(:current_user, :groups, false) {
    object.groups.pluck(:name)
  }

```

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [December 7, 2018, 3:35pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/3 "2018-12-07T15:35:46Z")

</div>

Great, that’s exactly what I was looking for. Logging `Discourse.User.current().groups` now:

```js
["trust_level_0", "trust_level_1", "admins", "staff", "TestGroup"]

```

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [December 7, 2018, 3:51pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/5 "2018-12-07T15:51:26Z")

</div>

I was discussing with @eviltrout about adding this per default for the current user serializer since many themes can benefit from this.

Is this still in your plans @eviltrout ?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [December 7, 2018, 4:29pm UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/6 "2018-12-07T16:29:58Z")

</div>

> [@Falco](#):
>
> adding this per default for the current user serializer since many themes can benefit from this.

@maja, can you add that to your list?

We should always serialize all the group names of the current user (not only the primary group).

---

<div class="post-metadata">

### Author: ![maja](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/maja/32/129533_2.png) [@maja](https://meta.discourse.org/u/maja)
#### Post date: [December 20, 2018, 9:53am UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/7 "2018-12-20T09:53:59Z")

</div>

Current user’s groups were added to the serializer:

> <https://github.com/discourse/discourse/commit/98d09c90acc503051d02094a9f25113eb5fdf293>

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [January 2, 2019, 9:33am UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/8 "2019-01-02T09:33:59Z")

</div>

How does one get a user’s groups in the Rails application? Via `current_user`, I have access to a user’s username, etc. but I can’t find a way to access their groups.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [January 2, 2019, 9:39am UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/9 "2019-01-02T09:39:07Z")

</div>

Did you try `current_user.groups`? That should work

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [January 2, 2019, 10:15am UTC](https://meta.discourse.org/t/plugin-development-list-a-user-s-groups-without-making-a-request/103710/10 "2019-01-02T10:15:38Z")

</div>

Yes, that works. Thank you. I did try logging that and it came up as not defined. I suppose I must’ve had a typo.
