From 91c5f928c22289ffaccf349543ec1ff5694274c4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 2 Oct 2017 16:50:27 +0800 Subject: [PATCH] FIX: `Group#mentionable` and `Group#messageable` not fully working. --- .../javascripts/discourse/components/composer-editor.js.es6 | 6 +++++- app/assets/javascripts/discourse/controllers/group.js.es6 | 6 +++--- app/serializers/group_show_serializer.rb | 6 +++++- test/javascripts/acceptance/groups-test.js.es6 | 2 +- test/javascripts/fixtures/group-fixtures.js.es6 | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 4a5de6d738b..8445b9f8a56 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -85,7 +85,11 @@ export default Ember.Component.extend({ const $input = this.$('.d-editor-input'); $input.autocomplete({ template: findRawTemplate('user-selector-autocomplete'), - dataSource: term => userSearch({ term, topicId, includeGroups: true }), + dataSource: term => userSearch({ + term, + topicId, + includeMentionableGroups: true + }), key: "@", transformComplete: v => v.username || v.name }); diff --git a/app/assets/javascripts/discourse/controllers/group.js.es6 b/app/assets/javascripts/discourse/controllers/group.js.es6 index d38f15290ec..4734ac8db45 100644 --- a/app/assets/javascripts/discourse/controllers/group.js.es6 +++ b/app/assets/javascripts/discourse/controllers/group.js.es6 @@ -48,9 +48,9 @@ export default Ember.Controller.extend({ }; }, - @computed("model.mentionable") - displayGroupMessageButton(mentionable) { - return this.currentUser && mentionable; + @computed("model.messageable") + displayGroupMessageButton(messageable) { + return this.currentUser && messageable; }, @observes('model.user_count') diff --git a/app/serializers/group_show_serializer.rb b/app/serializers/group_show_serializer.rb index 933111b71c1..e97d49e9eb6 100644 --- a/app/serializers/group_show_serializer.rb +++ b/app/serializers/group_show_serializer.rb @@ -1,5 +1,5 @@ class GroupShowSerializer < BasicGroupSerializer - attributes :is_group_user, :is_group_owner, :mentionable + attributes :is_group_user, :is_group_owner, :mentionable, :messageable def include_is_group_user? authenticated? @@ -21,6 +21,10 @@ class GroupShowSerializer < BasicGroupSerializer authenticated? end + def include_messageable? + authenticated? + end + def mentionable Group.mentionable(scope.user).exists?(id: object.id) end diff --git a/test/javascripts/acceptance/groups-test.js.es6 b/test/javascripts/acceptance/groups-test.js.es6 index 0038ff093a2..65ead1b17d6 100644 --- a/test/javascripts/acceptance/groups-test.js.es6 +++ b/test/javascripts/acceptance/groups-test.js.es6 @@ -132,7 +132,7 @@ QUnit.test("Admin Viewing Group", assert => { andThen(() => { assert.ok(find(".nav-pills li a[title='Edit Group']").length === 1, 'it should show edit group tab if user is admin'); assert.ok(find(".nav-pills li a[title='Logs']").length === 1, 'it should show Logs tab if user is admin'); - + assert.equal(count('.group-message-button'), 1, 'it displays show group message button'); assert.equal(find('.group-info-name').text(), 'Awesome Team', 'it should display the group name'); }); diff --git a/test/javascripts/fixtures/group-fixtures.js.es6 b/test/javascripts/fixtures/group-fixtures.js.es6 index 291db11d23d..78aab0abf8f 100644 --- a/test/javascripts/fixtures/group-fixtures.js.es6 +++ b/test/javascripts/fixtures/group-fixtures.js.es6 @@ -12,7 +12,8 @@ export default { "public_exit":true, "flair_url": 'fa-adjust', "is_group_owner":true, - "mentionable":true + "mentionable":true, + "messageable":true } }, "/groups/discourse/counts.json":{