mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 15:19:46 +08:00
FEATURE: allow group members to see all messages on group page
This commit is contained in:
parent
b781b6aea3
commit
3aa5129f54
@ -27,23 +27,13 @@ export default Ember.Controller.extend({
|
||||
this.get('tabs').forEach(tab => {
|
||||
tab.set('active', showing === tab.get('name'));
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
tabs: [
|
||||
Tab.create({
|
||||
active: true,
|
||||
name: 'posts',
|
||||
'location': 'group.index'
|
||||
}),
|
||||
Tab.create({
|
||||
name: 'topics'
|
||||
}),
|
||||
Tab.create({
|
||||
name: 'mentions'
|
||||
}),
|
||||
Tab.create({
|
||||
name: 'members'
|
||||
})
|
||||
Tab.create({ name: 'posts', active: true, 'location': 'group.index' }),
|
||||
Tab.create({ name: 'topics' }),
|
||||
Tab.create({ name: 'mentions' }),
|
||||
Tab.create({ name: 'members' }),
|
||||
Tab.create({ name: 'messages' }),
|
||||
]
|
||||
});
|
||||
|
@ -1,20 +1,21 @@
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
loading: false,
|
||||
limit: null,
|
||||
offset: null,
|
||||
|
||||
isOwner: function() {
|
||||
@computed('model.owners.@each')
|
||||
isOwner(owners) {
|
||||
if (this.get('currentUser.admin')) {
|
||||
return true;
|
||||
}
|
||||
const owners = this.get('model.owners');
|
||||
const currentUserId = this.get('currentUser.id');
|
||||
if (currentUserId) {
|
||||
return !!owners.findBy('id', currentUserId);
|
||||
}
|
||||
}.property('model.owners.@each'),
|
||||
},
|
||||
|
||||
actions: {
|
||||
removeMember(user) {
|
||||
|
@ -127,8 +127,8 @@ const Group = Discourse.Model.extend({
|
||||
var data = {};
|
||||
if (opts.beforePostId) { data.before_post_id = opts.beforePostId; }
|
||||
|
||||
return Discourse.ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(function (posts) {
|
||||
return posts.map(function (p) {
|
||||
return Discourse.ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
|
||||
return posts.map(p => {
|
||||
p.user = Discourse.User.create(p.user);
|
||||
return Em.Object.create(p);
|
||||
});
|
||||
|
@ -51,6 +51,7 @@ export default function() {
|
||||
this.route('topics');
|
||||
this.route('mentions');
|
||||
this.route('members');
|
||||
this.route('messages');
|
||||
});
|
||||
|
||||
// User routes
|
||||
|
@ -0,0 +1,11 @@
|
||||
export default Discourse.Route.extend({
|
||||
|
||||
model() {
|
||||
return this.modelFor("group").findPosts({type: 'messages'});
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
controller.set("model", model);
|
||||
this.controllerFor("group").set("showing", "messages");
|
||||
}
|
||||
});
|
@ -2,13 +2,12 @@
|
||||
<section class='user-navigation'>
|
||||
<ul class='action-list nav-stacked'>
|
||||
{{#each tabs as |tab|}}
|
||||
<li class="{{if tab.active 'active'}}">
|
||||
{{#link-to tab.location model}}{{tab.name}}
|
||||
{{#if tab.count}}
|
||||
<span class='count'>({{tab.count}})</span>
|
||||
{{/if}}
|
||||
{{/link-to}}
|
||||
</li>
|
||||
<li class="{{if tab.active 'active'}}">
|
||||
{{#link-to tab.location model}}
|
||||
{{tab.name}}
|
||||
{{#if tab.count}}<span class='count'>({{tab.count}})</span>{{/if}}
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</section>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<div class='user-stream'>
|
||||
{{#each controller as |post|}}
|
||||
{{group-post post=post}}
|
||||
{{else}}
|
||||
<div>{{i18n "groups.empty.posts"}}</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
@ -15,27 +15,28 @@
|
||||
<th></th>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{#each model.members as |m|}}
|
||||
<tr>
|
||||
<td class='avatar'>{{user-small user=m}}
|
||||
{{#if m.owner}}
|
||||
<span class='is-owner'>{{i18n "groups.owner"}}</span>
|
||||
{{/if}}
|
||||
</td>
|
||||
<td>
|
||||
<span class="text">{{bound-date m.last_posted_at}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="text">{{bound-date m.last_seen_at}}</span>
|
||||
</td>
|
||||
{{#if isOwner}}
|
||||
<td class='remove-user'>
|
||||
{{#unless m.owner}}
|
||||
<a class="remove-link" {{action "removeMember" m}}><i class="fa fa-times"></i></a>
|
||||
{{/unless}}
|
||||
{{#each model.members as |m|}}
|
||||
<tr>
|
||||
<td class='avatar'>
|
||||
{{user-small user=m}}
|
||||
{{#if m.owner}}<span class='is-owner'>{{i18n "groups.owner"}}</span>{{/if}}
|
||||
</td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
<td>
|
||||
<span class="text">{{bound-date m.last_posted_at}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="text">{{bound-date m.last_seen_at}}</span>
|
||||
</td>
|
||||
{{#if isOwner}}
|
||||
<td class='remove-user'>
|
||||
{{#unless m.owner}}
|
||||
<a class="remove-link" {{action "removeMember" m}}><i class="fa fa-times"></i></a>
|
||||
{{/unless}}
|
||||
</td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
{{else}}
|
||||
<div>{{i18n "groups.empty.users"}}</div>
|
||||
{{/if}}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<div class='user-stream'>
|
||||
{{#each controller as |post|}}
|
||||
{{group-post post=post}}
|
||||
{{else}}
|
||||
<div>{{i18n "groups.empty.mentions"}}</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
<div class='user-stream'>
|
||||
{{#each controller as |post|}}
|
||||
{{group-post post=post}}
|
||||
{{else}}
|
||||
<div>{{i18n "groups.empty.messages"}}</div>
|
||||
{{/each}}
|
||||
</div>
|
@ -1,5 +1,7 @@
|
||||
<div class='user-stream'>
|
||||
{{#each controller as |post|}}
|
||||
{{group-post post=post}}
|
||||
{{else}}
|
||||
<div>{{i18n "groups.empty.topics"}}</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
@ -6,10 +6,19 @@ class GroupsController < ApplicationController
|
||||
|
||||
def counts
|
||||
group = find_group(:group_id)
|
||||
render json: {counts: { posts: group.posts_for(guardian).count,
|
||||
topics: group.posts_for(guardian).where(post_number: 1).count,
|
||||
mentions: group.mentioned_posts_for(guardian).count,
|
||||
members: group.users.count } }
|
||||
|
||||
counts = {
|
||||
posts: group.posts_for(guardian).count,
|
||||
topics: group.posts_for(guardian).where(post_number: 1).count,
|
||||
mentions: group.mentioned_posts_for(guardian).count,
|
||||
members: group.users.count,
|
||||
}
|
||||
|
||||
if guardian.can_see_group_messages?(group)
|
||||
counts[:messages] = group.messages_for(guardian).where(post_number: 1).count
|
||||
end
|
||||
|
||||
render json: { counts: counts }
|
||||
end
|
||||
|
||||
def posts
|
||||
@ -30,6 +39,15 @@ class GroupsController < ApplicationController
|
||||
render_serialized posts.to_a, GroupPostSerializer
|
||||
end
|
||||
|
||||
def messages
|
||||
group = find_group(:group_id)
|
||||
posts = if guardian.can_see_group_messages?(group)
|
||||
group.messages_for(guardian, params[:before_post_id]).where(post_number: 1).limit(20).to_a
|
||||
else
|
||||
[]
|
||||
end
|
||||
render_serialized posts, GroupPostSerializer
|
||||
end
|
||||
|
||||
def members
|
||||
group = find_group(:group_id)
|
||||
@ -114,8 +132,4 @@ class GroupsController < ApplicationController
|
||||
group
|
||||
end
|
||||
|
||||
def the_group
|
||||
@the_group ||= find_group(:group_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -85,8 +85,10 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def posts_for(guardian, before_post_id=nil)
|
||||
user_ids = group_users.map {|gu| gu.user_id}
|
||||
result = Post.where(user_id: user_ids).includes(:user, :topic, :topic => :category).references(:posts, :topics, :category)
|
||||
user_ids = group_users.map { |gu| gu.user_id }
|
||||
result = Post.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
.where(user_id: user_ids)
|
||||
.where('topics.archetype <> ?', Archetype.private_message)
|
||||
.where(post_type: Post.types[:regular])
|
||||
|
||||
@ -95,9 +97,21 @@ class Group < ActiveRecord::Base
|
||||
result.order('posts.created_at desc')
|
||||
end
|
||||
|
||||
def messages_for(guardian, before_post_id=nil)
|
||||
result = Post.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
.where('topics.archetype = ?', Archetype.private_message)
|
||||
.where(post_type: Post.types[:regular])
|
||||
.where('topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)', self.id)
|
||||
|
||||
result = guardian.filter_allowed_categories(result)
|
||||
result = result.where('posts.id < ?', before_post_id) if before_post_id
|
||||
result.order('posts.created_at desc')
|
||||
end
|
||||
|
||||
def mentioned_posts_for(guardian, before_post_id=nil)
|
||||
result = Post.joins(:group_mentions)
|
||||
.includes(:user, :topic, :topic => :category)
|
||||
.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
.where('topics.archetype <> ?', Archetype.private_message)
|
||||
.where(post_type: Post.types[:regular])
|
||||
@ -113,9 +127,7 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.refresh_automatic_group!(name)
|
||||
|
||||
id = AUTO_GROUPS[name]
|
||||
return unless id
|
||||
return unless id = AUTO_GROUPS[name]
|
||||
|
||||
unless group = self.lookup_group(name)
|
||||
group = Group.new(name: name.to_s, automatic: true)
|
||||
|
@ -330,6 +330,12 @@ en:
|
||||
other: "%{count} users"
|
||||
|
||||
groups:
|
||||
empty:
|
||||
posts: "There is no post by members of this group."
|
||||
members: "There is no member in this group."
|
||||
mentions: "There is no mention of this group."
|
||||
messages: "There is no message for this group."
|
||||
topics: "There is no topic by members of this group."
|
||||
add: "Add"
|
||||
selector_placeholder: "Add members"
|
||||
owner: "owner"
|
||||
|
@ -344,6 +344,7 @@ Discourse::Application.routes.draw do
|
||||
get 'posts'
|
||||
get 'topics'
|
||||
get 'mentions'
|
||||
get 'messages'
|
||||
get 'counts'
|
||||
|
||||
member do
|
||||
|
@ -5,7 +5,11 @@ module GroupGuardian
|
||||
# Automatic groups are not represented in the GROUP_USERS
|
||||
# table and thus do not allow membership changes.
|
||||
def can_edit_group?(group)
|
||||
(group.users.where('group_users.owner').include?(user) || is_admin?) && !group.automatic
|
||||
(is_admin? || group.users.where('group_users.owner').include?(user)) && !group.automatic
|
||||
end
|
||||
|
||||
def can_see_group_messages?(group)
|
||||
is_admin? || group.users.include?(user)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user