Ability to block user
This commit is contained in:
parent
fb6d4511a0
commit
497ee5fbbc
9 changed files with 60 additions and 25 deletions
|
@ -40,9 +40,11 @@ class Admin::UsersController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
admin = params[:user].delete("admin")
|
admin = params[:user].delete("admin")
|
||||||
|
blocked = params[:user].delete("blocked")
|
||||||
|
|
||||||
@admin_user = User.new(params[:user])
|
@admin_user = User.new(params[:user])
|
||||||
@admin_user.admin = (admin && admin.to_i > 0)
|
@admin_user.admin = (admin && admin.to_i > 0)
|
||||||
|
@admin_user.blocked = blocked
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @admin_user.save
|
if @admin_user.save
|
||||||
|
@ -57,6 +59,8 @@ class Admin::UsersController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
admin = params[:user].delete("admin")
|
admin = params[:user].delete("admin")
|
||||||
|
blocked = params[:user].delete("blocked")
|
||||||
|
|
||||||
if params[:user][:password].blank?
|
if params[:user][:password].blank?
|
||||||
params[:user].delete(:password)
|
params[:user].delete(:password)
|
||||||
params[:user].delete(:password_confirmation)
|
params[:user].delete(:password_confirmation)
|
||||||
|
@ -64,6 +68,7 @@ class Admin::UsersController < ApplicationController
|
||||||
|
|
||||||
@admin_user = User.find(params[:id])
|
@admin_user = User.find(params[:id])
|
||||||
@admin_user.admin = (admin && admin.to_i > 0)
|
@admin_user.admin = (admin && admin.to_i > 0)
|
||||||
|
@admin_user.blocked = blocked
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @admin_user.update_attributes(params[:user])
|
if @admin_user.update_attributes(params[:user])
|
||||||
|
|
|
@ -16,6 +16,16 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
protected
|
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
|
def layout_by_resource
|
||||||
if devise_controller?
|
if devise_controller?
|
||||||
"devise"
|
"devise"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
%h3
|
%h3
|
||||||
Projects
|
Projects
|
||||||
= link_to 'New Project', new_admin_project_path, :class => "btn small right"
|
= link_to 'New Project', new_admin_project_path, :class => "btn small right"
|
||||||
%hr
|
%br
|
||||||
%table.zebra-striped
|
%table.zebra-striped.table-bordered
|
||||||
%thead
|
%thead
|
||||||
%th Name
|
%th Name
|
||||||
%th Path
|
%th Path
|
||||||
|
|
|
@ -32,10 +32,15 @@
|
||||||
.clearfix
|
.clearfix
|
||||||
= f.label :twitter
|
= f.label :twitter
|
||||||
.input= f.text_field :twitter
|
.input= f.text_field :twitter
|
||||||
|
%hr
|
||||||
.clearfix
|
.clearfix
|
||||||
= f.label :admin do
|
= f.label :admin do
|
||||||
= f.check_box :admin
|
= f.check_box :admin
|
||||||
%span Administrator
|
%span Administrator
|
||||||
|
.clearfix
|
||||||
|
= f.label :blocked do
|
||||||
|
= f.check_box :blocked
|
||||||
|
%span Blocked
|
||||||
.actions
|
.actions
|
||||||
= f.submit 'Save', :class => "btn primary"
|
= f.submit 'Save', :class => "btn primary"
|
||||||
- if @admin_user.new_record?
|
- if @admin_user.new_record?
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
%h3
|
%h3
|
||||||
Users
|
Users
|
||||||
= link_to 'New User', new_admin_user_path, :class => "btn small right"
|
= link_to 'New User', new_admin_user_path, :class => "btn small right"
|
||||||
%hr
|
%br
|
||||||
%table.zebra-striped
|
%table.zebra-striped.table-bordered
|
||||||
%thead
|
%thead
|
||||||
%th Admin
|
%th Admin
|
||||||
%th Name
|
%th Name
|
||||||
%th Email
|
%th Email
|
||||||
%th Projects
|
%th Projects
|
||||||
|
%th Blocked
|
||||||
%th
|
%th
|
||||||
%th
|
%th
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@
|
||||||
%td= link_to user.name, [:admin, user]
|
%td= link_to user.name, [:admin, user]
|
||||||
%td= user.email
|
%td= user.email
|
||||||
%td= user.users_projects.count
|
%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 '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"
|
%td= link_to 'Destroy', [:admin, user], :confirm => 'Are you sure?', :method => :delete, :class => "btn small danger"
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
%b
|
%b
|
||||||
Admin:
|
Admin:
|
||||||
%td= check_box_tag "admin", 1, @admin_user.admin, :disabled => :disabled
|
%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
|
%tr
|
||||||
%td
|
%td
|
||||||
%b
|
%b
|
||||||
|
|
|
@ -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
|
= 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
|
- if @project.owner == user
|
||||||
%span.label Project Owner
|
%span.label Project Owner
|
||||||
|
- if user.blocked
|
||||||
|
%span.label Blocked
|
||||||
|
|
5
db/migrate/20120413135904_add_blocked_field_to_user.rb
Normal file
5
db/migrate/20120413135904_add_blocked_field_to_user.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddBlockedFieldToUser < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :blocked, :boolean, :null => false, :default => false
|
||||||
|
end
|
||||||
|
end
|
43
db/schema.rb
43
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20120408181910) do
|
ActiveRecord::Schema.define(:version => 20120413135904) do
|
||||||
|
|
||||||
create_table "events", :force => true do |t|
|
create_table "events", :force => true do |t|
|
||||||
t.string "target_type"
|
t.string "target_type"
|
||||||
|
@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.integer "assignee_id"
|
t.integer "assignee_id"
|
||||||
t.integer "author_id"
|
t.integer "author_id"
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.boolean "closed", :default => false, :null => false
|
t.boolean "closed", :default => false, :null => false
|
||||||
t.integer "position", :default => 0
|
t.integer "position", :default => 0
|
||||||
t.boolean "critical", :default => false, :null => false
|
t.boolean "critical", :default => false, :null => false
|
||||||
|
@ -44,8 +44,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
|
|
||||||
create_table "keys", :force => true do |t|
|
create_table "keys", :force => true do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.text "key"
|
t.text "key"
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "identifier"
|
t.string "identifier"
|
||||||
|
@ -60,10 +60,10 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.integer "assignee_id"
|
t.integer "assignee_id"
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.boolean "closed", :default => false, :null => false
|
t.boolean "closed", :default => false, :null => false
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.text "st_commits", :limit => 2147483647
|
t.text "st_commits", :limit => 4294967295
|
||||||
t.text "st_diffs", :limit => 2147483647
|
t.text "st_diffs", :limit => 4294967295
|
||||||
t.boolean "merged", :default => false, :null => false
|
t.boolean "merged", :default => false, :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.string "noteable_id"
|
t.string "noteable_id"
|
||||||
t.string "noteable_type"
|
t.string "noteable_type"
|
||||||
t.integer "author_id"
|
t.integer "author_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
t.string "attachment"
|
t.string "attachment"
|
||||||
t.string "line_code"
|
t.string "line_code"
|
||||||
|
@ -98,8 +98,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "path"
|
t.string "path"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.boolean "private_flag", :default => true, :null => false
|
t.boolean "private_flag", :default => true, :null => false
|
||||||
t.string "code"
|
t.string "code"
|
||||||
t.integer "owner_id"
|
t.integer "owner_id"
|
||||||
|
@ -122,8 +122,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.text "content"
|
t.text "content"
|
||||||
t.integer "author_id", :null => false
|
t.integer "author_id", :null => false
|
||||||
t.integer "project_id", :null => false
|
t.integer "project_id", :null => false
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.string "file_name"
|
t.string "file_name"
|
||||||
t.datetime "expires_at"
|
t.datetime "expires_at"
|
||||||
end
|
end
|
||||||
|
@ -156,8 +156,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at"
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_sign_in_ip"
|
t.string "last_sign_in_ip"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.boolean "admin", :default => false, :null => false
|
t.boolean "admin", :default => false, :null => false
|
||||||
t.integer "projects_limit", :default => 10
|
t.integer "projects_limit", :default => 10
|
||||||
|
@ -168,6 +168,7 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
t.boolean "dark_scheme", :default => false, :null => false
|
t.boolean "dark_scheme", :default => false, :null => false
|
||||||
t.integer "theme_id", :default => 1, :null => false
|
t.integer "theme_id", :default => 1, :null => false
|
||||||
t.string "bio"
|
t.string "bio"
|
||||||
|
t.boolean "blocked", :default => false, :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||||
|
@ -176,16 +177,16 @@ ActiveRecord::Schema.define(:version => 20120408181910) do
|
||||||
create_table "users_projects", :force => true do |t|
|
create_table "users_projects", :force => true do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.integer "project_id", :null => false
|
t.integer "project_id", :null => false
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
t.integer "project_access", :default => 0, :null => false
|
t.integer "project_access", :default => 0, :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "web_hooks", :force => true do |t|
|
create_table "web_hooks", :force => true do |t|
|
||||||
t.string "url"
|
t.string "url"
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "wikis", :force => true do |t|
|
create_table "wikis", :force => true do |t|
|
||||||
|
|
Loading…
Reference in a new issue