How to retrieve group owners? (Rails code question)

You’ll need to write a small plugin to serialize the correct information. I saw your #marketplace post. Hopefully someone will take you up on that!

If you want to start seriously exploring plugins, you might consider checking out How to start building stuff for Discourse if you're newbie (like myself)

I hacked something together as a super rough proof of concept that might give you a starting point to figure it out on your own:

my-plugin/plugin.rb

# frozen_string_literal: true

# name: Group Test
# about: Group Test
# version: 0.1
# authors: Tester
# url: https://github.com/someone/something

enabled_site_setting :group_test_enabled

after_initialize do
  add_to_serializer(:basic_group, :owners) do
    GroupUser.where(group_id: object.id, owner: true).pluck("user_id")
  end
end

my-plugin/config/settings.yml

plugins:
  group_test_enabled:
    default: false
    client: true

In a theme’s </head> tab

<script type="text/x-handlebars" data-template-name="components/groups-info">
 {{#if showFullName}}
   <span class="groups-info-name">{{group.full_name}}</span>
 {{else}}
   <span class="groups-info-name">{{group.displayName}}</span>
   {{#each group.owners as |owner|}}
      {{#if owner}}
        <div>{{owner}}</div>
      {{/if}}
   {{/each}}
 {{/if}}
</script>

If you put all of that together and enable the plugin in your site settings, you should see the user ids of the group owners listed on the groups page.

I won’t be able to help beyond that, so best of luck!

6 Likes