"
+ begin
+ copy = "
"
copy << html unless html.nil?
copy << "
"
parser.parse(html) unless html.nil?
@@ -87,7 +87,7 @@ class SearchObserver < ActiveRecord::Observer
end
if attributes["title"]
scrubbed << " "
- scrubbed << attributes["title"]
+ scrubbed << attributes["title"]
scrubbed << " "
end
end
diff --git a/app/models/site.rb b/app/models/site.rb
index ffdc8600e..fe2ec4c61 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -20,10 +20,10 @@ class Site
def trust_levels
TrustLevel.all
end
-
+
def categories
Category.popular
- end
+ end
def archetypes
Archetype.list.reject{|t| t.id==Archetype.private_message}
@@ -35,8 +35,8 @@ class Site
def self.cached_json
# Sam: bumping this way down, SiteSerializer will serialize post actions as well,
- # On my local this was not being flushed as post actions types changed, it turn this
- # broke local.
+ # On my local this was not being flushed as post actions types changed, it turn this
+ # broke local.
Rails.cache.fetch(Site.cache_key, expires_in: 1.minute) do
MultiJson.dump(SiteSerializer.new(Site.new, root: false))
end
diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb
index 4dd77a299..f8946bd3b 100644
--- a/app/models/site_customization.rb
+++ b/app/models/site_customization.rb
@@ -1,26 +1,26 @@
class SiteCustomization < ActiveRecord::Base
-
+
ENABLED_KEY = '7e202ef2-56d7-47d5-98d8-a9c8d15e57dd'
CACHE_PATH = 'stylesheet-cache'
- @lock = Mutex.new
+ @lock = Mutex.new
- before_create do
+ before_create do
self.position ||= (SiteCustomization.maximum(:position) || 0) + 1
self.enabled ||= false
self.key ||= SecureRandom.uuid
true
end
- before_save do
+ before_save do
if self.stylesheet_changed?
- begin
+ begin
self.stylesheet_baked = Sass.compile self.stylesheet
rescue Sass::SyntaxError => e
error = e.sass_backtrace_str("custom stylesheet")
error.gsub!("\n", '\A ')
error.gsub!("'", '\27 ')
-
- self.stylesheet_baked =
+
+ self.stylesheet_baked =
"#main {display: none;}
footer {white-space: pre; margin-left: 100px;}
footer:after{ content: '#{error}' }"
@@ -30,8 +30,8 @@ footer:after{ content: '#{error}' }"
after_save do
if self.stylesheet_changed?
- if File.exists?(self.stylesheet_fullpath)
- File.delete self.stylesheet_fullpath
+ if File.exists?(self.stylesheet_fullpath)
+ File.delete self.stylesheet_fullpath
end
end
self.remove_from_cache!
@@ -43,9 +43,9 @@ footer:after{ content: '#{error}' }"
end
- after_destroy do
- if File.exists?(self.stylesheet_fullpath)
- File.delete self.stylesheet_fullpath
+ after_destroy do
+ if File.exists?(self.stylesheet_fullpath)
+ File.delete self.stylesheet_fullpath
end
self.remove_from_cache!
end
@@ -60,7 +60,7 @@ footer:after{ content: '#{error}' }"
return nil if preview_style == :none
return preview_style if preview_style
- @lock.synchronize do
+ @lock.synchronize do
style = self.where(enabled: true).first
if style
@cache[self.enabled_key] = style.key
@@ -97,14 +97,14 @@ footer:after{ content: '#{error}' }"
def self.lookup_style(key)
return if key.blank?
-
- # cache is cross site resiliant cause key is secure random
+
+ # cache is cross site resiliant cause key is secure random
@cache ||= {}
ensure_cache_listener
style = @cache[key]
return style if style
-
- @lock.synchronize do
+
+ @lock.synchronize do
style = self.where(key: key).first
@cache[key] = style
end
@@ -115,7 +115,7 @@ footer:after{ content: '#{error}' }"
klass = self
MessageBus.subscribe("/site_customization") do |msg|
message = msg.data
- klass.remove_from_cache!(message["key"], false)
+ klass.remove_from_cache!(message["key"], false)
end
@subscribed = true
@@ -125,7 +125,7 @@ footer:after{ content: '#{error}' }"
def self.remove_from_cache!(key, broadcast=true)
MessageBus.publish('/site_customization', {key: key}) if broadcast
if @cache
- @lock.synchronize do
+ @lock.synchronize do
@cache[key] = nil
end
end
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb
index e7b88bed5..efbd0e778 100644
--- a/app/models/site_setting.rb
+++ b/app/models/site_setting.rb
@@ -41,19 +41,19 @@ class SiteSetting < ActiveRecord::Base
# used mainly for dev, force hostname for Discourse.base_url
# You would usually use multisite for this
setting(:force_hostname, '')
- setting(:port, Rails.env.development? ? 3000 : '')
+ setting(:port, Rails.env.development? ? 3000 : '')
setting(:enable_private_messages, true)
setting(:use_ssl, false)
setting(:secret_token)
setting(:restrict_access, false)
setting(:access_password)
setting(:queue_jobs, !Rails.env.test?)
- setting(:crawl_images, !Rails.env.test?)
+ setting(:crawl_images, !Rails.env.test?)
setting(:enable_imgur, false)
setting(:imgur_api_key, '')
setting(:imgur_endpoint, "http://api.imgur.com/2/upload.json")
setting(:max_image_width, 690)
- setting(:category_featured_topics, 6)
+ setting(:category_featured_topics, 6)
setting(:topics_per_page, 30)
setting(:posts_per_page, 20)
setting(:invite_expiry_days, 14)
@@ -83,14 +83,14 @@ class SiteSetting < ActiveRecord::Base
setting(:email_time_window_mins, 5)
-
+
# How many characters we can import into a onebox
setting(:onebox_max_chars, 5000)
setting(:suggested_topics, 5)
setting(:allow_duplicate_topic_titles, false)
-
+
setting(:post_excerpt_maxlength, 300)
setting(:post_onebox_maxlength, 500)
setting(:best_of_score_threshold, 15)
@@ -99,14 +99,14 @@ class SiteSetting < ActiveRecord::Base
setting(:category_post_template,
"[Replace this first paragraph with a short description of your new category. Try to keep it below 200 characters.]\n\nUse this space below for a longer description, as well as to establish any rules or discussion!")
- # we need to think of a way to force users to enter certain settings, this is a minimal config thing
+ # we need to think of a way to force users to enter certain settings, this is a minimal config thing
setting(:notification_email, 'info@discourse.org')
setting(:send_welcome_message, true)
setting(:twitter_consumer_key, '')
setting(:twitter_consumer_secret, '')
-
+
setting(:facebook_app_id, '')
setting(:facebook_app_secret, '')
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 6d6e162a7..6f83b3d33 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -13,20 +13,20 @@ class Topic < ActiveRecord::Base
versioned :if => :new_version_required?
acts_as_paranoid
after_recover :update_flagged_posts_count
- after_destroy :update_flagged_posts_count
+ after_destroy :update_flagged_posts_count
rate_limit :default_rate_limiter
rate_limit :limit_topics_per_day
rate_limit :limit_private_messages_per_day
- validate :title_quality
+ validate :title_quality
validates_presence_of :title
validates :title, length: {in: SiteSetting.min_topic_title_length..SiteSetting.max_topic_title_length}
serialize :meta_data, ActiveRecord::Coders::Hstore
validate :unique_title
-
+
belongs_to :category
has_many :posts
@@ -62,7 +62,7 @@ class Topic < ActiveRecord::Base
# Helps us limit how many favorites can be made in a day
class FavoriteLimiter < RateLimiter
def initialize(user)
- super(user, "favorited:#{Date.today.to_s}", SiteSetting.max_favorites_per_day, 1.day.to_i)
+ super(user, "favorited:#{Date.today.to_s}", SiteSetting.max_favorites_per_day, 1.day.to_i)
end
end
@@ -78,11 +78,11 @@ class Topic < ActiveRecord::Base
after_create do
changed_to_category(category)
TopicUser.change(
- self.user_id, self.id,
+ self.user_id, self.id,
notification_level: TopicUser::NotificationLevel::WATCHING,
notifications_reason_id: TopicUser::NotificationReasons::CREATED_TOPIC
)
- if self.archetype == Archetype.private_message
+ if self.archetype == Archetype.private_message
DraftSequence.next!(self.user, Draft::NEW_PRIVATE_MESSAGE)
else
DraftSequence.next!(self.user, Draft::NEW_TOPIC)
@@ -91,12 +91,12 @@ class Topic < ActiveRecord::Base
# Additional rate limits on topics: per day and private messages per day
def limit_topics_per_day
- RateLimiter.new(user, "topics-per-day:#{Date.today.to_s}", SiteSetting.max_topics_per_day, 1.day.to_i)
+ RateLimiter.new(user, "topics-per-day:#{Date.today.to_s}", SiteSetting.max_topics_per_day, 1.day.to_i)
end
def limit_private_messages_per_day
return unless private_message?
- RateLimiter.new(user, "pms-per-day:#{Date.today.to_s}", SiteSetting.max_private_messages_per_day, 1.day.to_i)
+ RateLimiter.new(user, "pms-per-day:#{Date.today.to_s}", SiteSetting.max_private_messages_per_day, 1.day.to_i)
end
# Validate unique titles if a site setting is set
@@ -120,19 +120,19 @@ class Topic < ActiveRecord::Base
# We don't care about quality on private messages
return if private_message?
- sentinel = TextSentinel.new(title,
- min_entropy: SiteSetting.title_min_entropy,
+ sentinel = TextSentinel.new(title,
+ min_entropy: SiteSetting.title_min_entropy,
max_word_length: SiteSetting.max_word_length,
remove_interior_spaces: true)
if sentinel.valid?
# It's possible the sentinel has cleaned up the title a bit
- self.title = sentinel.text
+ self.title = sentinel.text
else
errors.add(:title, I18n.t(:is_invalid)) unless sentinel.valid?
end
end
-
+
def new_version_required?
return true if title_changed?
return true if category_id_changed?
@@ -147,9 +147,9 @@ class Topic < ActiveRecord::Base
.listable_topics
.topic_list_order
.includes(:user)
- .limit(5)
+ .limit(5)
end
-
+
def update_meta_data(data)
self.meta_data = (self.meta_data || {}).merge(data.stringify_keys)
save
@@ -159,27 +159,27 @@ class Topic < ActiveRecord::Base
@post_numbers ||= posts.order(:post_number).pluck(:post_number)
end
- def has_meta_data_boolean?(key)
+ def has_meta_data_boolean?(key)
meta_data_string(key) == 'true'
end
def meta_data_string(key)
- return nil unless meta_data.present?
- meta_data[key.to_s]
+ return nil unless meta_data.present?
+ meta_data[key.to_s]
end
def self.visible
where(visible: true)
end
- def private_message?
+ def private_message?
self.archetype == Archetype.private_message
end
def links_grouped
- exec_sql("SELECT ftl.url,
+ exec_sql("SELECT ftl.url,
ft.title,
- ftl.link_topic_id,
+ ftl.link_topic_id,
ftl.reflection,
ftl.internal,
MIN(ftl.user_id) AS user_id,
@@ -188,8 +188,8 @@ class Topic < ActiveRecord::Base
LEFT OUTER JOIN topics AS ft ON ftl.link_topic_id = ft.id
WHERE ftl.topic_id = ?
GROUP BY ftl.url, ft.title, ftl.link_topic_id, ftl.reflection, ftl.internal
- ORDER BY clicks DESC",
- self.id).to_a
+ ORDER BY clicks DESC",
+ self.id).to_a
end
def update_status(property, status, user)
@@ -212,18 +212,18 @@ class Topic < ActiveRecord::Base
highest = exec_sql("select coalesce(max(post_number),0) as max from posts where topic_id = ?", topic_id).first['max'].to_i
reply_sql = reply ? ", reply_count = reply_count + 1" : ""
- result = exec_sql("UPDATE topics SET highest_post_number = ? + 1#{reply_sql}
+ result = exec_sql("UPDATE topics SET highest_post_number = ? + 1#{reply_sql}
WHERE id = ? RETURNING highest_post_number", highest, topic_id)
result.first['highest_post_number'].to_i
end
# If a post is deleted we have to update our highest post counters
def self.reset_highest(topic_id)
- result = exec_sql "UPDATE topics
+ result = exec_sql "UPDATE topics
SET highest_post_number = (SELECT COALESCE(MAX(post_number), 0) FROM posts WHERE topic_id = :topic_id AND deleted_at IS NULL),
posts_count = (SELECT count(*) FROM posts WHERE deleted_at IS NULL AND topic_id = :topic_id)
WHERE id = :topic_id
- RETURNING highest_post_number", topic_id: topic_id
+ RETURNING highest_post_number", topic_id: topic_id
highest_post_number = result.first['highest_post_number'].to_i
# Update the forum topic user records
@@ -245,11 +245,11 @@ class Topic < ActiveRecord::Base
def self.calculate_avg_time
exec_sql("UPDATE topics
SET avg_time = x.gmean
- FROM (SELECT topic_id,
+ FROM (SELECT topic_id,
round(exp(avg(ln(avg_time)))) AS gmean
FROM posts
GROUP BY topic_id) AS x
- WHERE x.topic_id = topics.id")
+ WHERE x.topic_id = topics.id")
end
def changed_to_category(cat)
@@ -267,21 +267,21 @@ class Topic < ActiveRecord::Base
self.category_id = cat.id
self.save
- CategoryFeaturedTopic.feature_topics_for(old_category)
+ CategoryFeaturedTopic.feature_topics_for(old_category)
Category.update_all 'topic_count = topic_count + 1', ['id = ?', cat.id]
CategoryFeaturedTopic.feature_topics_for(cat) unless old_category.try(:id) == cat.try(:id)
- end
+ end
end
def add_moderator_post(user, text, opts={})
new_post = nil
Topic.transaction do
new_post = posts.create(user: user, raw: text, post_type: Post::MODERATOR_ACTION, no_bump: opts[:bump].blank?)
- increment!(:moderator_posts_count)
+ increment!(:moderator_posts_count)
new_post
end
-
+
if new_post.present?
# If we are moving posts, we want to insert the moderator post where the previous posts were
# in the stream, not at the end.
@@ -290,7 +290,7 @@ class Topic < ActiveRecord::Base
# Grab any links that are present
TopicLink.extract_from(new_post)
end
-
+
new_post
end
@@ -300,7 +300,7 @@ class Topic < ActiveRecord::Base
if name.blank?
if category_id.present?
CategoryFeaturedTopic.feature_topics_for(category)
- Category.update_all 'topic_count = topic_count - 1', ['id = ?', category_id]
+ Category.update_all 'topic_count = topic_count - 1', ['id = ?', category_id]
end
self.category_id = nil
self.save
@@ -324,12 +324,12 @@ class Topic < ActiveRecord::Base
if user.present?
if topic_allowed_users.create!(user_id: user.id)
# Notify the user they've been invited
- user.notifications.create(notification_type: Notification.Types[:invited_to_private_message],
+ user.notifications.create(notification_type: Notification.Types[:invited_to_private_message],
topic_id: self.id,
post_number: 1,
data: {topic_title: self.title,
display_username: invited_by.username}.to_json)
- return true
+ return true
end
elsif username_or_email =~ /^.+@.+$/
# If the user doesn't exist, but it looks like an email, invite the user by email.
@@ -339,21 +339,21 @@ class Topic < ActiveRecord::Base
# Success is whether the invite was created
return invite_by_email(invited_by, username_or_email).present?
end
-
+
false
end
# Invite a user by email and return the invite. Return the previously existing invite
- # if already exists. Returns nil if the invite can't be created.
+ # if already exists. Returns nil if the invite can't be created.
def invite_by_email(invited_by, email)
lower_email = email.downcase
- #
+ #
invite = Invite.with_deleted.where('invited_by_id = ? and email = ?', invited_by.id, lower_email).first
-
+
if invite.blank?
- invite = Invite.create(invited_by: invited_by, email: lower_email)
+ invite = Invite.create(invited_by: invited_by, email: lower_email)
unless invite.valid?
# If the email already exists, grant permission to that user
@@ -362,7 +362,7 @@ class Topic < ActiveRecord::Base
topic_allowed_users.create!(user_id: user.id)
end
- return nil
+ return nil
end
end
@@ -371,7 +371,7 @@ class Topic < ActiveRecord::Base
topic_invites.create(invite_id: invite.id)
Jobs.enqueue(:invite_email, invite_id: invite.id)
- invite
+ invite
end
def move_posts(moved_by, new_title, post_ids)
@@ -385,10 +385,10 @@ class Topic < ActiveRecord::Base
to_move.each_with_index do |post, i|
first_post_number ||= post.post_number
- row_count = Post.update_all ["post_number = :post_number, topic_id = :topic_id, sort_order = :post_number", post_number: i+1, topic_id: topic.id],
+ row_count = Post.update_all ["post_number = :post_number, topic_id = :topic_id, sort_order = :post_number", post_number: i+1, topic_id: topic.id],
['id = ? AND topic_id = ?', post.id, self.id]
- # We raise an error if any of the posts can't be moved
+ # We raise an error if any of the posts can't be moved
raise Discourse::InvalidParameters.new(:post_ids) if row_count == 0
end
@@ -444,28 +444,28 @@ class Topic < ActiveRecord::Base
add_description.call(al[featured_user2_id], :frequent_poster)
add_description.call(al[featured_user3_id], :frequent_poster)
add_description.call(al[featured_user4_id], :frequent_poster)
- add_description.call(al[last_post_user_id], :most_recent_poster)
+ add_description.call(al[last_post_user_id], :most_recent_poster)
- @posters_summary = [al[user_id],
- posted,
- al[last_post_user_id],
- al[featured_user1_id],
- al[featured_user2_id],
+ @posters_summary = [al[user_id],
+ posted,
+ al[last_post_user_id],
+ al[featured_user1_id],
+ al[featured_user2_id],
al[featured_user3_id],
al[featured_user4_id]
].compact.uniq[0..4]
unless @posters_summary[0] == al[last_post_user_id]
- # shuffle last_poster to back
+ # shuffle last_poster to back
@posters_summary.reject!{|u| u == al[last_post_user_id]}
@posters_summary << al[last_post_user_id]
end
- @posters_summary.map! do |p|
+ @posters_summary.map! do |p|
result = TopicPoster.new
result.user = p
result.description = descriptions[p.id].join(', ')
- result.extras = "latest" if al[last_post_user_id] == p
+ result.extras = "latest" if al[last_post_user_id] == p
result
end
@@ -479,9 +479,9 @@ class Topic < ActiveRecord::Base
TopicUser.change(user, self.id, starred: starred, starred_at: starred ? DateTime.now : nil)
# Update the star count
- exec_sql "UPDATE topics
- SET star_count = (SELECT COUNT(*)
- FROM topic_users AS ftu
+ exec_sql "UPDATE topics
+ SET star_count = (SELECT COUNT(*)
+ FROM topic_users AS ftu
WHERE ftu.topic_id = topics.id
AND ftu.starred = true)
WHERE id = ?", self.id
@@ -493,7 +493,7 @@ class Topic < ActiveRecord::Base
end
end
end
-
+
# Enable/disable the mute on the topic
def toggle_mute(user, muted)
TopicUser.change(user, self.id, notification_level: muted?(user) ? TopicUser::NotificationLevel::REGULAR : TopicUser::NotificationLevel::MUTED )
@@ -527,7 +527,7 @@ class Topic < ActiveRecord::Base
def notify_watch!(user)
TopicUser.change(user, self.id, notification_level: TopicUser::NotificationLevel::WATCHING)
end
-
+
def notify_tracking!(user)
TopicUser.change(user, self.id, notification_level: TopicUser::NotificationLevel::TRACKING)
end
@@ -535,7 +535,7 @@ class Topic < ActiveRecord::Base
def notify_regular!(user)
TopicUser.change(user, self.id, notification_level: TopicUser::NotificationLevel::REGULAR)
end
-
+
def notify_muted!(user)
TopicUser.change(user, self.id, notification_level: TopicUser::NotificationLevel::MUTED)
end
diff --git a/app/models/topic_invite.rb b/app/models/topic_invite.rb
index c252cfe1f..36fc62046 100644
--- a/app/models/topic_invite.rb
+++ b/app/models/topic_invite.rb
@@ -1,5 +1,5 @@
class TopicInvite < ActiveRecord::Base
-
+
belongs_to :topic
belongs_to :invite
diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index 35596e7b3..da3f5be4f 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -2,7 +2,7 @@ require 'uri'
require_dependency 'slug'
class TopicLink < ActiveRecord::Base
-
+
belongs_to :topic
belongs_to :user
belongs_to :post
@@ -26,7 +26,7 @@ class TopicLink < ActiveRecord::Base
# Extract any urls in body
def self.extract_from(post)
return unless post.present?
-
+
TopicLink.transaction do
added_urls = []
@@ -37,7 +37,7 @@ class TopicLink < ActiveRecord::Base
.map{|u| [u, URI.parse(u)] rescue nil}
.reject{|u,p| p.nil?}
.uniq{|u,p| u}
- .each do |url, parsed|
+ .each do |url, parsed|
begin
internal = false
@@ -45,7 +45,7 @@ class TopicLink < ActiveRecord::Base
post_number = nil
if parsed.host == Discourse.current_hostname || !parsed.host
internal = true
-
+
route = Rails.application.routes.recognize_path(parsed.path)
topic_id = route[:topic_id]
post_number = route[:post_number] || 1
@@ -55,8 +55,8 @@ class TopicLink < ActiveRecord::Base
next if topic_id == post.topic_id
added_urls << url
- TopicLink.create(post_id: post.id,
- user_id: post.user_id,
+ TopicLink.create(post_id: post.id,
+ user_id: post.user_id,
topic_id: post.topic_id,
url: url,
domain: parsed.host || Discourse.current_hostname,
@@ -94,9 +94,9 @@ class TopicLink < ActiveRecord::Base
rescue URI::InvalidURIError
# if the URI is invalid, don't store it.
rescue ActionController::RoutingError
- # If we can't find the route, no big deal
+ # If we can't find the route, no big deal
end
- end
+ end
# Remove links that aren't there anymore
if added_urls.present?
diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb
index c0a041af8..c1880020e 100644
--- a/app/models/topic_link_click.rb
+++ b/app/models/topic_link_click.rb
@@ -2,18 +2,18 @@ require_dependency 'discourse'
require 'ipaddr'
class TopicLinkClick < ActiveRecord::Base
-
+
belongs_to :topic_link, counter_cache: :clicks
belongs_to :user
has_ip_address :ip
-
+
validates_presence_of :topic_link_id
validates_presence_of :ip
# Create a click from a URL and post_id
def self.create_from(args={})
-
+
# Find the forum topic link
link = TopicLink.select(:id).where(url: args[:url])
link = link.where("user_id <> ?", args[:user_id]) if args[:user_id].present?
@@ -41,17 +41,17 @@ class TopicLinkClick < ActiveRecord::Base
.includes(:link_topic)
.where(topic_id: topic.id, post_id: posts.map(&:id))
.order('reflection asc, clicks desc')
-
+
result = {}
links.each do |l|
result[l.post_id] ||= []
- result[l.post_id] << {url: l.url,
- clicks: l.clicks,
- title: l.link_topic.try(:title),
+ result[l.post_id] << {url: l.url,
+ clicks: l.clicks,
+ title: l.link_topic.try(:title),
internal: l.internal,
reflection: l.reflection}
end
-
+
result
end
diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb
index 11e4a2a09..f06f004f4 100644
--- a/app/models/topic_list.rb
+++ b/app/models/topic_list.rb
@@ -21,13 +21,13 @@ class TopicList
# Create a lookup for all the user ids we need
user_ids = []
- @topics.each do |ft|
+ @topics.each do |ft|
user_ids << ft.user_id << ft.last_post_user_id << ft.featured_user_ids
end
avatar_lookup = AvatarLookup.new(user_ids)
- @topics.each do |ft|
+ @topics.each do |ft|
ft.user_data = @topic_lookup[ft.id] if @topic_lookup.present?
ft.posters = ft.posters_summary(ft.user_data, @current_user, avatar_lookup: avatar_lookup)
end
@@ -36,14 +36,14 @@ class TopicList
end
def filter_summary
- @filter_summary ||= get_summary
+ @filter_summary ||= get_summary
end
def attributes
{'more_topics_url' => page}
end
- protected
+ protected
def get_summary
s = {}
@@ -52,7 +52,7 @@ class TopicList
split.each do |i|
name, filter = i.split(",")
-
+
exclude = nil
if filter && filter[0] == "-"
exclude = filter[1..-1]
@@ -61,9 +61,9 @@ class TopicList
query = TopicQuery.new(@current_user, exclude_category: exclude)
s["unread"] = query.unread_count if name == 'unread'
s["new"] = query.new_count if name == 'new'
-
+
catSplit = name.split("/")
- if catSplit[0] == "category" && catSplit.length == 2 && @current_user
+ if catSplit[0] == "category" && catSplit.length == 2 && @current_user
query = TopicQuery.new(@current_user, only_category: catSplit[1], limit: false)
s[name] = query.unread_count + query.new_count
end
diff --git a/app/models/topic_poster.rb b/app/models/topic_poster.rb
index 5e30171af..ae1f228bf 100644
--- a/app/models/topic_poster.rb
+++ b/app/models/topic_poster.rb
@@ -4,8 +4,8 @@ class TopicPoster < OpenStruct
attr_accessor :user, :description, :extras, :id
def attributes
- {'user' => user,
- 'description' => description,
+ {'user' => user,
+ 'description' => description,
'extras' => extras,
'id' => id}
end
diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb
index 2edf38c30..650668527 100644
--- a/app/models/topic_user.rb
+++ b/app/models/topic_user.rb
@@ -1,8 +1,8 @@
class TopicUser < ActiveRecord::Base
-
+
belongs_to :user
belongs_to :topic
-
+
module NotificationLevel
WATCHING = 3
TRACKING = 2
@@ -16,11 +16,11 @@ class TopicUser < ActiveRecord::Base
USER_INTERACTED = 3
CREATED_POST = 4
end
-
+
def self.auto_track(user_id, topic_id, reason)
if exec_sql("select 1 from topic_users where user_id = ? and topic_id = ? and notifications_reason_id is null", user_id, topic_id).count == 1
- self.change(user_id, topic_id,
- notification_level: NotificationLevel::TRACKING,
+ self.change(user_id, topic_id,
+ notification_level: NotificationLevel::TRACKING,
notifications_reason_id: reason
)
@@ -74,13 +74,13 @@ class TopicUser < ActiveRecord::Base
# Sometimes people pass objs instead of the ids. We can handle that.
topic_id = topic_id.id if topic_id.is_a?(Topic)
user_id = user_id.id if user_id.is_a?(User)
-
+
TopicUser.transaction do
attrs = attrs.dup
attrs[:starred_at] = DateTime.now if attrs[:starred_at].nil? && attrs[:starred]
if attrs[:notification_level]
- attrs[:notifications_changed_at] ||= DateTime.now
+ attrs[:notifications_changed_at] ||= DateTime.now
attrs[:notifications_reason_id] ||= TopicUser::NotificationReasons::USER_CHANGED
end
attrs_array = attrs.to_a
@@ -88,7 +88,7 @@ class TopicUser < ActiveRecord::Base
attrs_sql = attrs_array.map {|t| "#{t[0]} = ?"}.join(", ")
vals = attrs_array.map {|t| t[1]}
rows = TopicUser.update_all([attrs_sql, *vals], ["topic_id = ? and user_id = ?", topic_id.to_i, user_id])
-
+
if rows == 0
now = DateTime.now
auto_track_after = self.exec_sql("select auto_track_topics_after_msecs from users where id = ?", user_id).values[0][0]
@@ -110,11 +110,11 @@ class TopicUser < ActiveRecord::Base
def self.track_visit!(topic,user)
now = DateTime.now
rows = exec_sql_row_count(
- "update topic_users set last_visited_at=? where topic_id=? and user_id=?",
+ "update topic_users set last_visited_at=? where topic_id=? and user_id=?",
now, topic.id, user.id
)
- if rows == 0
+ if rows == 0
exec_sql('insert into topic_users(topic_id, user_id, last_visited_at, first_visited_at)
values(?,?,?,?)',
topic.id, user.id, now, now)
@@ -133,22 +133,22 @@ class TopicUser < ActiveRecord::Base
topic_id: topic_id,
post_number: post_number,
now: DateTime.now,
- msecs: msecs,
- tracking: TopicUser::NotificationLevel::TRACKING,
+ msecs: msecs,
+ tracking: TopicUser::NotificationLevel::TRACKING,
threshold: SiteSetting.auto_track_topics_after
}
rows = exec_sql("UPDATE topic_users
- SET
- last_read_post_number = greatest(:post_number, tu.last_read_post_number),
- seen_post_count = t.highest_post_number,
+ SET
+ last_read_post_number = greatest(:post_number, tu.last_read_post_number),
+ seen_post_count = t.highest_post_number,
total_msecs_viewed = tu.total_msecs_viewed + :msecs,
- notification_level =
- case when tu.notifications_reason_id is null and (tu.total_msecs_viewed + :msecs) >
- coalesce(u.auto_track_topics_after_msecs,:threshold) and
- coalesce(u.auto_track_topics_after_msecs, :threshold) >= 0 then
- :tracking
- else
+ notification_level =
+ case when tu.notifications_reason_id is null and (tu.total_msecs_viewed + :msecs) >
+ coalesce(u.auto_track_topics_after_msecs,:threshold) and
+ coalesce(u.auto_track_topics_after_msecs, :threshold) >= 0 then
+ :tracking
+ else
tu.notification_level
end
FROM topic_users tu
@@ -157,38 +157,38 @@ class TopicUser < ActiveRecord::Base
WHERE
tu.topic_id = topic_users.topic_id AND
tu.user_id = topic_users.user_id AND
- tu.topic_id = :topic_id AND
+ tu.topic_id = :topic_id AND
tu.user_id = :user_id
RETURNING
topic_users.notification_level, tu.notification_level old_level
",
args).values
-
- if rows.length == 1
+
+ if rows.length == 1
before = rows[0][1].to_i
after = rows[0][0].to_i
- if before != after
+ if before != after
MessageBus.publish("/topic/#{topic_id}", {notification_level_change: after}, user_ids: [user.id])
end
end
if rows.length == 0
-
+
self
args[:tracking] = TopicUser::NotificationLevel::TRACKING
args[:regular] = TopicUser::NotificationLevel::REGULAR
args[:site_setting] = SiteSetting.auto_track_topics_after
exec_sql("INSERT INTO topic_users (user_id, topic_id, last_read_post_number, seen_post_count, last_visited_at, first_visited_at, notification_level)
- SELECT :user_id, :topic_id, :post_number, ft.highest_post_number, :now, :now,
+ SELECT :user_id, :topic_id, :post_number, ft.highest_post_number, :now, :now,
case when coalesce(u.auto_track_topics_after_msecs, :site_setting) = 0 then :tracking else :regular end
FROM topics AS ft
JOIN users u on u.id = :user_id
WHERE ft.id = :topic_id
- AND NOT EXISTS(SELECT 1
- FROM topic_users AS ftu
- WHERE ftu.user_id = :user_id and ftu.topic_id = :topic_id)",
+ AND NOT EXISTS(SELECT 1
+ FROM topic_users AS ftu
+ WHERE ftu.user_id = :user_id and ftu.topic_id = :topic_id)",
args)
end
end
diff --git a/app/models/upload.rb b/app/models/upload.rb
index 8e4568b40..41b9e278d 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -22,12 +22,12 @@ class Upload < ActiveRecord::Base
def self.create_on_imgur(user, file, topic_id)
@imgur_loaded = require 'imgur' unless @imgur_loaded
-
+
info = Imgur.upload_file(file)
Upload.create!({user_id: user.id,
topic_id: topic_id,
- original_filename: file.original_filename}.merge!(info))
+ original_filename: file.original_filename}.merge!(info))
end
def self.create_locally(user, file, topic_id)
@@ -35,28 +35,28 @@ class Upload < ActiveRecord::Base
topic_id: topic_id,
url: "",
filesize: File.size(file.tempfile),
- original_filename: file.original_filename)
+ original_filename: file.original_filename)
- # populate the rest of the info
+ # populate the rest of the info
clean_name = file.original_filename.gsub(" ", "_").downcase.gsub(/[^a-z0-9\._]/, "")
split = clean_name.split(".")
- if split.length > 1
+ if split.length > 1
clean_name = split[0..-2].join("_")
end
image_info = FastImage.new(file.tempfile)
clean_name += ".#{image_info.type}"
- url_root = "/uploads/#{RailsMultisite::ConnectionManagement.current_db}/#{upload.id}"
+ url_root = "/uploads/#{RailsMultisite::ConnectionManagement.current_db}/#{upload.id}"
path = "#{Rails.root}/public#{url_root}"
upload.width, upload.height = ImageSizer.resize(*image_info.size)
FileUtils.mkdir_p path
# not using cause mv, cause permissions are no good on move
File.open("#{path}/#{clean_name}", "wb") do |f|
- f.write File.read(file.tempfile)
+ f.write File.read(file.tempfile)
end
upload.url = "#{url_root}/#{clean_name}"
upload.save
- upload
+ upload
end
def self.create_on_s3(user, file, topic_id)
@@ -68,12 +68,12 @@ class Upload < ActiveRecord::Base
upload = Upload.new(user_id: user.id,
topic_id: topic_id,
filesize: File.size(tempfile),
- original_filename: file.original_filename)
+ original_filename: file.original_filename)
image_info = FastImage.new(tempfile)
blob = file.read
sha1 = Digest::SHA1.hexdigest(blob)
-
+
Fog.credentials_path = "#{Rails.root}/config/fog_credentials.yml"
fog = Fog::Storage.new(provider: 'AWS')
@@ -82,10 +82,10 @@ class Upload < ActiveRecord::Base
path = "/uploads/#{sha1[0]}/#{sha1[1]}"
location = "#{SiteSetting.s3_upload_bucket}#{path}"
directory = fog.directories.create(key: location)
-
+
Rails.logger.info "#{blob.size.inspect}"
- file = directory.files.create(key: remote_filename,
- body: tempfile,
+ file = directory.files.create(key: remote_filename,
+ body: tempfile,
public: true,
content_type: file.content_type)
upload.width, upload.height = ImageSizer.resize(*image_info.size)
diff --git a/app/models/user.rb b/app/models/user.rb
index 3ed14f3b0..fb55d91a6 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -337,7 +337,7 @@ class User < ActiveRecord::Base
def delete_all_posts!(guardian)
raise Discourse::InvalidAccess unless guardian.can_delete_all_posts? self
-
+
posts.order("post_number desc").each do |p|
if p.post_number == 1
p.topic.destroy
diff --git a/app/models/user_action.rb b/app/models/user_action.rb
index aeadb1f4c..8d5dc49cb 100644
--- a/app/models/user_action.rb
+++ b/app/models/user_action.rb
@@ -4,12 +4,12 @@ require_dependency 'sql_builder'
class UserAction < ActiveRecord::Base
belongs_to :user
attr_accessible :acting_user_id, :action_type, :target_topic_id, :target_post_id, :target_user_id, :user_id
-
+
validates_presence_of :action_type
validates_presence_of :user_id
LIKE = 1
- WAS_LIKED = 2
+ WAS_LIKED = 2
BOOKMARK = 3
NEW_TOPIC = 4
POST = 5
@@ -17,7 +17,7 @@ class UserAction < ActiveRecord::Base
MENTION = 7
TOPIC_RESPONSE = 8
QUOTE = 9
- STAR = 10
+ STAR = 10
EDIT = 11
NEW_PRIVATE_MESSAGE = 12
GOT_PRIVATE_MESSAGE = 13
@@ -41,20 +41,20 @@ class UserAction < ActiveRecord::Base
def self.stats(user_id, guardian)
sql = <
ORDER[b["action_type"].to_i]}
- results.each do |row|
+ results.each do |row|
row["description"] = self.description(row["action_type"], detailed: true)
end
@@ -65,20 +65,20 @@ SQL
stream(action_id:action_id, guardian: guardian)[0]
end
- def self.stream(opts={})
+ def self.stream(opts={})
user_id = opts[:user_id]
- offset = opts[:offset]||0
+ offset = opts[:offset]||0
limit = opts[:limit] ||60
- action_id = opts[:action_id]
+ action_id = opts[:action_id]
action_types = opts[:action_types]
guardian = opts[:guardian]
ignore_private_messages = opts[:ignore_private_messages]
builder = SqlBuilder.new("
-select t.title, a.action_type, a.created_at,
+select t.title, a.action_type, a.created_at,
t.id topic_id, coalesce(p.post_number, 1) post_number, u.email ,u.username, u.name, u.id user_id, coalesce(p.cooked, p2.cooked) cooked
from user_actions as a
-join topics t on t.id = a.target_topic_id
+join topics t on t.id = a.target_topic_id
left join posts p on p.id = a.target_post_id
left join users u on u.id = a.acting_user_id
left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
@@ -88,33 +88,33 @@ left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
/*limit*/
")
- unless guardian.can_see_deleted_posts?
+ unless guardian.can_see_deleted_posts?
builder.where("p.deleted_at is null and p2.deleted_at is null")
end
- if !guardian.can_see_private_messages?(user_id) || ignore_private_messages
+ if !guardian.can_see_private_messages?(user_id) || ignore_private_messages
builder.where("a.action_type not in (#{NEW_PRIVATE_MESSAGE},#{GOT_PRIVATE_MESSAGE})")
end
if action_id
builder.where("a.id = :id", id: action_id.to_i)
data = builder.exec.to_a
- else
+ else
builder.where("a.user_id = :user_id", user_id: user_id.to_i)
- builder.where("a.action_type in (:action_types)", action_types: action_types) if action_types && action_types.length > 0
+ builder.where("a.action_type in (:action_types)", action_types: action_types) if action_types && action_types.length > 0
builder.order_by("a.created_at desc")
builder.offset(offset.to_i)
builder.limit(limit.to_i)
data = builder.exec.to_a
end
-
- data.each do |row|
+
+ data.each do |row|
row["description"] = self.description(row["action_type"])
row["created_at"] = DateTime.parse(row["created_at"])
# we should probably cache the excerpts in the db at some point
row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"]
row["cooked"] = nil
- row["avatar_template"] = User.avatar_template(row["email"])
+ row["avatar_template"] = User.avatar_template(row["email"])
row.delete("email")
row["slug"] = Slug.for(row["title"])
end
@@ -124,7 +124,7 @@ left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
def self.description(row, opts = {})
t = I18n.t('user_action_descriptions')
- if opts[:detailed]
+ if opts[:detailed]
# will localize as soon as we stablize the names here
desc = case row.to_i
when BOOKMARK
@@ -155,7 +155,7 @@ left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
t[:inbox]
end
else
- desc =
+ desc =
case row.to_i
when NEW_TOPIC
then t[:posted]
@@ -181,11 +181,11 @@ left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
def self.log_action!(hash)
require_parameters(hash, :action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id)
transaction(requires_new: true) do
- begin
+ begin
action = self.new(hash)
if hash[:created_at]
- action.created_at = hash[:created_at]
+ action.created_at = hash[:created_at]
end
action.save!
rescue ActiveRecord::RecordNotUnique
@@ -198,7 +198,7 @@ left join posts p2 on p2.topic_id = a.target_topic_id and p2.post_number = 1
def self.remove_action!(hash)
require_parameters(hash, :action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id)
if action = UserAction.where(hash).first
- action.destroy
+ action.destroy
MessageBus.publish("/user/#{hash[:user_id]}", {user_action_id: action.id, remove: true})
end
end
diff --git a/app/models/user_action_observer.rb b/app/models/user_action_observer.rb
index a51aad0fd..8884ec006 100644
--- a/app/models/user_action_observer.rb
+++ b/app/models/user_action_observer.rb
@@ -3,8 +3,8 @@ class UserActionObserver < ActiveRecord::Observer
def after_save(model)
- case
- when (model.is_a?(PostAction) and (model.is_bookmark? or model.is_like?))
+ case
+ when (model.is_a?(PostAction) and (model.is_bookmark? or model.is_like?))
log_post_action(model)
when (model.is_a?(Topic))
log_topic(model)
@@ -17,29 +17,29 @@ class UserActionObserver < ActiveRecord::Observer
end
end
- protected
+ protected
def log_topic_user(model)
action = UserAction::STAR
- row = {
- action_type: action,
- user_id: model.user_id,
- acting_user_id: model.user_id,
- target_topic_id: model.topic_id,
+ row = {
+ action_type: action,
+ user_id: model.user_id,
+ acting_user_id: model.user_id,
+ target_topic_id: model.topic_id,
target_post_id: -1,
created_at: model.starred_at
}
- if model.starred
+ if model.starred
UserAction.log_action!(row)
- else
- UserAction.remove_action!(row)
+ else
+ UserAction.remove_action!(row)
end
end
-
+
def log_notification(model)
-
+
action =
case model.notification_type
when Notification.Types[:quoted]
@@ -60,80 +60,80 @@ class UserActionObserver < ActiveRecord::Observer
# stray data
return unless post
- row = {
- action_type: action,
- user_id: model.user_id,
- acting_user_id: (action == UserAction::EDIT) ? post.last_editor_id : post.user_id,
- target_topic_id: model.topic_id,
+ row = {
+ action_type: action,
+ user_id: model.user_id,
+ acting_user_id: (action == UserAction::EDIT) ? post.last_editor_id : post.user_id,
+ target_topic_id: model.topic_id,
target_post_id: post.id,
created_at: model.created_at
}
- if post.deleted_at.nil?
+ if post.deleted_at.nil?
UserAction.log_action!(row)
- else
- UserAction.remove_action!(row)
+ else
+ UserAction.remove_action!(row)
end
end
def log_post(model)
-
+
# first post gets nada
return if model.post_number == 1
- row = {
- action_type: UserAction::POST,
- user_id: model.user_id,
- acting_user_id: model.user_id,
+ row = {
+ action_type: UserAction::POST,
+ user_id: model.user_id,
+ acting_user_id: model.user_id,
target_post_id: model.id,
target_topic_id: model.topic_id,
created_at: model.created_at
}
-
+
rows = [row]
- if model.topic.private_message?
+ if model.topic.private_message?
rows = []
model.topic.topic_allowed_users.each do |ta|
row = row.dup
- row[:user_id] = ta.user_id
+ row[:user_id] = ta.user_id
row[:action_type] = ta.user_id == model.user_id ? UserAction::NEW_PRIVATE_MESSAGE : UserAction::GOT_PRIVATE_MESSAGE
rows << row
end
end
rows.each do |row|
- if model.deleted_at.nil?
+ if model.deleted_at.nil?
UserAction.log_action!(row)
- else
- UserAction.remove_action!(row)
+ else
+ UserAction.remove_action!(row)
end
end
return if model.topic.private_message?
# a bit odd but we may have stray records
- if model.topic and model.topic.user_id != model.user_id
- row[:action_type] = UserAction::TOPIC_RESPONSE
- row[:user_id] = model.topic.user_id
+ if model.topic and model.topic.user_id != model.user_id
+ row[:action_type] = UserAction::TOPIC_RESPONSE
+ row[:user_id] = model.topic.user_id
- if model.deleted_at.nil?
+ if model.deleted_at.nil?
UserAction.log_action!(row)
- else
- UserAction.remove_action!(row)
+ else
+ UserAction.remove_action!(row)
end
end
end
def log_topic(model)
- row = {
- action_type: model.archetype == Archetype.private_message ? UserAction::NEW_PRIVATE_MESSAGE : UserAction::NEW_TOPIC,
- user_id: model.user_id,
- acting_user_id: model.user_id,
+ row = {
+ action_type: model.archetype == Archetype.private_message ? UserAction::NEW_PRIVATE_MESSAGE : UserAction::NEW_TOPIC,
+ user_id: model.user_id,
+ acting_user_id: model.user_id,
target_topic_id: model.id,
- target_post_id: -1,
+ target_post_id: -1,
created_at: model.created_at
}
@@ -142,17 +142,17 @@ class UserActionObserver < ActiveRecord::Observer
if model.private_message?
model.topic_allowed_users.reject{|a| a.user_id == model.user_id}.each do |ta|
row = row.dup
- row[:user_id] = ta.user_id
+ row[:user_id] = ta.user_id
row[:action_type] = UserAction::GOT_PRIVATE_MESSAGE
rows << row
end
end
rows.each do |row|
- if model.deleted_at.nil?
+ if model.deleted_at.nil?
UserAction.log_action!(row)
- else
- UserAction.remove_action!(row)
+ else
+ UserAction.remove_action!(row)
end
end
end
@@ -162,9 +162,9 @@ class UserActionObserver < ActiveRecord::Observer
action = UserAction::LIKE if model.is_like?
row = {
- action_type: action,
- user_id: model.user_id,
- acting_user_id: model.user_id,
+ action_type: action,
+ user_id: model.user_id,
+ acting_user_id: model.user_id,
target_post_id: model.post_id,
target_topic_id: model.post.topic_id,
created_at: model.created_at
@@ -176,7 +176,7 @@ class UserActionObserver < ActiveRecord::Observer
UserAction.remove_action!(row)
end
- if model.is_like?
+ if model.is_like?
row[:action_type] = UserAction::WAS_LIKED
row[:user_id] = model.post.user_id
if model.deleted_at.nil?
diff --git a/app/models/user_email_observer.rb b/app/models/user_email_observer.rb
index bc31d53b4..97b019c67 100644
--- a/app/models/user_email_observer.rb
+++ b/app/models/user_email_observer.rb
@@ -13,36 +13,36 @@ class UserEmailObserver < ActiveRecord::Observer
def email_user_mentioned(notification)
return unless notification.user.email_direct?
- Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
- :user_email,
- type: :user_mentioned,
+ Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
+ :user_email,
+ type: :user_mentioned,
user_id: notification.user_id,
notification_id: notification.id)
end
def email_user_quoted(notification)
return unless notification.user.email_direct?
- Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
- :user_email,
- type: :user_quoted,
+ Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
+ :user_email,
+ type: :user_quoted,
user_id: notification.user_id,
notification_id: notification.id)
end
def email_user_replied(notification)
return unless notification.user.email_direct?
- Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
- :user_email,
- type: :user_replied,
+ Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
+ :user_email,
+ type: :user_replied,
user_id: notification.user_id,
notification_id: notification.id)
end
def email_user_invited_to_private_message(notification)
return unless notification.user.email_direct?
- Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
- :user_email,
- type: :user_invited_to_private_message,
+ Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
+ :user_email,
+ type: :user_invited_to_private_message,
user_id: notification.user_id,
notification_id: notification.id)
end
diff --git a/app/models/view.rb b/app/models/view.rb
index f3b225b24..61b915b08 100644
--- a/app/models/view.rb
+++ b/app/models/view.rb
@@ -2,13 +2,13 @@ require 'ipaddr'
class View < ActiveRecord::Base
- belongs_to :parent, polymorphic: true
+ belongs_to :parent, polymorphic: true
belongs_to :user
validates_presence_of :parent_type, :parent_id, :ip, :viewed_at
# TODO: This could happen asyncronously
def self.create_for(parent, ip, user=nil)
-
+
# Only store a view once per day per thing per user per ip
redis_key = "view:#{parent.class.name}:#{parent.id}:#{Date.today.to_s}"
if user.present?
diff --git a/app/serializers/admin_detailed_user_serializer.rb b/app/serializers/admin_detailed_user_serializer.rb
index d1254f553..24694d11b 100644
--- a/app/serializers/admin_detailed_user_serializer.rb
+++ b/app/serializers/admin_detailed_user_serializer.rb
@@ -1,8 +1,8 @@
class AdminDetailedUserSerializer < AdminUserSerializer
attributes :moderator,
- :can_grant_admin,
- :can_impersonate,
+ :can_grant_admin,
+ :can_impersonate,
:can_revoke_admin,
:like_count,
:post_count,
@@ -20,7 +20,7 @@ class AdminDetailedUserSerializer < AdminUserSerializer
def can_grant_admin
scope.can_grant_admin?(object)
end
-
+
def can_delete_all_posts
scope.can_delete_all_posts?(object)
end
diff --git a/app/serializers/admin_user_serializer.rb b/app/serializers/admin_user_serializer.rb
index f3f8d622b..3b1f734bc 100644
--- a/app/serializers/admin_user_serializer.rb
+++ b/app/serializers/admin_user_serializer.rb
@@ -1,16 +1,16 @@
class AdminUserSerializer < BasicUserSerializer
- attributes :email,
- :active,
- :admin,
- :last_seen_age,
+ attributes :email,
+ :active,
+ :admin,
+ :last_seen_age,
:days_visited,
:last_emailed_age,
- :created_at_age,
+ :created_at_age,
:username_lower,
:trust_level,
:flag_level,
- :username,
+ :username,
:avatar_template,
:topics_entered,
:posts_read_count,
diff --git a/app/serializers/application_serializer.rb b/app/serializers/application_serializer.rb
index 8c4205398..3065792ea 100644
--- a/app/serializers/application_serializer.rb
+++ b/app/serializers/application_serializer.rb
@@ -1,3 +1,3 @@
class ApplicationSerializer < ActiveModel::Serializer
embed :ids, :include => true
-end
\ No newline at end of file
+end
diff --git a/app/serializers/basic_topic_serializer.rb b/app/serializers/basic_topic_serializer.rb
index 593faa6e6..13a073c4f 100644
--- a/app/serializers/basic_topic_serializer.rb
+++ b/app/serializers/basic_topic_serializer.rb
@@ -3,7 +3,7 @@ require_dependency 'age_words'
class BasicTopicSerializer < ApplicationSerializer
include ActionView::Helpers
- attributes :id, :title, :reply_count, :posts_count, :highest_post_number, :image_url, :created_at,
+ attributes :id, :title, :reply_count, :posts_count, :highest_post_number, :image_url, :created_at,
:last_posted_at, :age, :unseen, :last_read_post_number, :unread, :new_posts
def age
@@ -11,17 +11,17 @@ class BasicTopicSerializer < ApplicationSerializer
end
def seen
- object.user_data.present?
+ object.user_data.present?
end
def unseen
return false if scope.blank?
- return false if scope.user.blank?
+ return false if scope.user.blank?
return false if object.user_data.present?
return false if object.created_at < scope.user.created_at
# Only mark things as new since your last visit
- if scope.user.previous_visit_at.present?
+ if scope.user.previous_visit_at.present?
return false if object.created_at < scope.user.previous_visit_at
end
@@ -50,4 +50,4 @@ class BasicTopicSerializer < ApplicationSerializer
@unread_helper ||= Unread.new(object, object.user_data)
end
-end
\ No newline at end of file
+end
diff --git a/app/serializers/category_detailed_serializer.rb b/app/serializers/category_detailed_serializer.rb
index 68b80a508..28afff806 100644
--- a/app/serializers/category_detailed_serializer.rb
+++ b/app/serializers/category_detailed_serializer.rb
@@ -3,7 +3,7 @@ class CategoryDetailedSerializer < CategorySerializer
attributes :topic_count, :topics_week, :topics_month, :topics_year
has_many :featured_users, serializer: BasicUserSerializer
- has_many :featured_topics, serializer: CategoryTopicSerializer, embed: :objects, key: :topics
+ has_many :featured_topics, serializer: CategoryTopicSerializer, embed: :objects, key: :topics
def topics_week
object.topics_week || 0
diff --git a/app/serializers/category_excerpt_serializer.rb b/app/serializers/category_excerpt_serializer.rb
index fd0b4e777..4ac0e2506 100644
--- a/app/serializers/category_excerpt_serializer.rb
+++ b/app/serializers/category_excerpt_serializer.rb
@@ -2,8 +2,8 @@ require_dependency 'excerpt_type'
class CategoryExcerptSerializer < ActiveModel::Serializer
include ExcerptType
-
- attributes :excerpt, :name, :color, :slug, :topic_url, :topics_year,
+
+ attributes :excerpt, :name, :color, :slug, :topic_url, :topics_year,
:topics_month, :topics_week, :category_url, :can_edit, :can_delete
@@ -17,7 +17,7 @@ class CategoryExcerptSerializer < ActiveModel::Serializer
def topics_week
object.topics_week || 0
- end
+ end
def category_url
"/category/#{object.slug}"
diff --git a/app/serializers/category_featured_users_serializer.rb b/app/serializers/category_featured_users_serializer.rb
index 2ecd67fcd..6fbded88a 100644
--- a/app/serializers/category_featured_users_serializer.rb
+++ b/app/serializers/category_featured_users_serializer.rb
@@ -1,5 +1,5 @@
class CategoryFeaturedUsersSerializer < CategorySerializer
-
+
has_many :featured_users, serializer: BasicUserSerializer, embed: :objects
end
diff --git a/app/serializers/category_list_serializer.rb b/app/serializers/category_list_serializer.rb
index 1b6580f19..dfc587440 100644
--- a/app/serializers/category_list_serializer.rb
+++ b/app/serializers/category_list_serializer.rb
@@ -1,5 +1,5 @@
class CategoryListSerializer < ApplicationSerializer
-
+
attributes :can_create_category
has_many :categories, serializer: CategoryDetailedSerializer, embed: :objects
diff --git a/app/serializers/category_topic_serializer.rb b/app/serializers/category_topic_serializer.rb
index 05b0a45cd..8918d087d 100644
--- a/app/serializers/category_topic_serializer.rb
+++ b/app/serializers/category_topic_serializer.rb
@@ -1,7 +1,7 @@
class CategoryTopicSerializer < BasicTopicSerializer
attributes :slug
-
+
has_one :category
end
diff --git a/app/serializers/email_log_serializer.rb b/app/serializers/email_log_serializer.rb
index 280e18bac..56ad183f0 100644
--- a/app/serializers/email_log_serializer.rb
+++ b/app/serializers/email_log_serializer.rb
@@ -1,5 +1,5 @@
class EmailLogSerializer < ApplicationSerializer
-
+
attributes :id, :to_address, :email_type, :user_id, :created_at
has_one :user, serializer: BasicUserSerializer, embed: :objects
diff --git a/app/serializers/invite_serializer.rb b/app/serializers/invite_serializer.rb
index 76d5805ab..3b9c1a063 100644
--- a/app/serializers/invite_serializer.rb
+++ b/app/serializers/invite_serializer.rb
@@ -3,7 +3,7 @@ class InviteSerializer < ApplicationSerializer
attributes :email, :created_at, :redeemed_at
has_one :user, embed: :objects, serializer: InvitedUserSerializer
-
+
def include_email?
!object.redeemed?
diff --git a/app/serializers/invited_user_serializer.rb b/app/serializers/invited_user_serializer.rb
index 35b0b3d23..a6afc7673 100644
--- a/app/serializers/invited_user_serializer.rb
+++ b/app/serializers/invited_user_serializer.rb
@@ -1,9 +1,9 @@
class InvitedUserSerializer < BasicUserSerializer
- attributes :topics_entered,
- :posts_read_count,
- :last_seen_at,
- :time_read,
+ attributes :topics_entered,
+ :posts_read_count,
+ :last_seen_at,
+ :time_read,
:days_visited,
:days_since_created
diff --git a/app/serializers/notification_serializer.rb b/app/serializers/notification_serializer.rb
index c054ff92a..c6eb84127 100644
--- a/app/serializers/notification_serializer.rb
+++ b/app/serializers/notification_serializer.rb
@@ -1,14 +1,14 @@
class NotificationSerializer < ApplicationSerializer
- attributes :notification_type,
- :read,
- :created_at,
+ attributes :notification_type,
+ :read,
+ :created_at,
:post_number,
:topic_id,
:slug,
:data
- def slug
+ def slug
Slug.for(object.topic.title) if object.topic.present?
end
diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb
index bf74deea4..f51913206 100644
--- a/app/serializers/post_serializer.rb
+++ b/app/serializers/post_serializer.rb
@@ -9,20 +9,20 @@ class PostSerializer < ApplicationSerializer
attr_accessor :draft_sequence
attributes :id,
- :post_number,
+ :post_number,
:post_type,
- :created_at,
+ :created_at,
:updated_at,
- :reply_count,
- :reply_to_post_number,
- :reply_below_post_number,
+ :reply_count,
+ :reply_to_post_number,
+ :reply_below_post_number,
:quote_count,
:avg_time,
:incoming_link_count,
:reads,
:score,
:yours,
- :topic_slug,
+ :topic_slug,
:topic_id,
:display_username,
:version,
@@ -39,10 +39,10 @@ class PostSerializer < ApplicationSerializer
:actions_summary,
:moderator?,
:avatar_template,
- :user_id,
+ :user_id,
:draft_sequence,
:hidden,
- :hidden_reason_id,
+ :hidden_reason_id,
:deleted_at
@@ -89,7 +89,7 @@ class PostSerializer < ApplicationSerializer
else
I18n.t('flagging.user_must_edit')
end
- else
+ else
object.filter_quotes(@parent_post)
end
end
@@ -138,8 +138,8 @@ class PostSerializer < ApplicationSerializer
count = object.send(count_col) if object.respond_to?(count_col)
count ||= 0
- action_summary = {id: id,
- count: count,
+ action_summary = {id: id,
+ count: count,
hidden: (sym == :vote),
can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}
@@ -148,7 +148,7 @@ class PostSerializer < ApplicationSerializer
action_summary[:can_clear_flags] = scope.is_admin? && PostActionType.FlagTypes.include?(id)
if post_actions.present? and post_actions.has_key?(id)
- action_summary[:acted] = true
+ action_summary[:acted] = true
action_summary[:can_undo] = scope.can_delete?(post_actions[id])
end
@@ -163,8 +163,8 @@ class PostSerializer < ApplicationSerializer
result
end
- def include_draft_sequence?
- @draft_sequence.present?
+ def include_draft_sequence?
+ @draft_sequence.present?
end
def include_slug_title?
@@ -172,13 +172,13 @@ class PostSerializer < ApplicationSerializer
end
def include_raw?
- @add_raw.present?
+ @add_raw.present?
end
def include_link_counts?
return true if @single_post_link_counts.present?
- @topic_view.present? and @topic_view.link_counts.present? and @topic_view.link_counts[object.id].present?
+ @topic_view.present? and @topic_view.link_counts.present? and @topic_view.link_counts[object.id].present?
end
def include_read?
@@ -186,7 +186,7 @@ class PostSerializer < ApplicationSerializer
end
def include_reply_to_user?
- object.quoteless? and object.reply_to_user
+ object.quoteless? and object.reply_to_user
end
def include_bookmarked?
@@ -196,6 +196,6 @@ class PostSerializer < ApplicationSerializer
private
def post_actions
- @post_actions ||= (@topic_view.present? && @topic_view.all_post_actions.present?) ? @topic_view.all_post_actions[object.id] : nil
+ @post_actions ||= (@topic_view.present? && @topic_view.all_post_actions.present?) ? @topic_view.all_post_actions[object.id] : nil
end
end
diff --git a/app/serializers/suggested_topic_serializer.rb b/app/serializers/suggested_topic_serializer.rb
index e25b3ba1f..75a4c9108 100644
--- a/app/serializers/suggested_topic_serializer.rb
+++ b/app/serializers/suggested_topic_serializer.rb
@@ -7,5 +7,5 @@ class SuggestedTopicSerializer < BasicTopicSerializer
return nil if object.last_posted_at.blank?
AgeWords.age_words(Time.now - object.last_posted_at)
end
-
+
end
diff --git a/app/serializers/topic_link_serializer.rb b/app/serializers/topic_link_serializer.rb
index be1192e47..d0b1fc3df 100644
--- a/app/serializers/topic_link_serializer.rb
+++ b/app/serializers/topic_link_serializer.rb
@@ -29,4 +29,4 @@ class TopicLinkSerializer < ApplicationSerializer
object['user_id'].present?
end
-end
\ No newline at end of file
+end
diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb
index 09aa55cbd..285d1229f 100644
--- a/app/serializers/topic_list_serializer.rb
+++ b/app/serializers/topic_list_serializer.rb
@@ -1,5 +1,5 @@
class TopicListSerializer < ApplicationSerializer
-
+
attributes :can_create_topic, :more_topics_url, :filter_summary, :draft, :draft_key, :draft_sequence
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
diff --git a/app/serializers/topic_post_count_serializer.rb b/app/serializers/topic_post_count_serializer.rb
index c2a087a9d..836ae78bf 100644
--- a/app/serializers/topic_post_count_serializer.rb
+++ b/app/serializers/topic_post_count_serializer.rb
@@ -19,4 +19,4 @@ class TopicPostCountSerializer < BasicUserSerializer
end
-end
\ No newline at end of file
+end
diff --git a/app/serializers/topic_poster_serializer.rb b/app/serializers/topic_poster_serializer.rb
index 41a7341df..540aa0c86 100644
--- a/app/serializers/topic_poster_serializer.rb
+++ b/app/serializers/topic_poster_serializer.rb
@@ -3,4 +3,4 @@ class TopicPosterSerializer < ApplicationSerializer
attributes :extras, :description
has_one :user, serializer: BasicUserSerializer
-end
\ No newline at end of file
+end
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb
index 490d3071d..d5f64ee73 100644
--- a/app/serializers/topic_view_serializer.rb
+++ b/app/serializers/topic_view_serializer.rb
@@ -1,15 +1,15 @@
class TopicViewSerializer < ApplicationSerializer
# These attributes will be delegated to the topic
- def self.topic_attributes
+ def self.topic_attributes
[:id,
- :title,
- :posts_count,
- :highest_post_number,
- :created_at,
- :views,
- :reply_count,
- :last_posted_at,
+ :title,
+ :posts_count,
+ :highest_post_number,
+ :created_at,
+ :views,
+ :reply_count,
+ :last_posted_at,
:visible,
:closed,
:pinned,
@@ -24,11 +24,11 @@ class TopicViewSerializer < ApplicationSerializer
[:can_moderate, :can_edit, :can_delete, :can_invite_to, :can_move_posts]
end
- attributes *topic_attributes
+ attributes *topic_attributes
attributes *guardian_attributes
- attributes :draft,
- :draft_key,
+ attributes :draft,
+ :draft_key,
:draft_sequence,
:post_action_visibility,
:voted_in_topic,
@@ -42,7 +42,7 @@ class TopicViewSerializer < ApplicationSerializer
:notifications_reason_id,
:posts,
:at_bottom
-
+
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
has_many :allowed_users, serializer: BasicUserSerializer, embed: :objects
@@ -84,11 +84,11 @@ class TopicViewSerializer < ApplicationSerializer
end
def draft_sequence
- object.draft_sequence
+ object.draft_sequence
end
def post_action_visibility
- object.post_action_visibility
+ object.post_action_visibility
end
def include_post_action_visibility?
@@ -105,10 +105,10 @@ class TopicViewSerializer < ApplicationSerializer
def include_can_reply_as_new_topic?
scope.can_create?(Post, object.topic)
- end
+ end
def can_create_post
- true
+ true
end
def include_can_create_post?
@@ -117,7 +117,7 @@ class TopicViewSerializer < ApplicationSerializer
def categoryName
object.topic.category.name
- end
+ end
def include_categoryName?
object.topic.category.present?
end
@@ -148,7 +148,7 @@ class TopicViewSerializer < ApplicationSerializer
alias_method :include_notification_level?, :has_topic_user?
def notifications_reason_id
- object.topic_user.notifications_reason_id
+ object.topic_user.notifications_reason_id
end
alias_method :include_notifications_reason_id?, :has_topic_user?
@@ -168,7 +168,7 @@ class TopicViewSerializer < ApplicationSerializer
object.links.present?
end
- def participants
+ def participants
object.posts_count.collect {|tuple| {user: object.participants[tuple.first], post_count: tuple[1]}}
end
@@ -184,7 +184,7 @@ class TopicViewSerializer < ApplicationSerializer
end
# Whether we're at the bottom of a topic (last page)
- def at_bottom
+ def at_bottom
posts.present? and (@highest_number_in_posts == object.topic.highest_post_number)
end
diff --git a/app/serializers/upload_serializer.rb b/app/serializers/upload_serializer.rb
index 9f00b3af2..8971e9a3d 100644
--- a/app/serializers/upload_serializer.rb
+++ b/app/serializers/upload_serializer.rb
@@ -1,5 +1,5 @@
class UploadSerializer < ApplicationSerializer
-
+
attributes :url, :filesize, :original_filename, :width, :height
end
diff --git a/app/serializers/user_excerpt_serializer.rb b/app/serializers/user_excerpt_serializer.rb
index 040f0f788..606089076 100644
--- a/app/serializers/user_excerpt_serializer.rb
+++ b/app/serializers/user_excerpt_serializer.rb
@@ -4,7 +4,7 @@ class UserExcerptSerializer < ActiveModel::Serializer
include ExcerptType
# TODO: Inherit from basic user serializer?
-
+
attributes :bio_cooked, :username, :url, :name, :avatar_template
def url
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb
index e9c3bc75d..f503f18a4 100644
--- a/app/serializers/user_serializer.rb
+++ b/app/serializers/user_serializer.rb
@@ -1,16 +1,16 @@
class UserSerializer < BasicUserSerializer
-
- attributes :name,
- :email,
- :last_posted_at,
- :last_seen_at,
+
+ attributes :name,
+ :email,
+ :last_posted_at,
+ :last_seen_at,
:bio_raw,
- :bio_cooked,
- :created_at,
- :website,
- :can_edit,
- :stream,
- :stats,
+ :bio_cooked,
+ :created_at,
+ :website,
+ :can_edit,
+ :stream,
+ :stats,
:can_send_private_message_to_user,
:bio_excerpt,
:invited_by,
@@ -20,7 +20,7 @@ class UserSerializer < BasicUserSerializer
def self.private_attributes(*attrs)
attributes *attrs
attrs.each do |attr|
- define_method "include_#{attr}?" do
+ define_method "include_#{attr}?" do
can_edit
end
end
@@ -28,7 +28,7 @@ class UserSerializer < BasicUserSerializer
def bio_excerpt
e = object.bio_excerpt
- unless e && e.length > 0
+ unless e && e.length > 0
e = if scope.user && scope.user.id == object.id
I18n.t('user_profile.no_info_me', username_lower: object.username_lower)
else
@@ -38,9 +38,9 @@ class UserSerializer < BasicUserSerializer
e
end
- private_attributes :email,
- :email_digests,
- :email_private_messages,
+ private_attributes :email,
+ :email_digests,
+ :email_private_messages,
:email_direct,
:digest_after_days,
:auto_track_topics_after_msecs