Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to delete spammers

  • Loading branch information...
commit 714ba74cb402419bf751932e060c76ba0aa05698 1 parent 6026ef7
@rkuykendall authored
View
22 app/controllers/users_controller.rb
@@ -23,7 +23,7 @@ def show
@reviews = Review.find(:all, :order => 'created_at DESC', :conditions => [ 'user_id = ?', @user.id ] )
respond_to do |format|
- if permission(@user)
+ if permission(@user) && !admin?
format.html { render :action => "manage" }
else
format.html { render :action => "show" }
@@ -74,11 +74,29 @@ def update
end
end
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ @users = User.find_by_permalink(params[:id])
+ @users.destroy
+
+ respond_to do |format|
+ flash[:notice] = "<strong>#{params[:id]}</strong> has been destroyed."
+ format.html { redirect_to '/' }
+ format.xml { render :nothing => true }
+ end
+ end
+
private
def users_before
@user = User.find_by_permalink(params[:id])
- access_denied unless permission(@user)
+
+ if action_name == 'destroy'
+ access_denied unless admin?
+ else
+ access_denied unless permission(@user)
+ end
end
end
View
2  app/models/user.rb
@@ -10,6 +10,8 @@ class User < ActiveRecord::Base
# you can also specifiy a different permalink field in your database by giving a second paramater
# has_permalink :title, :my_permalink_field
+ has_many :reviews, :dependent => :destroy
+ has_many :items, :dependent => :destroy
# we now add the to_param method which Rails's routing uses
def to_param
View
7 app/views/users/show.html.erb
@@ -1,4 +1,9 @@
-<h1><%= link_to pagetitle(@user.login), user_path(@user) %></h1>
+<h1>
+ <%= link_to pagetitle(@user.login), user_path(@user) %>
+ <% if permission(@user) %>
+ <%= link_to("Delete this spammer", user_url(@user), :class => 'button negative delete', :confirm => "Are you sure? This will destroy everything he owns.", :method => :delete) if admin? %>
+ <% end %>
+</h1>
<div class="content">
<h2><%= pluralize(@items.size, 'Submission') %></h2>
View
5 public/stylesheets/application.css
@@ -137,6 +137,11 @@ form.cmxform input[type=submit] {
}
+h1 .button {
+ position: relative;
+ top: -10px;
+}
+
.button:hover {
/* Colors: Standard */
background-color: #dff4ff;
Please sign in to comment.
Something went wrong with that request. Please try again.