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