Skip to content

Commit

Permalink
给用户增加所属公司
Browse files Browse the repository at this point in the history
给权限增加所属公司
  • Loading branch information
karidyang committed Jul 16, 2014
1 parent 04afc6d commit 4b2b28a
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 147 deletions.
4 changes: 2 additions & 2 deletions app/controllers/roles_controller.rb
Expand Up @@ -18,7 +18,7 @@ def index
return
end

@roles = Role.order('name').paginate(:page => params[:page])
@roles = Role.where('company_id=?', @current_user.company_id).order('name').paginate(:page => params[:page])
render 'admin/roles/index'
end

Expand Down Expand Up @@ -53,7 +53,7 @@ def create
return
end
@role = Role.new(params[:role])

@role.company_id = @current_user.company_id
if @role.save
params[:role][:privilege_ids] ||= []
if @role.update_attributes(params[:role])
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/users_controller.rb
Expand Up @@ -11,9 +11,9 @@ def index
return
end
if params.has_key?('name')
@users = User.where('name like ?', "%#{params[:name]}%").paginate(:page => params[:page])
@users = User.where('name like ? and company_id=?', "%#{params[:name]}%", current_user.company_id).paginate(:page => params[:page])
else
@users = User.paginate(:page => params[:page])
@users = User.where('company_id=?', current_user.company_id).paginate(:page => params[:page])
end
render 'admin/users/index'
end
Expand Down Expand Up @@ -51,7 +51,7 @@ def create
return
end
@user = User.new(params[:user])

@user.company_id = @current_user.company_id
if @user.save
flash.now[:error] = '注册成功.'
redirect_back_or_default user_path
Expand All @@ -70,7 +70,6 @@ def update
end
@user = User.find(params[:id])


if @user.update_attributes(params[:user])
redirect_to(@user, :notice => '保存用户成功.')

Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20140716140020_add_company_to_user.rb
@@ -0,0 +1,8 @@
class AddCompanyToUser < ActiveRecord::Migration
def change
add_column :users, :company_id, :integer

add_index :users, :name
add_index :users, :company_id
end
end
7 changes: 7 additions & 0 deletions db/migrate/20140716140454_add_company_to_role.rb
@@ -0,0 +1,7 @@
class AddCompanyToRole < ActiveRecord::Migration
def change
add_column :roles, :company_id, :integer

add_index :roles, :company_id
end
end

0 comments on commit 4b2b28a

Please sign in to comment.