FIX: If you don't have permission to onebox a post, just show the link instead of crashing out

This commit is contained in:
Robin Ward 2013-07-15 15:10:05 -04:00
parent e8f3e7c2e8
commit e83cd9d111

View File

@ -19,9 +19,9 @@ module Oneboxer
case route[:controller]
when 'users'
user = User.where(username_lower: route[:username].downcase).first
return nil unless user
return nil unless user
Guardian.new.ensure_can_see!(user)
return @url unless Guardian.new.can_see?(user)
args.merge! avatar: PrettyText.avatar_img(user.username, 'tiny'), username: user.username
args[:bio] = user.bio_cooked if user.bio_cooked.present?
@ -33,7 +33,7 @@ module Oneboxer
post = Post.where(topic_id: route[:topic_id], post_number: route[:post_number].to_i).first
return nil unless post
Guardian.new.ensure_can_see!(post)
return @url unless Guardian.new.can_see?(post)
topic = post.topic
slug = Slug.for(topic.title)
@ -52,7 +52,8 @@ module Oneboxer
topic = Topic.where(id: route[:topic_id].to_i).includes(:user).first
return nil unless topic
Guardian.new.ensure_can_see!(topic)
return @url unless Guardian.new.can_see?(topic)
post = topic.posts.first
posters = topic.posters_summary.map do |p|