UX: Display button to message group on group page.

https://meta.discourse.org/t/make-it-easier-to-send-a-message-to-groups/65065
This commit is contained in:
Guo Xiang Tan 2017-07-27 17:51:25 +09:00
parent 9c93a20cf1
commit 75374c76b3
7 changed files with 72 additions and 10 deletions

View File

@ -48,6 +48,11 @@ export default Ember.Controller.extend({
}; };
}, },
@computed("model.mentionable")
displayGroupMessageButton(mentionable) {
return this.currentUser && mentionable;
},
@observes('model.user_count') @observes('model.user_count')
_setMembersTabCount() { _setMembersTabCount() {
this.get('tabs')[0].set('count', this.get('model.user_count')); this.get('tabs')[0].set('count', this.get('model.user_count'));
@ -66,5 +71,11 @@ export default Ember.Controller.extend({
return canSee; return canSee;
}); });
},
actions: {
messageGroup() {
this.send('createNewMessageViaParams', this.get('model.name'));
}
} }
}); });

View File

@ -43,6 +43,14 @@
{{/each}} {{/each}}
{{/mobile-nav}} {{/mobile-nav}}
{{#if displayGroupMessageButton}}
{{d-button
action="messageGroup"
class="btn-primary group-message-button"
icon="envelope"
label="groups.message"}}
{{/if}}
{{group-membership-button model=model showLogin='showLogin'}} {{group-membership-button model=model showLogin='showLogin'}}
</div> </div>
</div> </div>

View File

@ -1,8 +1,8 @@
class GroupShowSerializer < BasicGroupSerializer class GroupShowSerializer < BasicGroupSerializer
attributes :is_group_user, :is_group_owner attributes :is_group_user, :is_group_owner, :mentionable
def include_is_group_user? def include_is_group_user?
scope.authenticated? authenticated?
end end
def is_group_user def is_group_user
@ -10,15 +10,27 @@ class GroupShowSerializer < BasicGroupSerializer
end end
def include_is_group_owner? def include_is_group_owner?
scope.authenticated? authenticated?
end end
def is_group_owner def is_group_owner
scope.is_admin? || fetch_group_user&.owner scope.is_admin? || fetch_group_user&.owner
end end
def include_mentionable?
authenticated?
end
def mentionable
Group.mentionable(scope.user).exists?(id: object.id)
end
private private
def authenticated?
scope.authenticated?
end
def fetch_group_user def fetch_group_user
@group_user ||= object.group_users.find_by(user: scope.user) @group_user ||= object.group_users.find_by(user: scope.user)
end end

View File

@ -421,6 +421,7 @@ en:
join: "Join Group" join: "Join Group"
leave: "Leave Group" leave: "Leave Group"
request: "Request to Join Group" request: "Request to Join Group"
message: "Message"
automatic_group: Automatic Group automatic_group: Automatic Group
closed_group: Closed Group closed_group: Closed Group
is_group_user: "You are a member of this group" is_group_user: "You are a member of this group"

View File

@ -1,6 +1,9 @@
require 'rails_helper' require 'rails_helper'
describe GroupShowSerializer do describe GroupShowSerializer do
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group) }
context 'admin user' do context 'admin user' do
let(:user) { Fabricate(:admin) } let(:user) { Fabricate(:admin) }
let(:group) { Fabricate(:group, users: [user]) } let(:group) { Fabricate(:group, users: [user]) }
@ -14,9 +17,6 @@ describe GroupShowSerializer do
end end
context 'group owner' do context 'group owner' do
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group) }
before do before do
group.add_owner(user) group.add_owner(user)
end end
@ -28,4 +28,18 @@ describe GroupShowSerializer do
expect(json[:group_show][:is_group_user]).to eq(true) expect(json[:group_show][:is_group_user]).to eq(true)
end end
end end
describe '#mentionable' do
let(:group) { Fabricate(:group, alias_level: Group::ALIAS_LEVELS[:everyone]) }
it 'should return the right value' do
json = GroupShowSerializer.new(group, scope: Guardian.new).as_json
expect(json[:group_show][:mentionable]).to eq(nil)
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
expect(json[:group_show][:mentionable]).to eq(true)
end
end
end end

View File

@ -42,12 +42,13 @@ QUnit.test("Browsing Groups", assert => {
}); });
}); });
QUnit.test("Viewing Group", assert => { QUnit.test("Anonymous Viewing Group", assert => {
visit("/groups/discourse"); visit("/groups/discourse");
andThen(() => { andThen(() => {
assert.ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair"); assert.ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair");
assert.ok(count('.group-members tr') > 0, "it lists group members"); assert.ok(count('.group-members tr') > 0, "it lists group members");
assert.ok(count('.group-message-button') === 0, 'it does not show group message button');
}); });
click(".nav-pills li a[title='Activity']"); click(".nav-pills li a[title='Activity']");
@ -80,6 +81,20 @@ QUnit.test("Viewing Group", assert => {
}); });
}); });
QUnit.test("User Viewing Group", assert => {
logIn();
Discourse.reset();
visit("/groups/discourse");
click('.group-message-button');
andThen(() => {
assert.ok(count('#reply-control') === 1, 'it opens the composer');
assert.equal(find('.ac-wrap .item').text(), 'discourse', 'it prefills the group name');
});
});
QUnit.test("Admin Viewing Group", assert => { QUnit.test("Admin Viewing Group", assert => {
logIn(); logIn();
Discourse.reset(); Discourse.reset();

View File

@ -6,11 +6,12 @@ export default {
"name":"discourse", "name":"discourse",
"full_name":"Awesome Team", "full_name":"Awesome Team",
"user_count":8, "user_count":8,
"alias_level":0, "alias_level":99,
"visible":true, "visible":true,
"public":true, "public":true,
"flair_url": 'fa-adjust', "flair_url": 'fa-adjust',
"is_group_owner":true "is_group_owner":true,
"mentionable":true
} }
}, },
"/groups/discourse/counts.json":{ "/groups/discourse/counts.json":{