added delete all posts button

wired up the ability to enable all themes
This commit is contained in:
Sam Saffron
2013-02-07 18:11:56 +11:00
parent 8f4417f962
commit 85973ce6b0
13 changed files with 93 additions and 17 deletions

View File

@@ -319,11 +319,11 @@ class Post < ActiveRecord::Base
Post.transaction do
self.last_version_at = revised_at
updater.call(true)
EditRateLimiter.new(updated_by).performed!
EditRateLimiter.new(updated_by).performed! unless opts[:bypass_rate_limiter]
# If a new version is created of the last post, bump it.
unless Post.where('post_number > ? and topic_id = ?', self.post_number, self.topic_id).exists?
topic.update_column(:bumped_at, Time.now)
topic.update_column(:bumped_at, Time.now) unless opts[:bypass_bump]
end
end

View File

@@ -1,5 +1,6 @@
class SiteCustomization < ActiveRecord::Base
ENABLED_KEY = '7e202ef2-56d7-47d5-98d8-a9c8d15e57dd'
CACHE_PATH = 'stylesheet-cache'
@lock = Mutex.new
@@ -49,18 +50,36 @@ footer:after{ content: '#{error}' }"
self.remove_from_cache!
end
def self.enabled_style
@cache ||= {}
preview_style = @cache[ENABLED_KEY]
return nil if preview_style == :none
return preview_style if preview_style
@lock.synchronize do
style = self.where(enabled: true).first
if style
@cache[ENABLED_KEY] = style.key
else
@cache[ENABLED_KEY] = :none
end
end
end
def self.custom_stylesheet(preview_style)
preview_style ||= enabled_style
style = lookup_style(preview_style)
style.stylesheet_link_tag.html_safe if style
end
def self.custom_header(preview_style)
preview_style ||= enabled_style
style = lookup_style(preview_style)
style.header.html_safe if style
end
def self.override_default_style(preview_style)
preview_style ||= enabled_style
style = lookup_style(preview_style)
style.override_default_style if style
end
@@ -103,6 +122,7 @@ footer:after{ content: '#{error}' }"
end
def remove_from_cache!
self.class.remove_from_cache!(ENABLED_KEY)
self.class.remove_from_cache!(self.key)
end

View File

@@ -335,6 +335,18 @@ class User < ActiveRecord::Base
PrettyText.excerpt(bio_cooked, 350)
end
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
else
p.destroy
end
end
end
def is_banned?
!banned_till.nil? && banned_till > DateTime.now
end