mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
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:
parent
9c93a20cf1
commit
75374c76b3
@ -48,6 +48,11 @@ export default Ember.Controller.extend({
|
||||
};
|
||||
},
|
||||
|
||||
@computed("model.mentionable")
|
||||
displayGroupMessageButton(mentionable) {
|
||||
return this.currentUser && mentionable;
|
||||
},
|
||||
|
||||
@observes('model.user_count')
|
||||
_setMembersTabCount() {
|
||||
this.get('tabs')[0].set('count', this.get('model.user_count'));
|
||||
@ -66,5 +71,11 @@ export default Ember.Controller.extend({
|
||||
|
||||
return canSee;
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
messageGroup() {
|
||||
this.send('createNewMessageViaParams', this.get('model.name'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -43,6 +43,14 @@
|
||||
{{/each}}
|
||||
{{/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'}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,8 +1,8 @@
|
||||
class GroupShowSerializer < BasicGroupSerializer
|
||||
attributes :is_group_user, :is_group_owner
|
||||
attributes :is_group_user, :is_group_owner, :mentionable
|
||||
|
||||
def include_is_group_user?
|
||||
scope.authenticated?
|
||||
authenticated?
|
||||
end
|
||||
|
||||
def is_group_user
|
||||
@ -10,15 +10,27 @@ class GroupShowSerializer < BasicGroupSerializer
|
||||
end
|
||||
|
||||
def include_is_group_owner?
|
||||
scope.authenticated?
|
||||
authenticated?
|
||||
end
|
||||
|
||||
def is_group_owner
|
||||
scope.is_admin? || fetch_group_user&.owner
|
||||
end
|
||||
|
||||
def include_mentionable?
|
||||
authenticated?
|
||||
end
|
||||
|
||||
def mentionable
|
||||
Group.mentionable(scope.user).exists?(id: object.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticated?
|
||||
scope.authenticated?
|
||||
end
|
||||
|
||||
def fetch_group_user
|
||||
@group_user ||= object.group_users.find_by(user: scope.user)
|
||||
end
|
||||
|
@ -421,6 +421,7 @@ en:
|
||||
join: "Join Group"
|
||||
leave: "Leave Group"
|
||||
request: "Request to Join Group"
|
||||
message: "Message"
|
||||
automatic_group: Automatic Group
|
||||
closed_group: Closed Group
|
||||
is_group_user: "You are a member of this group"
|
||||
|
@ -1,6 +1,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe GroupShowSerializer do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
context 'admin user' do
|
||||
let(:user) { Fabricate(:admin) }
|
||||
let(:group) { Fabricate(:group, users: [user]) }
|
||||
@ -14,9 +17,6 @@ describe GroupShowSerializer do
|
||||
end
|
||||
|
||||
context 'group owner' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group) }
|
||||
|
||||
before do
|
||||
group.add_owner(user)
|
||||
end
|
||||
@ -28,4 +28,18 @@ describe GroupShowSerializer do
|
||||
expect(json[:group_show][:is_group_user]).to eq(true)
|
||||
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
|
||||
|
@ -42,12 +42,13 @@ QUnit.test("Browsing Groups", assert => {
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("Viewing Group", assert => {
|
||||
QUnit.test("Anonymous Viewing Group", assert => {
|
||||
visit("/groups/discourse");
|
||||
|
||||
andThen(() => {
|
||||
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-message-button') === 0, 'it does not show group message button');
|
||||
});
|
||||
|
||||
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 => {
|
||||
logIn();
|
||||
Discourse.reset();
|
||||
@ -102,4 +117,4 @@ QUnit.test("Admin Viewing Group", assert => {
|
||||
'it should show messages tab if user is admin'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,11 +6,12 @@ export default {
|
||||
"name":"discourse",
|
||||
"full_name":"Awesome Team",
|
||||
"user_count":8,
|
||||
"alias_level":0,
|
||||
"alias_level":99,
|
||||
"visible":true,
|
||||
"public":true,
|
||||
"flair_url": 'fa-adjust',
|
||||
"is_group_owner":true
|
||||
"is_group_owner":true,
|
||||
"mentionable":true
|
||||
}
|
||||
},
|
||||
"/groups/discourse/counts.json":{
|
||||
|
Loading…
Reference in New Issue
Block a user