diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 5b27d11..bed47e4 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -69,7 +69,8 @@ display: inline-block; float: left; margin: 12px 0; - width: 33%; + min-height: 80px; + width: 32%; } img { height: 50px; @@ -80,6 +81,9 @@ float: right; margin-right: 60px; } + a.wl-button { + margin: 5px auto 0; + } } .admin-table { color: #333; diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 61a83a5..24f1b84 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -38,6 +38,11 @@ def user_update head :ok end + def delete_user + User.find(params[:id]).destroy + redirect_to :admin_users + end + def options @results = Language.find(:all, :order => "title") get_used_items(Language) diff --git a/app/models/user.rb b/app/models/user.rb index 876ea60..7bb097e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,7 @@ class User < ActiveRecord::Base include ValidatesAsImage before_save :calculate_fields + after_destroy :destroy_inactive_widgets has_attached_file :avatar, :styles => { @@ -8,8 +9,8 @@ class User < ActiveRecord::Base :medium => ["100x100!", :png], :large => ["800x800", :png] }, :default_url => "register_default_image.jpg" - has_many :widgets - has_many :downloads + has_many :widgets, :dependent => :destroy + has_many :downloads, :dependent => :destroy # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, @@ -62,5 +63,7 @@ def calculate_fields self.name = "#{self.first_name} #{self.last_name}" self.url_title = "#{self.first_name.to_s.downcase}-#{self.last_name.to_s.downcase}" end - + def destroy_inactive_widgets + Widget.where("user_id = ?", self.id).destroy_all + end end diff --git a/app/views/admin/_user.html.erb b/app/views/admin/_user.html.erb index 5819626..74ae2aa 100644 --- a/app/views/admin/_user.html.erb +++ b/app/views/admin/_user.html.erb @@ -13,6 +13,7 @@ <% if user_signed_in? && current_user.id != user.id %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer %> + <%= link_to "Remove User", admin_delete_user_path(user), :confirm => "Are you sure you want to delete this user?", :class => "wl-button wl-overlay-button", :method => "delete" %> <% else %> <%= check_box_tag "chk_user_reviewer#{user.id}", 1, user.reviewer, :disabled => true %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8a11596..9f4f6eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,6 +50,7 @@ # Admin section match '/admin/users' => 'admin#users', :as => :admin_users match '/admin/users/admin' => 'admin#adminusers', :as => :admin_admin_users + delete '/admin/users/delete/:id' => 'admin#delete_user', :as => :admin_delete_user match '/admin/options' => 'admin#options', :as => :admin_options match '/admin/languages/edit/:id' => 'admin#edit_language', :as => :admin_edit_language post '/admin/languages/save' => 'admin#save_language', :as => :admin_add_edit_language