Topic Ratings Plugin


(Ivan Rapekas) #164

Hi @angus, thanks for reply!
My case is:

  1. Only specific group (staff would be enough, let it be) is allowed to add/remove stars
  2. Only staff can see stars
  3. Non-group users should not see any ratings (as this plugin not installed).

The scenario is necessary to rate topics and posts by staff members. It will allow to gather statistics (data explore plugin is used) about the most important conversations, thoughts directions or people. This can help to improve services that we provide to our community via forum.

Unfortunately I had not success to develop this function by myself…


(Angus McLeod) #165

Sorry, just to be sure I’m understanding you, staff will be rating other people’s (normal users) posts?


(Ivan Rapekas) #166

No problem. Yes, staff will rate users’ posts. Also staff users will rate posts the same way both in private categories and categories shared between other registered users.


(François Douville) #167

Great plugin again! :smiley:

  1. Is it possible to hide “no ratings yet” when there is no rating?

  2. Is it possible to have the choice to set, by default, no rating? Now it is by default mark to set a rating. Like this : 22 but with stars like this (without mark) image


(Angus McLeod) #168

Yup, I’ll tackle these a bit later in the week.

Task List

  1. Hide “no ratings” when there is no rating.

  2. Add a setting to not check add a rating by default.

  3. Add a ratings-specific topic list that lists topics by average rating.

  4. Improve the rspec and unit tests.


(Alex Salvador) #169

I have a topic for which I unchecked the “Add à rating” box. However, each time I edit this topic, the “Add a topic” box appears checked again, and I have to uncheck it each time.
Is it possible to keep track of the fact that the box was chosen unchecked upon creation of the topic, and keep this preference by default when editing that topic ?


(Angus McLeod) #170

This should fix your issue.


(pari) #171

I’m having the following error with rating topics:

### Message

NoMethodError (undefined method `to_i' for [3730, 3730]:Array Did you mean? to_s to_a to_h) /var/www/discourse/plugins/discourse-ratings/plugin.rb:104:in `rating_count'

### Backtrace

/var/www/discourse/plugins/discourse-ratings/plugin.rb:104:in `rating_count' /var/www/discourse/plugins/discourse-ratings/plugin.rb:145:in `has_ratings' /var/www/discourse/plugins/discourse-ratings/plugin.rb:129:in `include_average_rating?' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:375:in `include?' (eval):58:in `_fast_attributes' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:468:in `rescue in attributes' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:455:in `attributes' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:480:in `_serializable_hash' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:359:in `serializable_hash' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:347:in `as_json' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/json/encoding.rb:35:in `encode' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/json/encoding.rb:22:in `encode' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/core_ext/object/json.rb:41:in `to_json' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/active_model_serializers-0.8.4/lib/active_model/serializer.rb:331:in `to_json' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/multi_json-1.13.1/lib/multi_json/adapters/oj.rb:40:in `dump' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/multi_json-1.13.1/lib/multi_json/adapters/oj.rb:40:in `dump' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/multi_json-1.13.1/lib/multi_json/adapter.rb:25:in `dump' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/multi_json-1.13.1/lib/multi_json.rb:139:in `dump' /var/www/discourse/app/controllers/application_controller.rb:395:in `render_json_dump' /var/www/discourse/app/controllers/topics_controller.rb:777:in `block (2 levels) in perform_show_response' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/mime_responds.rb:203:in `respond_to' /var/www/discourse/app/controllers/topics_controller.rb:769:in `perform_show_response' /var/www/discourse/app/controllers/topics_controller.rb:128:in `show' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:194:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rendering.rb:30:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:42:in `block in process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:132:in `run_callbacks' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:41:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rescue.rb:22:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in `block in instrument' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications/instrumenter.rb:23:in `instrument' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in `instrument' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:32:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/params_wrapper.rb:256:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.0/lib/active_record/railties/controller_runtime.rb:24:in `process_action' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:134:in `process' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionview-5.2.0/lib/action_view/rendering.rb:32:in `process' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-mini-profiler-1.0.0/lib/mini_profiler/profiling_methods.rb:78:in `block in profile_method' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:191:in `dispatch' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:252:in `dispatch' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:52:in `dispatch' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:34:in `serve' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:52:in `block in serve' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in `each' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in `serve' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:840:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-protection-2.0.2/lib/rack/protection/frame_options.rb:31:in `call' /var/www/discourse/lib/middleware/omniauth_bypass_middleware.rb:24:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/tempfile_reaper.rb:15:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/conditional_get.rb:25:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/head.rb:12:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/http/content_security_policy.rb:18:in `call' /var/www/discourse/lib/middleware/anonymous_cache.rb:200:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:232:in `context' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:226:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/cookies.rb:670:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:98:in `run_callbacks' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:26:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/logster-1.2.9/lib/logster/middleware/reporter.rb:31:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:38:in `call_app' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:28:in `call' /var/www/discourse/config/initializers/100-quiet_logger.rb:16:in `call' /var/www/discourse/config/initializers/100-silence_logger.rb:29:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-mini-profiler-1.0.0/lib/mini_profiler/profiler.rb:174:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/message_bus-2.1.5/lib/message_bus/rack/middleware.rb:63:in `call' /var/www/discourse/lib/middleware/request_tracker.rb:186:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/railtie.rb:190:in `public_send' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/railtie.rb:190:in `method_missing' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:68:in `block in call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `each' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/urlmap.rb:53:in `call' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:606:in `process_client' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:701:in `worker_loop' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:549:in `spawn_missing_workers' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:563:in `maintain_worker_count' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:293:in `join' /var/www/discourse/vendor/bundle/ruby/2.4.0/gems/unicorn-5.4.0/bin/unicorn:126:in `<top (required)>' /var/www/discourse/vendor/bundle/ruby/2.4.0/bin/unicorn:23:in `load' /var/www/discourse/vendor/bundle/ruby/2.4.0/bin/unicorn:23:in `<main>'

### Env

hostname talk-app
process_id 2810
application_version 4b2e42757d00556468ec82047a8fcc723b087e1a
HTTP_HOST talk.zabanshenas.com
REQUEST_URI /t/540.json?api_key=1d4d600b283c1e2b3f7092ccbc51ba8fabe0040991d57f978b30bccef1695b95&api_username=pompi
REQUEST_METHOD GET
HTTP_ACCEPT */*
HTTP_X_FORWARDED_FOR 5.114.215.8, 5.114.215.8
HTTP_X_REAL_IP 5.114.215.8
username pompi
params api_key 1d4d600b283c1e2b3f7092ccbc51ba8fabe0040991d57f978b30bccef1695b95
--- --- --- ---
--- ---
api_username pompi


(Angus McLeod) #172

This is a strange error. It should not be possible. Nevertheless, I’ve added some logic that handles it. Please update and it should work.


(Sam Saffron) #173

I have seen this before. I feel there is an internal bug we have where we should be allowed to explicitly register a type and then have core enforce it on the way in and the way out.


(Angus McLeod) #174

Yeah, I was thinking the same.