mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:02:46 +08:00
FIX: user avatar urls need to be absolute in wordpress api
This commit is contained in:
parent
d69472c9fb
commit
e6841d0849
14
app/serializers/post_wordpress_serializer.rb
Normal file
14
app/serializers/post_wordpress_serializer.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
# The most basic attributes of a topic that we need to create a link for it.
|
||||
class PostWordpressSerializer < BasicPostSerializer
|
||||
|
||||
include UrlHelper
|
||||
|
||||
def avatar_template
|
||||
if object.user
|
||||
absolute object.user.avatar_template
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -6,8 +6,8 @@ class TopicViewWordpressSerializer < ApplicationSerializer
|
|||
:filtered_posts_count,
|
||||
:posts
|
||||
|
||||
has_many :participants, serializer: BasicUserSerializer, embed: :objects
|
||||
has_many :posts, serializer: BasicPostSerializer, embed: :objects
|
||||
has_many :participants, serializer: UserWordpressSerializer, embed: :objects
|
||||
has_many :posts, serializer: PostWordpressSerializer, embed: :objects
|
||||
|
||||
def id
|
||||
object.topic.id
|
||||
|
|
13
app/serializers/user_wordpress_serializer.rb
Normal file
13
app/serializers/user_wordpress_serializer.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class UserWordpressSerializer < BasicUserSerializer
|
||||
|
||||
include UrlHelper
|
||||
|
||||
def avatar_template
|
||||
if Hash === object
|
||||
absolute User.avatar_template(user[:username], user[:uploaded_avatar_id])
|
||||
else
|
||||
absolute object.avatar_template
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -24,7 +24,7 @@ describe TopicsController do
|
|||
post = json['posts'][0]
|
||||
post['id'].should == p2.id
|
||||
post['username'].should == user.username
|
||||
post['avatar_template'].should == user.avatar_template
|
||||
post['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}"
|
||||
post['name'].should == user.name
|
||||
post['created_at'].should be_present
|
||||
post['cooked'].should == p2.cooked
|
||||
|
@ -34,7 +34,7 @@ describe TopicsController do
|
|||
participant = json['participants'][0]
|
||||
participant['id'].should == user.id
|
||||
participant['username'].should == user.username
|
||||
participant['avatar_template'].should == user.avatar_template
|
||||
participant['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user