Ability to block user

This commit is contained in:
randx 2012-04-13 08:12:34 +03:00
parent fb6d4511a0
commit 497ee5fbbc
9 changed files with 60 additions and 25 deletions

View file

@ -40,9 +40,11 @@ class Admin::UsersController < ApplicationController
def create
admin = params[:user].delete("admin")
blocked = params[:user].delete("blocked")
@admin_user = User.new(params[:user])
@admin_user.admin = (admin && admin.to_i > 0)
@admin_user.blocked = blocked
respond_to do |format|
if @admin_user.save
@ -57,6 +59,8 @@ class Admin::UsersController < ApplicationController
def update
admin = params[:user].delete("admin")
blocked = params[:user].delete("blocked")
if params[:user][:password].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
@ -64,6 +68,7 @@ class Admin::UsersController < ApplicationController
@admin_user = User.find(params[:id])
@admin_user.admin = (admin && admin.to_i > 0)
@admin_user.blocked = blocked
respond_to do |format|
if @admin_user.update_attributes(params[:user])

View file

@ -16,6 +16,16 @@ class ApplicationController < ActionController::Base
protected
def after_sign_in_path_for resource
if resource.is_a?(User) && resource.respond_to?(:blocked) && resource.blocked
sign_out resource
flash[:alert] = "Your account was blocked"
new_user_session_path
else
super
end
end
def layout_by_resource
if devise_controller?
"devise"

View file

@ -1,8 +1,8 @@
%h3
Projects
= link_to 'New Project', new_admin_project_path, :class => "btn small right"
%hr
%table.zebra-striped
%br
%table.zebra-striped.table-bordered
%thead
%th Name
%th Path

View file

@ -32,10 +32,15 @@
.clearfix
= f.label :twitter
.input= f.text_field :twitter
%hr
.clearfix
= f.label :admin do
= f.check_box :admin
%span Administrator
.clearfix
= f.label :blocked do
= f.check_box :blocked
%span Blocked
.actions
= f.submit 'Save', :class => "btn primary"
- if @admin_user.new_record?

View file

@ -1,13 +1,14 @@
%h3
Users
= link_to 'New User', new_admin_user_path, :class => "btn small right"
%hr
%table.zebra-striped
%br
%table.zebra-striped.table-bordered
%thead
%th Admin
%th Name
%th Email
%th Projects
%th Blocked
%th
%th
@ -17,6 +18,7 @@
%td= link_to user.name, [:admin, user]
%td= user.email
%td= user.users_projects.count
%td= check_box_tag "blocked", 1, user.blocked, :disabled => :disabled
%td= link_to 'Edit', edit_admin_user_path(user), :id => "edit_#{dom_id(user)}", :class => "btn small"
%td= link_to 'Destroy', [:admin, user], :confirm => 'Are you sure?', :method => :delete, :class => "btn small danger"

View file

@ -16,6 +16,11 @@
%b
Admin:
%td= check_box_tag "admin", 1, @admin_user.admin, :disabled => :disabled
%tr
%td
%b
Blocked:
%td= check_box_tag "blocked", 1, @admin_user.blocked, :disabled => :disabled
%tr
%td
%b

View file

@ -13,3 +13,5 @@
= f.select :project_access, options_for_select(UsersProject.access_roles, member.project_access), {}, :class => "medium project-access-select", :disabled => !allow_admin
- if @project.owner == user
%span.label Project Owner
- if user.blocked
%span.label Blocked