diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index b46b788..de86adb 100755 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -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 @@ -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]) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 792c6a2..9fa2b93 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 @@ -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 @@ -70,7 +70,6 @@ def update end @user = User.find(params[:id]) - if @user.update_attributes(params[:user]) redirect_to(@user, :notice => '保存用户成功.') diff --git a/db/migrate/20140716140020_add_company_to_user.rb b/db/migrate/20140716140020_add_company_to_user.rb new file mode 100644 index 0000000..e460c4c --- /dev/null +++ b/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 diff --git a/db/migrate/20140716140454_add_company_to_role.rb b/db/migrate/20140716140454_add_company_to_role.rb new file mode 100644 index 0000000..7a97a7e --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index b147a6b..ff6ff5a 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,123 +11,123 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131020115903) do +ActiveRecord::Schema.define(:version => 20140716140454) do create_table "account_details", :force => true do |t| - t.integer "account_id" - t.integer "account_type" - t.decimal "money", :precision => 8, :scale => 2 - t.date "trans_time" - t.string "note" - t.string "updateby" - t.integer "record" - t.decimal "unit_price", :precision => 8, :scale => 2 - t.decimal "can_push", :precision => 8, :scale => 2, :default => 0.0 - t.integer "receipt_id" + t.integer "account_id" + t.integer "account_type" + t.decimal "money", :precision => 8, :scale => 2 + t.date "trans_time" + t.string "note" + t.string "updateby" + t.integer "record" + t.decimal "unit_price", :precision => 8, :scale => 2 + t.decimal "can_push", :precision => 8, :scale => 2, :default => 0.0 + t.integer "receipt_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "house_id" - t.integer "plot_id" - t.string "receipt_no" - t.integer "item_id" - t.string "item_name" - t.decimal "discount", :precision => 8, :scale => 2, :default => 1.0 - t.decimal "discount_money", :precision => 8, :scale => 2, :default => 0.0 + t.integer "house_id" + t.integer "plot_id" + t.string "receipt_no" + t.integer "item_id" + t.string "item_name" + t.decimal "discount", :precision => 8, :scale => 2, :default => 1.0 + t.decimal "discount_money", :precision => 8, :scale => 2, :default => 0.0 end add_index "account_details", ["account_id"], :name => "index_account_details_on_account_id" create_table "accounts", :force => true do |t| - t.integer "house_id" - t.string "house_code" - t.decimal "money", :precision => 8, :scale => 2 - t.integer "item_id" - t.integer "item_type" - t.string "item_name" - t.integer "plot_id" + t.integer "house_id" + t.string "house_code" + t.decimal "money", :precision => 8, :scale => 2 + t.integer "item_id" + t.integer "item_type" + t.string "item_name" + t.integer "plot_id" t.datetime "created_at" t.datetime "updated_at" end create_table "areas", :force => true do |t| - t.string "name" + t.string "name" t.integer "house_num" t.integer "plot_id" end create_table "bill_items", :force => true do |t| - t.integer "bill_id" - t.integer "item_id" - t.string "item_name" - t.decimal "money", :precision => 8, :scale => 2 - t.date "trans_time" - t.integer "status" - t.decimal "pay_money", :precision => 8, :scale => 2 - t.date "pay_date" - t.integer "house_id" - t.decimal "unit_price", :precision => 8, :scale => 2 - t.integer "record" - t.integer "start_record" - t.integer "end_record" - t.decimal "push", :precision => 8, :scale => 2 - t.string "operator" + t.integer "bill_id" + t.integer "item_id" + t.string "item_name" + t.decimal "money", :precision => 8, :scale => 2 + t.date "trans_time" + t.integer "status" + t.decimal "pay_money", :precision => 8, :scale => 2 + t.date "pay_date" + t.integer "house_id" + t.decimal "unit_price", :precision => 8, :scale => 2 + t.decimal "record", :precision => 8, :scale => 2 + t.integer "start_record" + t.integer "end_record" + t.decimal "push", :precision => 8, :scale => 2 + t.string "operator" t.datetime "created_at" t.datetime "updated_at" - t.integer "item_type" - t.integer "plot_id" - t.integer "receipt_id" - t.string "receipt_no" - t.string "note" + t.integer "item_type" + t.integer "plot_id" + t.integer "receipt_id" + t.string "receipt_no" + t.string "note" end create_table "bills", :force => true do |t| - t.string "bill_name" - t.date "bill_date" - t.integer "bill_status" - t.decimal "curr_money", :precision => 8, :scale => 2 - t.integer "house_id" - t.integer "plot_id" + t.string "bill_name" + t.date "bill_date" + t.integer "bill_status" + t.decimal "curr_money", :precision => 8, :scale => 2 + t.integer "house_id" + t.integer "plot_id" t.datetime "created_at" t.datetime "updated_at" end create_table "car_ports", :force => true do |t| - t.string "port_no" - t.integer "port_charge_id" - t.integer "plot_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "port_no" + t.integer "port_charge_id" + t.integer "plot_id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "cars", :force => true do |t| - t.string "car_no" - t.integer "house_id" - t.integer "car_port_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "car_no" + t.integer "house_id" + t.integer "car_port_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "charges", :force => true do |t| - t.string "item_name" - t.integer "period_type" - t.decimal "price", :precision => 8, :scale => 2 - t.integer "unit_type" - t.integer "item_num" - t.integer "period" - t.integer "fee_rate", :default => 0 - t.integer "return_back" - t.string "note" - t.integer "plot_id", :null => false + t.string "item_name" + t.integer "period_type" + t.decimal "price", :precision => 8, :scale => 2 + t.integer "unit_type" + t.integer "item_num" + t.integer "period" + t.integer "fee_rate", :default => 0 + t.integer "return_back" + t.string "note" + t.integer "plot_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.boolean "bind_area", :default => false + t.boolean "bind_area", :default => false end add_index "charges", ["plot_id"], :name => "index_charges_on_plot_id" create_table "charges_houses", :id => false, :force => true do |t| t.integer "charge_id", :null => false - t.integer "house_id", :null => false + t.integer "house_id", :null => false end create_table "companies", :force => true do |t| @@ -138,52 +138,53 @@ end create_table "houses", :force => true do |t| - t.string "house_code" - t.integer "area_id", :null => false - t.decimal "builded_area", :precision => 8, :scale => 2 - t.decimal "real_area", :precision => 8, :scale => 2 - t.decimal "share_area", :precision => 8, :scale => 2 - t.integer "status" - t.integer "use_type" - t.integer "unit_id" - t.integer "plot_id", :null => false + t.string "house_code" + t.integer "area_id", :null => false + t.decimal "builded_area", :precision => 8, :scale => 2 + t.decimal "real_area", :precision => 8, :scale => 2 + t.decimal "share_area", :precision => 8, :scale => 2 + t.integer "status" + t.integer "use_type" + t.integer "unit_id" + t.integer "plot_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "owner_name" - t.date "receive_time" - t.date "checkin_time" + t.string "owner_name" + t.date "receive_time" + t.date "checkin_time" end add_index "houses", ["area_id"], :name => "index_houses_on_area_id" add_index "houses", ["plot_id"], :name => "index_houses_on_plot_id" create_table "notices", :force => true do |t| - t.string "topic" - t.string "content" - t.integer "publish_type" - t.date "expire_date" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "topic" + t.text "content" + t.integer "publish_type" + t.date "expire_date" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "notices_users", :force => true do |t| - t.integer "notice_id", :null => false - t.integer "user_id", :null => false - t.boolean "is_read", :default => false + t.integer "notice_id", :null => false + t.integer "user_id", :null => false + t.boolean "is_read", :default => false end add_index "notices_users", ["notice_id", "user_id"], :name => "index_notices_users_on_notice_id_and_user_id", :unique => true create_table "owners", :force => true do |t| - t.string "name" - t.integer "age" - t.boolean "sex", :default => false - t.string "phone" - t.string "id_card" - t.string "contract_no" - t.integer "house_id", :null => false + t.string "name" + t.integer "age" + t.boolean "sex", :default => false + t.string "phone" + t.string "id_card" + t.string "contract_no" + t.integer "house_id", :null => false t.datetime "created_at" t.datetime "updated_at" + t.integer "plot_id" end add_index "owners", ["house_id"], :name => "index_owners_on_house_id" @@ -191,17 +192,17 @@ create_table "pay_reports", :force => true do |t| t.integer "plot_id" t.integer "item_id" - t.string "item_name" - t.decimal "money", :precision => 8, :scale => 2 - t.date "trans_time" + t.string "item_name" + t.decimal "money", :precision => 8, :scale => 2 + t.date "trans_time" end create_table "plots", :force => true do |t| - t.string "name" - t.string "developer" - t.string "constructor" - t.string "address" - t.string "phone" + t.string "name" + t.string "developer" + t.string "constructor" + t.string "address" + t.string "phone" t.integer "company_id" end @@ -217,27 +218,30 @@ end create_table "privileges_roles", :id => false, :force => true do |t| - t.integer "role_id", :null => false + t.integer "role_id", :null => false t.integer "privilege_id", :null => false end create_table "receipts", :force => true do |t| - t.string "receipt_no" - t.integer "house_id" - t.string "house_code" - t.integer "plot_id" - t.date "print_date" - t.string "print_user" + t.string "receipt_no" + t.integer "house_id" + t.string "house_code" + t.integer "plot_id" + t.date "print_date" + t.string "print_user" t.datetime "created_at" t.datetime "updated_at" end create_table "roles", :force => true do |t| - t.string "name" + t.string "name" t.datetime "created_at" t.datetime "updated_at" + t.integer "company_id" end + add_index "roles", ["company_id"], :name => "index_roles_on_company_id" + create_table "roles_users", :id => false, :force => true do |t| t.integer "user_id", :null => false t.integer "role_id", :null => false @@ -246,40 +250,44 @@ create_table "unpay_reports", :force => true do |t| t.integer "plot_id" t.integer "item_id" - t.string "item_name" - t.decimal "money", :precision => 8, :scale => 2 - t.date "trans_time" + t.string "item_name" + t.decimal "money", :precision => 8, :scale => 2 + t.date "trans_time" end create_table "user_reports", :force => true do |t| - t.date "trans_time" + t.date "trans_time" t.integer "item_id" - t.string "item_name" + t.string "item_name" t.integer "house_id" - t.string "house_code" - t.string "owner" - t.decimal "pay_money", :precision => 8, :scale => 2, :default => 0.0 + t.string "house_code" + t.string "owner" + t.decimal "pay_money", :precision => 8, :scale => 2, :default => 0.0 t.decimal "unpay_money", :precision => 8, :scale => 2, :default => 0.0 - t.decimal "pre_money", :precision => 8, :scale => 2, :default => 0.0 - t.string "operator" + t.decimal "pre_money", :precision => 8, :scale => 2, :default => 0.0 + t.string "operator" + t.integer "plot_id" end create_table "users", :force => true do |t| - t.string "email", :null => false - t.string "name", :null => false - t.integer "state", :default => 1, :null => false - t.string "crypted_password", :null => false - t.string "password_salt", :null => false - t.string "persistence_token", :null => false - t.string "single_access_token", :null => false - t.string "perishable_token", :null => false - t.integer "login_count", :default => 0, :null => false - t.integer "failed_login_count", :default => 0, :null => false + t.string "email", :null => false + t.string "name", :null => false + t.integer "state", :default => 1, :null => false + t.string "crypted_password", :null => false + t.string "password_salt", :null => false + t.string "persistence_token", :null => false + t.string "single_access_token", :null => false + t.string "perishable_token", :null => false + t.integer "login_count", :default => 0, :null => false + t.integer "failed_login_count", :default => 0, :null => false t.datetime "last_login_at" - t.string "current_login_ip" - t.string "last_login_ip" + t.string "current_login_ip" + t.string "last_login_ip" + t.integer "company_id" end + add_index "users", ["company_id"], :name => "index_users_on_company_id" add_index "users", ["email"], :name => "index_users_on_email" + add_index "users", ["name"], :name => "index_users_on_name" end