Skip to content

Commit

Permalink
Allow disabling categories via site setting
Browse files Browse the repository at this point in the history
  • Loading branch information
gdpelican committed Jan 17, 2018
1 parent 1bea756 commit b585bb3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Feel free to style elements underneath the `.retort-picker` class in `Admin > Cu

There's an additional site setting, 'retort allow multiple reactions', which determines whether users can react to a single post multiple times or not. (It is enabled by default). If you only want users to be able to create one reaction per post (if you're using Retort as a voting system, for example), set this option to false.

### Disabling retort for particular categories

The 'retort disabled categories' site setting allows disabling particular reacting in particular categories by name. These category names are case-insensitive.

For example, entering `staff|announcements` into this field will disallow all users from reacting to topics in the categories name 'Staff' or 'Announcements'.

### Contributing

Pull requests welcome! To contribute:
Expand Down
7 changes: 6 additions & 1 deletion assets/javascripts/discourse/initializers/retort-init.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ function initializePlugin(api) {
})

api.decorateWidget('post-contents:after-cooked', helper => {
let post = Retort.postFor(helper.getModel().id)
let postId = helper.getModel().id
let post = Retort.postFor(postId)

if (Retort.disabledFor(postId)) { return }

Retort.storeWidget(helper)

return _.map(post.retorts, (retort) => {
Expand All @@ -30,6 +34,7 @@ function initializePlugin(api) {
if (!Discourse.User.current() || !siteSettings.retort_enabled) { return }

api.addPostMenuButton('retort', attrs => {
if (Retort.disabledFor(attrs.id)) { return }
return {
action: 'clickRetort',
icon: 'smile-o',
Expand Down
7 changes: 7 additions & 0 deletions assets/javascripts/discourse/lib/retort.js.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ajax } from 'discourse/lib/ajax'

const disabledCategories = Discourse.SiteSettings.retort_disabled_categories.split('|')

export default Ember.Object.create({

callback(data) {
Expand All @@ -23,6 +25,11 @@ export default Ember.Object.create({
})
},

disabledFor(postId) {
let categoryName = this.postFor(postId).get('topic.category.name') || ''
return _.contains(disabledCategories, categoryName.toLowerCase())
},

openPicker(post) {
this.set('picker.active', true)
this.set('picker.postId', post.id)
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ en:
retort_allowed_emojis: "List out the emojis you'd like to allow, separated by the '|' character"
retort_emojis_per_row: "Select how many custom emojis will appear per row (Leave blank to have them all appear in a single row)"
retort_allow_multiple_reactions: "Allow users to react multiple times to the same post"
retort_disabled_categories: "List out the categories you'd like to DISABLE retort for, separated by the '|' character"
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ plugins:
client: true
retort_allow_multiple_reactions:
default: true
retort_disabled_categories:
default: ""
client: true

0 comments on commit b585bb3

Please sign in to comment.