Permalink
Browse files

User blocking improved. Admin area styled

  • Loading branch information...
1 parent c0df0cd commit c9def945d4222eeb8026a0311495259bf99267a1 @randx randx committed Apr 16, 2012
View
@@ -1,5 +1,13 @@
v 2.4.0
+ - Ability to block user
+ - Simplified dashboard area
+ - Improved admin area
- Accept merge request
+ - Bootstrap 2.0
+ - Responsive layout
+ - Big commits handling
+ - Perfomance improved
+ - Milestones
v 2.3.1
- Issues pagination
@@ -450,3 +450,17 @@ form {
}
}
+
+table.admin-table {
+ @extend .table-bordered;
+ @extend .zebra-striped;
+ th {
+ border-color: #CCC;
+ border-bottom: 1px solid #bbb;
+ background:#eee;
+ background-image: -webkit-gradient(linear, 0 0, 0 30, color-stop(0.066, #eee), to(#dfdfdf));
+ background-image: -webkit-linear-gradient(#eee 6.6%, #dfdfdf);
+ background-image: -moz-linear-gradient(#eee 6.6%, #dfdfdf);
+ background-image: -o-linear-gradient(#eee 6.6%, #dfdfdf);
+ }
+}
@@ -4,7 +4,9 @@ class Admin::UsersController < ApplicationController
before_filter :authenticate_admin!
def index
- @admin_users = User.page(params[:page])
+ @admin_users = User.scoped
+ @admin_users = @admin_users.filter(params[:filter])
+ @admin_users = @admin_users.order("updated_at DESC").page(params[:page])
end
def show
@@ -38,13 +40,31 @@ def edit
@admin_user = User.find(params[:id])
end
+ def block
+ @admin_user = User.find(params[:id])
+
+ if @admin_user.block
+ redirect_to :back, alert: "Successfully blocked"
+ else
+ redirect_to :back, alert: "Error occured. User was not blocked"
+ end
+ end
+
+ def unblock
+ @admin_user = User.find(params[:id])
+
+ if @admin_user.update_attribute(:blocked, false)
+ redirect_to :back, alert: "Successfully unblocked"
+ else
+ redirect_to :back, alert: "Error occured. User was not unblocked"
+ end
+ end
+
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
@@ -59,7 +79,6 @@ def create
def update
admin = params[:user].delete("admin")
- blocked = params[:user].delete("blocked")
if params[:user][:password].blank?
params[:user].delete(:password)
@@ -68,7 +87,6 @@ def update
@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])
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
+ before_filter :reject_blocked!
before_filter :set_current_user_for_mailer
protect_from_forgery
helper_method :abilities, :can?
@@ -16,6 +17,14 @@ class ApplicationController < ActionController::Base
protected
+ def reject_blocked!
+ if current_user && current_user.blocked
+ sign_out current_user
+ flash[:alert] = "Your account was blocked"
+ redirect_to new_user_session_path
+ end
+ end
+
def after_sign_in_path_for resource
if resource.is_a?(User) && resource.respond_to?(:blocked) && resource.blocked
sign_out resource
View
@@ -48,7 +48,25 @@ class User < ActiveRecord::Base
before_create :ensure_authentication_token
alias_attribute :private_token, :authentication_token
+
scope :not_in_project, lambda { |project| where("id not in (:ids)", :ids => project.users.map(&:id) ) }
+ scope :admins, where(:admin => true)
+ scope :blocked, where(:blocked => true)
+ scope :active, where(:blocked => false)
+
+ def self.filter filter_name
+ case filter_name
+ when "admins"; self.admins
+ when "blocked"; self.blocked
+ when "wop"; self.without_projects
+ else
+ self.active
+ end
+ end
+
+ def self.without_projects
+ where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)')
+ end
def identifier
email.gsub /[@.]/, "_"
@@ -58,6 +76,7 @@ def is_admin?
admin
end
+
def require_ssh_key?
keys.count == 0
end
@@ -101,6 +120,17 @@ def cared_merge_requests
def project_ids
projects.map(&:id)
end
+
+ # Remove user from all projects and
+ # set blocked attribute to true
+ def block
+ users_projects.all.each do |membership|
+ return false unless membership.destroy
+ end
+
+ self.blocked = true
+ save
+ end
end
# == Schema Information
#
@@ -2,7 +2,7 @@
Projects
= link_to 'New Project', new_admin_project_path, :class => "btn small right"
%br
-%table.zebra-striped.table-bordered
+%table.admin-table
%thead
%th Name
%th Path
@@ -2,9 +2,8 @@
= @admin_project.name
= link_to 'Edit', edit_admin_project_path(@admin_project), :class => "btn right small"
-%hr
-
-%table.zebra-striped
+%br
+%table.zebra-striped.table-bordered
%tr
%td
%b
@@ -29,47 +28,47 @@
Description:
%td
= @admin_project.description
+%br
+%h3
+ Team
+ %small
+ (#{@admin_project.users_projects.count})
+%br
+%table.zebra-striped.table-bordered
+ %thead
+ %tr
+ %th Name
+ %th Project Access
+ %th Repository Access
+ %th
+ - @admin_project.users_projects.each do |tm|
+ %tr
+ %td
+ = link_to tm.user_name, admin_user_path(tm.user)
+ %td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), :class => "medium project-access-select", :disabled => :disabled
+ %td= link_to 'Edit Access', edit_admin_team_member_path(tm), :class => "btn small"
+ %td= link_to 'Remove from team', admin_team_member_path(tm), :confirm => 'Are you sure?', :method => :delete, :class => "btn danger small"
-.span12
-
- %h3
- Team
- %small
- (#{@admin_project.users_projects.count})
-
- %hr
-
- %table.zebra-striped
+%br
+%h3 Add new team member
+%br
+= form_tag team_update_admin_project_path(@admin_project), :class => "bulk_import", :method => :put do
+ %table.zebra-striped.table-bordered
%thead
%tr
- %th Name
- %th Project Access
- %th Repository Access
- %th
+ %th Users
+ %th Project Access:
- - @admin_project.users_projects.each do |tm|
- %tr
- %td
- = link_to tm.user_name, admin_user_path(tm.user)
- %td= select_tag :tm_project_access, options_for_select(Project.access_options, tm.project_access), :class => "medium project-access-select", :disabled => :disabled
- %td= link_to 'Edit Access', edit_admin_team_member_path(tm), :class => "btn small"
- %td= link_to 'Remove from team', admin_team_member_path(tm), :confirm => 'Are you sure?', :method => :delete, :class => "btn danger small"
-
- = form_tag team_update_admin_project_path(@admin_project), :class => "bulk_import", :method => :put do
- %table
- %thead
- %tr
- %th Users
- %th Project Access:
- %th Repo Access:
-
- %tr
- %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), :multiple => true
- %td= select_tag :project_access, options_for_select(Project.access_options), :class => "project-access-select"
+ %tr
+ %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), :multiple => true
+ %td= select_tag :project_access, options_for_select(Project.access_options), :class => "project-access-select"
- .actions
- = submit_tag 'Add', :class => "btn primary"
+ %tr
+ %td= submit_tag 'Add', :class => "btn primary"
+ %td
+ Read more about project permissions
+ %strong= link_to "here", help_permissions_path, :class => "vlink"
:css
form select {
@@ -6,41 +6,55 @@
- @admin_user.errors.full_messages.each do |msg|
%li= msg
- .clearfix
- = f.label :name
- .input= f.text_field :name
- .clearfix
- = f.label :email
- .input= f.text_field :email
- .clearfix
- = f.label :password
- .input= f.password_field :password
- .clearfix
- = f.label :password_confirmation
- .input= f.password_field :password_confirmation
+ .row
+ .span6
+ .clearfix
+ = f.label :name
+ .input
+ = f.text_field :name
+ %span.help-inline * requried
+ .clearfix
+ = f.label :email
+ .input
+ = f.text_field :email
+ %span.help-inline * requried
+ .clearfix
+ = f.label :password
+ .input= f.password_field :password
+ .clearfix
+ = f.label :password_confirmation
+ .input= f.password_field :password_confirmation
+ %hr
+ .clearfix
+ = f.label :skype
+ .input= f.text_field :skype
+ .clearfix
+ = f.label :linkedin
+ .input= f.text_field :linkedin
+ .clearfix
+ = f.label :twitter
+ .input= f.text_field :twitter
+ .span6
+ .clearfix
+ = f.label :projects_limit
+ .input= f.text_field :projects_limit, :class => "small_input"
- .clearfix
- = f.label :projects_limit
- .input= f.text_field :projects_limit, :class => "small_input"
-
- .clearfix
- = f.label :skype
- .input= f.text_field :skype
- .clearfix
- = f.label :linkedin
- .input= f.text_field :linkedin
- .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
+ .alert
+ .clearfix
+ %p Give user ability to manage application.
+ = f.label :admin, :class => "checkbox" do
+ = f.check_box :admin
+ %span Administrator
+ - unless @admin_user.new_record?
+ .alert.alert-error
+ - if @admin_user.blocked
+ %span
+ = link_to 'Unblock', unblock_admin_user_path(@admin_user), :method => :put, :class => "btn small"
+ This user is blocked and is not able to login GitLab
+ - else
+ %span
+ = link_to 'Block', block_admin_user_path(@admin_user), :confirm => 'USER WILL BE BLOCKED! Are you sure?', :method => :put, :class => "btn small danger"
+ Blocked user will removed from all projects &amp; will not be able to login to GitLab.
.actions
= f.submit 'Save', :class => "btn primary"
- if @admin_user.new_record?
Oops, something went wrong.

0 comments on commit c9def94

Please sign in to comment.