DiscourseUserDirectory - Experimental User Directory Plugin


(Sam Bauch) #1

Continuing the discussion from Creating Ember routes through a plugin:

I’m ready to put this out in the wild. Obviously it’s very early and this is barely more than a trivial extension, but it will (should?) allow users to access a public facing user directory accessible via a top nav button.

I am having trouble with registering a CSS file, there is no test coverage, and is mainly comprised of code ripped from other parts of Discourse. Should go without saying that YMMV.

Thanks to @eviltrout for the help and @danneu for the tutorial

github repo


Adding a listing of users
How can I enable a directory of members?
(Robin Ward) #2

Awesome stuff. I tried to get this working but it crashes my ruby process as I have a lot more users :slight_smile:

I can offer you some initial feedback though:

  • Your code is triggering a n+1 query on views for users. So if you have thousands like I have in my local database it’s not great. It would be better to use active model serializers and render only the json you need for a user. It looks like a BasicUserSerializer would work great in this case. I’d also limit the results, maybe to the top 100.

  • You can add translations to your gem! The disabled discourse_poll gem in the source code has an example of this.

  • It would be cool if we added hooks to register new menu items so the installer doesn’t have to jump through hoops. This might be a good pull request to discourse proper.

Still, awesome that you figured so much out using our very primitive plugin stuff.


(Sam Bauch) #3

Yeah I definitely didn’t optimize against having a large set of users. Mostly just wanted to get a proof of concept going as the plugin system seems like the most maintainable way for me to build features that are really not suited for core Discourse without having to fight through merge conflicts.

Translations in gem, awesome, will do!

I was initially using the BasicUserSerializer but had ripped it out when I was having trouble with some ember bindings, but I forgot to add that back in. In my own instance I’m also wanting to add some values to the user record, so I’ll probably need to then construct my own serializer.

Generally I’m happy to see how you are using serialization as I’m working on another project now that my collaborator wants to use an MVVM architecture, and Active Model Serializers seems like a good Rails way to accomplish the view model aspect.

Yes, I definitely think a hook for menu items would be a good addition. I’m almost questioning the validity of specifying allowed menu items in the ember app. I suppose it provides the benefit of not adding a broken nav item if an admin were to simply add a new value to the pipe separated list in site settings?

I’d be happy to take a crack at that. My first thought would be to add a method similar to the register_assets method called on plugin installation that would push a string into the array of allowed nav items?

Thanks for the feedback! Am really loving Discourse so far and hope to build out a couple more plugins. An events plugin would probably be next for me, but I’ll also flesh this out more as well. Keep up the good work!


(Sam Bauch) #4

I decided to take a crack at this, and think I have it, but am I bit concerned about testing.

Essentially the method needs to write to nav_item.js, but I’m not sure of a way to do this without actually writing to the file.

Currently I implemented a way to reset the validNavItems to the default value. Definitely could use some feedback, will PR shortly.


(Piotr Szal) #5

I updated the plugin from @SBauch, so it is working now with the new plugin engine from discourse.

But I cant display the default navigation in the top of the /directory site.
What I have to do?

My experience in Ember.js is low.


(Piotr Szal) #6

Hello,

I try to implement the endless page feature from topic/posts in the user directory plugin. The Rails section is ready and deliver same data structure as the topics_controller.rb.

In my directory_route.js I get the userStream data from the PreloadStore, but the data is not accessible in my directory.js.handlebars.

Can someone help me? Why is postStream accessible in the topic.js.handlebars but my userStream in directory.js.handlebars isnt?


(Piotr Szal) #7

Hello,

the plugin have now an infinite page and loads the first active 1000 users in bunch of 20 user.
I have to clean up the code.

How to test a plugin which uses methods from main project?


(Ehsan) #8

When using the Docker installation, this plugin gets removed every time I upgrade. I assume it’s because of the manual code changes it requires for installation. Is there any way around this?


(Sam Saffron) #9

Look at the container config, you add plugins there:

Eg:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git

^^^ Adds docker manager.

Is there any way we can improve documentation here? Pull request?


(Ehsan) #10

There’s no issue with having the plugin get cloned, but installation of the plugin requires modifying site_settings.yml and lib/discourse.rb in order to add items to the top menu. I would have thought plugins could do that without having to modify Discourse code or config files.


(Sam Saffron) #11

This plugin needs to be fixed, there should be no need to do that


(Piotr Szal) #12

@ehsan should be fixed now.


(Lisa Wess) #13

I am curious about this plugin. Does anyone have a demo/screenshot of what it looks like?

Thank you!


(Sol) #14

Please post more information like demo/screenshots, please :slight_smile: