mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
Let's not show tons of extra information about invites unless you're the
person who invited them.
This commit is contained in:
parent
e7ae0bba5f
commit
539890afdf
@ -6,7 +6,13 @@
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.UserInvitedController = Ember.ArrayController.extend({
|
||||
Discourse.UserInvitedController = Ember.ObjectController.extend({
|
||||
user: null,
|
||||
|
||||
init: function() {
|
||||
this._super();
|
||||
this.set('searchTerm', '');
|
||||
},
|
||||
|
||||
/**
|
||||
Observe the search term box with a debouncer and change the results.
|
||||
@ -44,8 +50,8 @@ Discourse.UserInvitedController = Ember.ArrayController.extend({
|
||||
@property showSearch
|
||||
**/
|
||||
showSearch: function() {
|
||||
return !(Em.isNone(this.get('searchTerm')) && this.get('model.length') === 0);
|
||||
}.property('searchTerm', 'model.length'),
|
||||
return !(Em.isNone(this.get('searchTerm')) && this.get('invites.length') === 0);
|
||||
}.property('searchTerm', 'invites.length'),
|
||||
|
||||
/**
|
||||
Were the results limited by our `maxInvites`
|
||||
@ -53,8 +59,8 @@ Discourse.UserInvitedController = Ember.ArrayController.extend({
|
||||
@property truncated
|
||||
**/
|
||||
truncated: function() {
|
||||
return this.get('model.length') === Discourse.SiteSettings.invites_shown;
|
||||
}.property('model.length'),
|
||||
return this.get('invites.length') === Discourse.SiteSettings.invites_shown;
|
||||
}.property('invites.length'),
|
||||
|
||||
actions: {
|
||||
|
||||
|
@ -36,9 +36,11 @@ Discourse.Invite.reopenClass({
|
||||
if (!Em.isNone(filter)) { data.filter = filter; }
|
||||
|
||||
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited.json", {data: data}).then(function (result) {
|
||||
return result.map(function (i) {
|
||||
result.invites = result.invites.map(function (i) {
|
||||
return Discourse.Invite.create(i);
|
||||
});
|
||||
|
||||
return Em.Object.create(result);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,42 +12,46 @@
|
||||
</form>
|
||||
{{/if}}
|
||||
|
||||
{{#if model}}
|
||||
{{#if model.invites}}
|
||||
<table class='table'>
|
||||
<tr>
|
||||
<th>{{i18n user.invited.user}}</th>
|
||||
<th>{{i18n user.invited.redeemed_at}}</th>
|
||||
<th>{{i18n user.last_seen}}</th>
|
||||
<th>{{i18n user.invited.topics_entered}}</th>
|
||||
<th>{{i18n user.invited.posts_read_count}}</th>
|
||||
<th>{{i18n user.invited.time_read}}</th>
|
||||
<th>{{i18n user.invited.days_visited}}</th>
|
||||
{{#if can_see_invite_details}}
|
||||
<th>{{i18n user.last_seen}}</th>
|
||||
<th>{{i18n user.invited.topics_entered}}</th>
|
||||
<th>{{i18n user.invited.posts_read_count}}</th>
|
||||
<th>{{i18n user.invited.time_read}}</th>
|
||||
<th>{{i18n user.invited.days_visited}}</th>
|
||||
{{/if}}
|
||||
</tr>
|
||||
{{#each model}}
|
||||
{{#each invite in model.invites}}
|
||||
<tr>
|
||||
{{#if user}}
|
||||
<td>
|
||||
{{#link-to 'user' user}}{{avatar user imageSize="tiny"}}{{/link-to}}
|
||||
{{#link-to 'user' user}}{{user.username}}{{/link-to}}
|
||||
</td>
|
||||
<td>{{unboundDate redeemed_at}}</td>
|
||||
<td>{{unboundDate user.last_seen_at}}</td>
|
||||
<td>{{number user.topics_entered}}</td>
|
||||
<td>{{number user.posts_read_count}}</td>
|
||||
<td>{{{unbound user.time_read}}}</td>
|
||||
<td><span title="{{i18n user.invited.days_visited}}">{{{unbound user.days_visited}}}</span>
|
||||
/
|
||||
<span title="{{i18n user.invited.account_age_days}}">{{{unbound user.days_since_created}}}</span></td>
|
||||
{{#if invite.user}}
|
||||
<td>
|
||||
{{#link-to 'user' invite.user}}{{avatar invite.user imageSize="tiny"}}{{/link-to}}
|
||||
{{#link-to 'user' invite.user}}{{invite.user.username}}{{/link-to}}
|
||||
</td>
|
||||
<td>{{unboundDate invite.redeemed_at}}</td>
|
||||
{{#if can_see_invite_details}}
|
||||
<td>{{unboundDate invite.user.last_seen_at}}</td>
|
||||
<td>{{number invite.user.topics_entered}}</td>
|
||||
<td>{{number invite.user.posts_read_count}}</td>
|
||||
<td>{{{unbound invite.user.time_read}}}</td>
|
||||
<td><span title="{{i18n user.invited.days_visited}}">{{{unbound invite.user.days_visited}}}</span>
|
||||
/
|
||||
<span title="{{i18n user.invited.account_age_days}}">{{{unbound invite.user.days_since_created}}}</span></td>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<td>{{unbound email}}</td>
|
||||
<td>{{unbound invite.email}}</td>
|
||||
<td colspan='6'>
|
||||
{{#if expired}}
|
||||
{{#if invite.expired}}
|
||||
{{i18n user.invited.expired}}
|
||||
{{/if}}
|
||||
{{#if rescinded}}
|
||||
{{#if invite.rescinded}}
|
||||
{{i18n user.invited.rescinded}}
|
||||
{{else}}
|
||||
<button class='btn' {{action rescind this}}>{{i18n user.invited.rescind}}</button>
|
||||
<button class='btn' {{action rescind invite}}>{{i18n user.invited.rescind}}</button>
|
||||
{{/if}}
|
||||
</td>
|
||||
{{/if}}
|
||||
|
@ -68,15 +68,15 @@ class UsersController < ApplicationController
|
||||
def invited
|
||||
inviter = fetch_user_from_params
|
||||
|
||||
invites = if guardian.can_see_pending_invites_from?(inviter)
|
||||
invites = if guardian.can_see_invite_details?(inviter)
|
||||
Invite.find_all_invites_from(inviter)
|
||||
else
|
||||
Invite.find_redeemed_invites_from(inviter)
|
||||
end
|
||||
|
||||
invites = invites.filter_by(params[:filter])
|
||||
|
||||
render_serialized(invites.to_a, InviteSerializer)
|
||||
render_json_dump invites: serialize_data(invites.to_a, InviteSerializer),
|
||||
can_see_invite_details: guardian.can_see_invite_details?(inviter)
|
||||
end
|
||||
|
||||
def is_local_username
|
||||
|
@ -1,7 +1,6 @@
|
||||
class InviteSerializer < ApplicationSerializer
|
||||
|
||||
attributes :email, :created_at, :redeemed_at, :expired
|
||||
has_one :user, embed: :objects, serializer: InvitedUserSerializer
|
||||
attributes :email, :created_at, :redeemed_at, :expired, :user
|
||||
|
||||
def include_email?
|
||||
!object.redeemed?
|
||||
@ -11,4 +10,10 @@ class InviteSerializer < ApplicationSerializer
|
||||
object.expired?
|
||||
end
|
||||
|
||||
def user
|
||||
ser = InvitedUserSerializer.new(object.user, scope: scope, root: false)
|
||||
ser.invited_by = object.invited_by
|
||||
ser.as_json
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -7,24 +7,46 @@ class InvitedUserSerializer < BasicUserSerializer
|
||||
:days_visited,
|
||||
:days_since_created
|
||||
|
||||
attr_accessor :invited_by
|
||||
|
||||
def time_read
|
||||
AgeWords.age_words(object.user_stat.time_read)
|
||||
end
|
||||
|
||||
def include_time_read?
|
||||
scope.can_see_invite_details?(invited_by)
|
||||
end
|
||||
|
||||
def days_visited
|
||||
object.user_stat.days_visited
|
||||
end
|
||||
|
||||
def include_days_visited?
|
||||
scope.can_see_invite_details?(invited_by)
|
||||
end
|
||||
|
||||
def topics_entered
|
||||
object.user_stat.topics_entered
|
||||
end
|
||||
|
||||
def include_topics_entered?
|
||||
scope.can_see_invite_details?(invited_by)
|
||||
end
|
||||
|
||||
def posts_read_count
|
||||
object.user_stat.posts_read_count
|
||||
end
|
||||
|
||||
def include_posts_read_count?
|
||||
scope.can_see_invite_details?(invited_by)
|
||||
end
|
||||
|
||||
def days_since_created
|
||||
((Time.now - object.created_at) / 60 / 60 / 24).ceil
|
||||
end
|
||||
|
||||
def include_days_since_created
|
||||
scope.can_see_invite_details?(invited_by)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -176,7 +176,7 @@ class Guardian
|
||||
@user.approved?
|
||||
end
|
||||
|
||||
def can_see_pending_invites_from?(user)
|
||||
def can_see_invite_details?(user)
|
||||
is_me?(user)
|
||||
end
|
||||
|
||||
|
@ -1108,18 +1108,18 @@ describe Guardian do
|
||||
end
|
||||
end
|
||||
|
||||
context "can_see_pending_invites_from?" do
|
||||
context "can_see_invite_details?" do
|
||||
|
||||
it 'is false without a logged in user' do
|
||||
Guardian.new(nil).can_see_pending_invites_from?(user).should be_false
|
||||
Guardian.new(nil).can_see_invite_details?(user).should be_false
|
||||
end
|
||||
|
||||
it 'is false without a user to look at' do
|
||||
Guardian.new(user).can_see_pending_invites_from?(nil).should be_false
|
||||
Guardian.new(user).can_see_invite_details?(nil).should be_false
|
||||
end
|
||||
|
||||
it 'is true when looking at your own invites' do
|
||||
Guardian.new(user).can_see_pending_invites_from?(user).should be_true
|
||||
Guardian.new(user).can_see_invite_details?(user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -835,7 +835,7 @@ describe UsersController do
|
||||
|
||||
xhr :get, :invited, username: inviter.username, filter: 'billybob'
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to have(1).item
|
||||
expect(invites.first).to include('email' => 'billybob@example.com')
|
||||
end
|
||||
@ -857,7 +857,7 @@ describe UsersController do
|
||||
|
||||
xhr :get, :invited, username: inviter.username, filter: 'billybob'
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to have(1).item
|
||||
expect(invites.first).to include('email' => 'billybob@example.com')
|
||||
end
|
||||
@ -870,7 +870,7 @@ describe UsersController do
|
||||
|
||||
xhr :get, :invited, username: inviter.username
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to be_empty
|
||||
end
|
||||
end
|
||||
@ -883,7 +883,7 @@ describe UsersController do
|
||||
|
||||
xhr :get, :invited, username: inviter.username
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to have(1).item
|
||||
expect(invites.first).to include('email' => invite.email)
|
||||
end
|
||||
@ -898,13 +898,13 @@ describe UsersController do
|
||||
inviter = Fabricate(:user)
|
||||
invite = Fabricate(:invite, invited_by: inviter)
|
||||
stub_guardian(user) do |guardian|
|
||||
guardian.stubs(:can_see_pending_invites_from?).
|
||||
guardian.stubs(:can_see_invite_details?).
|
||||
with(inviter).returns(true)
|
||||
end
|
||||
|
||||
xhr :get, :invited, username: inviter.username
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to have(1).item
|
||||
expect(invites.first).to include("email" => invite.email)
|
||||
end
|
||||
@ -917,14 +917,14 @@ describe UsersController do
|
||||
invitee = Fabricate(:user)
|
||||
Fabricate(:invite, invited_by: inviter)
|
||||
stub_guardian(user) do |guardian|
|
||||
guardian.stubs(:can_see_pending_invites_from?).
|
||||
guardian.stubs(:can_see_invite_details?).
|
||||
with(inviter).returns(false)
|
||||
end
|
||||
|
||||
xhr :get, :invited, username: inviter.username
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
expect(invites).to be_empty
|
||||
json = JSON.parse(response.body)['invites']
|
||||
expect(json).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -938,7 +938,7 @@ describe UsersController do
|
||||
|
||||
xhr :get, :invited, username: inviter.username
|
||||
|
||||
invites = JSON.parse(response.body)
|
||||
invites = JSON.parse(response.body)['invites']
|
||||
expect(invites).to have(1).item
|
||||
expect(invites.first).to include('email' => invite.email)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user