mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-29 23:43:55 -04:00
added delete all posts button
wired up the ability to enable all themes
This commit is contained in:
parent
8f4417f962
commit
85973ce6b0
13 changed files with 93 additions and 17 deletions
app
assets/javascripts/admin
controllers/admin
models
serializers
views/layouts
config
lib
spec/models
|
@ -1,10 +1,14 @@
|
||||||
window.Discourse.AdminUser = Discourse.Model.extend
|
window.Discourse.AdminUser = Discourse.Model.extend
|
||||||
|
|
||||||
|
deleteAllPosts: ->
|
||||||
|
@set('can_delete_all_posts', false)
|
||||||
|
$.ajax "/admin/users/#{@get('id')}/delete_all_posts", type: 'PUT'
|
||||||
|
|
||||||
# Revoke the user's admin access
|
# Revoke the user's admin access
|
||||||
revokeAdmin: ->
|
revokeAdmin: ->
|
||||||
@set('admin',false)
|
@set('admin',false)
|
||||||
@set('can_grant_admin',true)
|
@set('can_grant_admin',true)
|
||||||
@set('can_revoke_admin',false)
|
@set('can_revoke_admin',false)
|
||||||
$.ajax "/admin/users/#{@get('id')}/revoke_admin", type: 'PUT'
|
$.ajax "/admin/users/#{@get('id')}/revoke_admin", type: 'PUT'
|
||||||
|
|
||||||
grantAdmin: ->
|
grantAdmin: ->
|
||||||
|
@ -18,13 +22,11 @@ window.Discourse.AdminUser = Discourse.Model.extend
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
bootbox.alert("Message sent to all clients!")
|
bootbox.alert("Message sent to all clients!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
approve: ->
|
approve: ->
|
||||||
@set('can_approve', false)
|
@set('can_approve', false)
|
||||||
@set('approved', true)
|
@set('approved', true)
|
||||||
@set('approved_by', Discourse.get('currentUser'))
|
@set('approved_by', Discourse.get('currentUser'))
|
||||||
$.ajax "/admin/users/#{@get('id')}/approve", type: 'PUT'
|
$.ajax "/admin/users/#{@get('id')}/approve", type: 'PUT'
|
||||||
|
|
||||||
username_lower:(->
|
username_lower:(->
|
||||||
@get('username').toLowerCase()
|
@get('username').toLowerCase()
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td class='message'>
|
<td class='message'>
|
||||||
<div>{{avatar user imageSize="small"}} {{message}}</div>
|
<div><a href="/admin{{unbound user.path}}">{{avatar user imageSize="small"}}</a> {{message}}</div>
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|
|
@ -139,6 +139,14 @@
|
||||||
<div class='display-row'>
|
<div class='display-row'>
|
||||||
<div class='field'>{{i18n admin.user.post_count}}</div>
|
<div class='field'>{{i18n admin.user.post_count}}</div>
|
||||||
<div class='value'>{{content.post_count}}</div>
|
<div class='value'>{{content.post_count}}</div>
|
||||||
|
<div class='controls'>
|
||||||
|
{{#if content.can_delete_all_posts}}
|
||||||
|
<button class='btn' {{action deleteAllPosts target="content"}}>
|
||||||
|
<i class='icon icon-trash'></i>
|
||||||
|
{{i18n admin.user.delete_all_posts}}
|
||||||
|
</button>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='display-row'>
|
<div class='display-row'>
|
||||||
<div class='field'>{{i18n admin.user.posts_read_count}}</div>
|
<div class='field'>{{i18n admin.user.posts_read_count}}</div>
|
||||||
|
|
|
@ -19,6 +19,11 @@ class Admin::UsersController < Admin::AdminController
|
||||||
render_serialized(@user, AdminDetailedUserSerializer, root: false)
|
render_serialized(@user, AdminDetailedUserSerializer, root: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_all_posts
|
||||||
|
@user = User.where(id: params[:user_id]).first
|
||||||
|
@user.delete_all_posts!(guardian)
|
||||||
|
render nothing: true
|
||||||
|
end
|
||||||
def ban
|
def ban
|
||||||
@user = User.where(id: params[:user_id]).first
|
@user = User.where(id: params[:user_id]).first
|
||||||
guardian.ensure_can_ban!(@user)
|
guardian.ensure_can_ban!(@user)
|
||||||
|
|
|
@ -319,11 +319,11 @@ class Post < ActiveRecord::Base
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
self.last_version_at = revised_at
|
self.last_version_at = revised_at
|
||||||
updater.call(true)
|
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.
|
# 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?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class SiteCustomization < ActiveRecord::Base
|
class SiteCustomization < ActiveRecord::Base
|
||||||
|
|
||||||
|
ENABLED_KEY = '7e202ef2-56d7-47d5-98d8-a9c8d15e57dd'
|
||||||
CACHE_PATH = 'stylesheet-cache'
|
CACHE_PATH = 'stylesheet-cache'
|
||||||
@lock = Mutex.new
|
@lock = Mutex.new
|
||||||
|
|
||||||
|
@ -49,18 +50,36 @@ footer:after{ content: '#{error}' }"
|
||||||
self.remove_from_cache!
|
self.remove_from_cache!
|
||||||
end
|
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)
|
def self.custom_stylesheet(preview_style)
|
||||||
|
preview_style ||= enabled_style
|
||||||
style = lookup_style(preview_style)
|
style = lookup_style(preview_style)
|
||||||
style.stylesheet_link_tag.html_safe if style
|
style.stylesheet_link_tag.html_safe if style
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.custom_header(preview_style)
|
def self.custom_header(preview_style)
|
||||||
|
preview_style ||= enabled_style
|
||||||
style = lookup_style(preview_style)
|
style = lookup_style(preview_style)
|
||||||
style.header.html_safe if style
|
style.header.html_safe if style
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.override_default_style(preview_style)
|
def self.override_default_style(preview_style)
|
||||||
|
preview_style ||= enabled_style
|
||||||
style = lookup_style(preview_style)
|
style = lookup_style(preview_style)
|
||||||
style.override_default_style if style
|
style.override_default_style if style
|
||||||
end
|
end
|
||||||
|
@ -103,6 +122,7 @@ footer:after{ content: '#{error}' }"
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_from_cache!
|
def remove_from_cache!
|
||||||
|
self.class.remove_from_cache!(ENABLED_KEY)
|
||||||
self.class.remove_from_cache!(self.key)
|
self.class.remove_from_cache!(self.key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -335,6 +335,18 @@ class User < ActiveRecord::Base
|
||||||
PrettyText.excerpt(bio_cooked, 350)
|
PrettyText.excerpt(bio_cooked, 350)
|
||||||
end
|
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?
|
def is_banned?
|
||||||
!banned_till.nil? && banned_till > DateTime.now
|
!banned_till.nil? && banned_till > DateTime.now
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,8 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
||||||
:post_count,
|
:post_count,
|
||||||
:flags_given_count,
|
:flags_given_count,
|
||||||
:flags_received_count,
|
:flags_received_count,
|
||||||
:private_topics_count
|
:private_topics_count,
|
||||||
|
:can_delete_all_posts
|
||||||
|
|
||||||
has_one :approved_by, serializer: BasicUserSerializer, embed: :objects
|
has_one :approved_by, serializer: BasicUserSerializer, embed: :objects
|
||||||
|
|
||||||
|
@ -19,6 +20,10 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
||||||
def can_grant_admin
|
def can_grant_admin
|
||||||
scope.can_grant_admin?(object)
|
scope.can_grant_admin?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_delete_all_posts
|
||||||
|
scope.can_delete_all_posts?(object)
|
||||||
|
end
|
||||||
|
|
||||||
def moderator
|
def moderator
|
||||||
object.has_trust_level?(:moderator)
|
object.has_trust_level?(:moderator)
|
||||||
|
|
|
@ -50,11 +50,7 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<%- unless SiteCustomization.override_default_style(session[:preview_style]) %>
|
<%- unless SiteCustomization.override_default_style(session[:preview_style]) %>
|
||||||
<%- if params[:shiny] %>
|
<%=stylesheet_link_tag "application"%>
|
||||||
<%=stylesheet_link_tag "shiny/shiny"%>
|
|
||||||
<%- else %>
|
|
||||||
<%=stylesheet_link_tag "application"%>
|
|
||||||
<%- end %>
|
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
<%- if mini_profiler_enabled? %>
|
<%- if mini_profiler_enabled? %>
|
||||||
|
|
|
@ -369,6 +369,7 @@ en:
|
||||||
ban_failed: "Something went wrong banning this user {{error}}"
|
ban_failed: "Something went wrong banning this user {{error}}"
|
||||||
unban_failed: "Something went wrong unbanning this user {{error}}"
|
unban_failed: "Something went wrong unbanning this user {{error}}"
|
||||||
ban_duration: "How long would you like to ban the user for? (days)"
|
ban_duration: "How long would you like to ban the user for? (days)"
|
||||||
|
delete_all_posts: "Delete all posts"
|
||||||
ban: "Ban"
|
ban: "Ban"
|
||||||
unban: "Unban"
|
unban: "Unban"
|
||||||
banned: "Banned?"
|
banned: "Banned?"
|
||||||
|
|
|
@ -30,6 +30,7 @@ Discourse::Application.routes.draw do
|
||||||
put 'approve-bulk' => 'users#approve_bulk'
|
put 'approve-bulk' => 'users#approve_bulk'
|
||||||
end
|
end
|
||||||
put 'ban' => 'users#ban'
|
put 'ban' => 'users#ban'
|
||||||
|
put 'delete_all_posts' => 'users#delete_all_posts'
|
||||||
put 'unban' => 'users#unban'
|
put 'unban' => 'users#unban'
|
||||||
put 'revoke_admin' => 'users#revoke_admin'
|
put 'revoke_admin' => 'users#revoke_admin'
|
||||||
put 'grant_admin' => 'users#grant_admin'
|
put 'grant_admin' => 'users#grant_admin'
|
||||||
|
|
|
@ -167,6 +167,13 @@ class Guardian
|
||||||
@user.id == user_id
|
@user.id == user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_delete_all_posts?(user)
|
||||||
|
return false unless is_admin?
|
||||||
|
return false if user.created_at < 7.days.ago
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
# Support for ensure_{blah}! methods.
|
# Support for ensure_{blah}! methods.
|
||||||
def method_missing(method, *args, &block)
|
def method_missing(method, *args, &block)
|
||||||
if method.to_s =~ /^ensure_(.*)\!$/
|
if method.to_s =~ /^ensure_(.*)\!$/
|
||||||
|
|
|
@ -67,12 +67,8 @@ describe User do
|
||||||
user.reload
|
user.reload
|
||||||
user.posts_read_count.should == 1
|
user.posts_read_count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context '.enqueue_welcome_message' do
|
context '.enqueue_welcome_message' do
|
||||||
|
@ -174,6 +170,29 @@ describe User do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'delete posts' do
|
||||||
|
before do
|
||||||
|
@post1 = Fabricate(:post)
|
||||||
|
@user = @post1.user
|
||||||
|
@post2 = Fabricate(:post, topic: @post1.topic, user: @user)
|
||||||
|
@post3 = Fabricate(:post, user: @user)
|
||||||
|
@posts = [@post1, @post2, @post3]
|
||||||
|
@guardian = Guardian.new(Fabricate(:admin))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'allows moderator to delete all posts' do
|
||||||
|
@user.delete_all_posts!(@guardian)
|
||||||
|
@posts.each do |p|
|
||||||
|
p.reload
|
||||||
|
if p
|
||||||
|
p.topic.should be_nil
|
||||||
|
else
|
||||||
|
p.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'new' do
|
describe 'new' do
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue