Commit 497ee5fbbc781c8a5ffb754de5f8f5a46304aa57
1 parent
fb6d4511
Exists in
master
and in
4 other branches
Ability to block user
Showing
9 changed files
with
60 additions
and
25 deletions
Show diff stats
app/controllers/admin/users_controller.rb
| ... | ... | @@ -40,9 +40,11 @@ class Admin::UsersController < ApplicationController |
| 40 | 40 | |
| 41 | 41 | def create |
| 42 | 42 | admin = params[:user].delete("admin") |
| 43 | + blocked = params[:user].delete("blocked") | |
| 43 | 44 | |
| 44 | 45 | @admin_user = User.new(params[:user]) |
| 45 | 46 | @admin_user.admin = (admin && admin.to_i > 0) |
| 47 | + @admin_user.blocked = blocked | |
| 46 | 48 | |
| 47 | 49 | respond_to do |format| |
| 48 | 50 | if @admin_user.save |
| ... | ... | @@ -57,6 +59,8 @@ class Admin::UsersController < ApplicationController |
| 57 | 59 | |
| 58 | 60 | def update |
| 59 | 61 | admin = params[:user].delete("admin") |
| 62 | + blocked = params[:user].delete("blocked") | |
| 63 | + | |
| 60 | 64 | if params[:user][:password].blank? |
| 61 | 65 | params[:user].delete(:password) |
| 62 | 66 | params[:user].delete(:password_confirmation) |
| ... | ... | @@ -64,6 +68,7 @@ class Admin::UsersController < ApplicationController |
| 64 | 68 | |
| 65 | 69 | @admin_user = User.find(params[:id]) |
| 66 | 70 | @admin_user.admin = (admin && admin.to_i > 0) |
| 71 | + @admin_user.blocked = blocked | |
| 67 | 72 | |
| 68 | 73 | respond_to do |format| |
| 69 | 74 | if @admin_user.update_attributes(params[:user]) | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -16,6 +16,16 @@ class ApplicationController < ActionController::Base |
| 16 | 16 | |
| 17 | 17 | protected |
| 18 | 18 | |
| 19 | + def after_sign_in_path_for resource | |
| 20 | + if resource.is_a?(User) && resource.respond_to?(:blocked) && resource.blocked | |
| 21 | + sign_out resource | |
| 22 | + flash[:alert] = "Your account was blocked" | |
| 23 | + new_user_session_path | |
| 24 | + else | |
| 25 | + super | |
| 26 | + end | |
| 27 | + end | |
| 28 | + | |
| 19 | 29 | def layout_by_resource |
| 20 | 30 | if devise_controller? |
| 21 | 31 | "devise" | ... | ... |
app/views/admin/projects/index.html.haml
app/views/admin/users/_form.html.haml
| ... | ... | @@ -32,10 +32,15 @@ |
| 32 | 32 | .clearfix |
| 33 | 33 | = f.label :twitter |
| 34 | 34 | .input= f.text_field :twitter |
| 35 | + %hr | |
| 35 | 36 | .clearfix |
| 36 | 37 | = f.label :admin do |
| 37 | 38 | = f.check_box :admin |
| 38 | 39 | %span Administrator |
| 40 | + .clearfix | |
| 41 | + = f.label :blocked do | |
| 42 | + = f.check_box :blocked | |
| 43 | + %span Blocked | |
| 39 | 44 | .actions |
| 40 | 45 | = f.submit 'Save', :class => "btn primary" |
| 41 | 46 | - if @admin_user.new_record? | ... | ... |
app/views/admin/users/index.html.haml
| 1 | 1 | %h3 |
| 2 | 2 | Users |
| 3 | 3 | = link_to 'New User', new_admin_user_path, :class => "btn small right" |
| 4 | -%hr | |
| 5 | -%table.zebra-striped | |
| 4 | +%br | |
| 5 | +%table.zebra-striped.table-bordered | |
| 6 | 6 | %thead |
| 7 | 7 | %th Admin |
| 8 | 8 | %th Name |
| 9 | 9 | %th Email |
| 10 | 10 | %th Projects |
| 11 | + %th Blocked | |
| 11 | 12 | %th |
| 12 | 13 | %th |
| 13 | 14 | |
| ... | ... | @@ -17,6 +18,7 @@ |
| 17 | 18 | %td= link_to user.name, [:admin, user] |
| 18 | 19 | %td= user.email |
| 19 | 20 | %td= user.users_projects.count |
| 21 | + %td= check_box_tag "blocked", 1, user.blocked, :disabled => :disabled | |
| 20 | 22 | %td= link_to 'Edit', edit_admin_user_path(user), :id => "edit_#{dom_id(user)}", :class => "btn small" |
| 21 | 23 | %td= link_to 'Destroy', [:admin, user], :confirm => 'Are you sure?', :method => :delete, :class => "btn small danger" |
| 22 | 24 | ... | ... |
app/views/admin/users/show.html.haml
app/views/team_members/_show.html.haml
| ... | ... | @@ -13,3 +13,5 @@ |
| 13 | 13 | = f.select :project_access, options_for_select(UsersProject.access_roles, member.project_access), {}, :class => "medium project-access-select", :disabled => !allow_admin |
| 14 | 14 | - if @project.owner == user |
| 15 | 15 | %span.label Project Owner |
| 16 | + - if user.blocked | |
| 17 | + %span.label Blocked | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(:version => 20120408181910) do | |
| 14 | +ActiveRecord::Schema.define(:version => 20120413135904) do | |
| 15 | 15 | |
| 16 | 16 | create_table "events", :force => true do |t| |
| 17 | 17 | t.string "target_type" |
| ... | ... | @@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 30 | 30 | t.integer "assignee_id" |
| 31 | 31 | t.integer "author_id" |
| 32 | 32 | t.integer "project_id" |
| 33 | - t.datetime "created_at", :null => false | |
| 34 | - t.datetime "updated_at", :null => false | |
| 33 | + t.datetime "created_at" | |
| 34 | + t.datetime "updated_at" | |
| 35 | 35 | t.boolean "closed", :default => false, :null => false |
| 36 | 36 | t.integer "position", :default => 0 |
| 37 | 37 | t.boolean "critical", :default => false, :null => false |
| ... | ... | @@ -44,8 +44,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 44 | 44 | |
| 45 | 45 | create_table "keys", :force => true do |t| |
| 46 | 46 | t.integer "user_id" |
| 47 | - t.datetime "created_at", :null => false | |
| 48 | - t.datetime "updated_at", :null => false | |
| 47 | + t.datetime "created_at" | |
| 48 | + t.datetime "updated_at" | |
| 49 | 49 | t.text "key" |
| 50 | 50 | t.string "title" |
| 51 | 51 | t.string "identifier" |
| ... | ... | @@ -60,10 +60,10 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 60 | 60 | t.integer "assignee_id" |
| 61 | 61 | t.string "title" |
| 62 | 62 | t.boolean "closed", :default => false, :null => false |
| 63 | - t.datetime "created_at", :null => false | |
| 64 | - t.datetime "updated_at", :null => false | |
| 65 | - t.text "st_commits", :limit => 2147483647 | |
| 66 | - t.text "st_diffs", :limit => 2147483647 | |
| 63 | + t.datetime "created_at" | |
| 64 | + t.datetime "updated_at" | |
| 65 | + t.text "st_commits", :limit => 4294967295 | |
| 66 | + t.text "st_diffs", :limit => 4294967295 | |
| 67 | 67 | t.boolean "merged", :default => false, :null => false |
| 68 | 68 | end |
| 69 | 69 | |
| ... | ... | @@ -84,8 +84,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 84 | 84 | t.string "noteable_id" |
| 85 | 85 | t.string "noteable_type" |
| 86 | 86 | t.integer "author_id" |
| 87 | - t.datetime "created_at", :null => false | |
| 88 | - t.datetime "updated_at", :null => false | |
| 87 | + t.datetime "created_at" | |
| 88 | + t.datetime "updated_at" | |
| 89 | 89 | t.integer "project_id" |
| 90 | 90 | t.string "attachment" |
| 91 | 91 | t.string "line_code" |
| ... | ... | @@ -98,8 +98,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 98 | 98 | t.string "name" |
| 99 | 99 | t.string "path" |
| 100 | 100 | t.text "description" |
| 101 | - t.datetime "created_at", :null => false | |
| 102 | - t.datetime "updated_at", :null => false | |
| 101 | + t.datetime "created_at" | |
| 102 | + t.datetime "updated_at" | |
| 103 | 103 | t.boolean "private_flag", :default => true, :null => false |
| 104 | 104 | t.string "code" |
| 105 | 105 | t.integer "owner_id" |
| ... | ... | @@ -122,8 +122,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 122 | 122 | t.text "content" |
| 123 | 123 | t.integer "author_id", :null => false |
| 124 | 124 | t.integer "project_id", :null => false |
| 125 | - t.datetime "created_at", :null => false | |
| 126 | - t.datetime "updated_at", :null => false | |
| 125 | + t.datetime "created_at" | |
| 126 | + t.datetime "updated_at" | |
| 127 | 127 | t.string "file_name" |
| 128 | 128 | t.datetime "expires_at" |
| 129 | 129 | end |
| ... | ... | @@ -156,8 +156,8 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 156 | 156 | t.datetime "last_sign_in_at" |
| 157 | 157 | t.string "current_sign_in_ip" |
| 158 | 158 | t.string "last_sign_in_ip" |
| 159 | - t.datetime "created_at", :null => false | |
| 160 | - t.datetime "updated_at", :null => false | |
| 159 | + t.datetime "created_at" | |
| 160 | + t.datetime "updated_at" | |
| 161 | 161 | t.string "name" |
| 162 | 162 | t.boolean "admin", :default => false, :null => false |
| 163 | 163 | t.integer "projects_limit", :default => 10 |
| ... | ... | @@ -168,6 +168,7 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 168 | 168 | t.boolean "dark_scheme", :default => false, :null => false |
| 169 | 169 | t.integer "theme_id", :default => 1, :null => false |
| 170 | 170 | t.string "bio" |
| 171 | + t.boolean "blocked", :default => false, :null => false | |
| 171 | 172 | end |
| 172 | 173 | |
| 173 | 174 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
| ... | ... | @@ -176,16 +177,16 @@ ActiveRecord::Schema.define(:version => 20120408181910) do |
| 176 | 177 | create_table "users_projects", :force => true do |t| |
| 177 | 178 | t.integer "user_id", :null => false |
| 178 | 179 | t.integer "project_id", :null => false |
| 179 | - t.datetime "created_at", :null => false | |
| 180 | - t.datetime "updated_at", :null => false | |
| 180 | + t.datetime "created_at" | |
| 181 | + t.datetime "updated_at" | |
| 181 | 182 | t.integer "project_access", :default => 0, :null => false |
| 182 | 183 | end |
| 183 | 184 | |
| 184 | 185 | create_table "web_hooks", :force => true do |t| |
| 185 | 186 | t.string "url" |
| 186 | 187 | t.integer "project_id" |
| 187 | - t.datetime "created_at", :null => false | |
| 188 | - t.datetime "updated_at", :null => false | |
| 188 | + t.datetime "created_at" | |
| 189 | + t.datetime "updated_at" | |
| 189 | 190 | end |
| 190 | 191 | |
| 191 | 192 | create_table "wikis", :force => true do |t| | ... | ... |