From 9a1ce7b89cfb50a9214a96aa66805538b471636d Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 28 Oct 2011 03:35:00 +0400 Subject: [PATCH] Fixed bug with roles seeding. --- app/models/role.rb | 21 ++++++++++++++++----- config/roles.yml | 4 ++-- db/schema.rb | 10 ++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/models/role.rb b/app/models/role.rb index c3f9ac8e2..9e143f34c 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -7,11 +7,23 @@ class Role < ActiveRecord::Base validate :name, :presence => true - scope :exclude_acter, lambda {|obj| {:conditions => (obj != :all and obj != '') ? ['"to" <> ?', obj.to_s] : '"to" NOT NULL OR "to" <> \'\''}} - scope :exclude_target, lambda {|targ| {:conditions => (targ != :system and targ != '') ? ['"on" <> ?', targ.to_s] : '"on" NOT NULL OR "to" <> \'\''}} + scope :exclude_acter, lambda {|obj| + t = self.arel_table + where(t[:to].not_eq((obj != :all) ? obj.to_s : '')) + } + scope :exclude_target, lambda {|targ| + t = self.arel_table + where(t[:on].not_eq((targ != :system) ? targ.to_s : '')) + } - scope :by_acter, lambda {|obj| {:conditions => (obj != :all and obj != '') ? ['"to" = ?', obj.to_s] : '"to" ISNULL OR "to" = \'\''}} - scope :by_target, lambda {|targ| {:conditions => (targ != :system and targ != '') ? ['"on" = ?', targ.to_s] : '"on" ISNULL OR "on" = \'\''}} + scope :by_acter, lambda {|obj| + t = self.arel_table + where(t[:to].eq((obj != :all) ? obj.to_s : '')) + } + scope :by_target, lambda {|targ| + t = self.arel_table + where(t[:on].eq((targ != :system) ? targ.to_s : '')) + } scope :default, where(:use_default => true) @@ -33,7 +45,6 @@ class Role < ActiveRecord::Base def check_default if on_changed? and !on || on == '' roles = Role.by_acter(to).by_target('').default - puts roles.inspect if roles and roles.size > 0 roles.each {|r| r.update_attributes(:use_default => false)} end diff --git a/config/roles.yml b/config/roles.yml index cef577c0a..f303ee478 100644 --- a/config/roles.yml +++ b/config/roles.yml @@ -171,9 +171,9 @@ rights: {} id: 6 - to: + to: '' can_see: - "on": + "on": '' - name: !binary | 0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA= diff --git a/db/schema.rb b/db/schema.rb index c974e48e9..520386245 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111026200223) do +ActiveRecord::Schema.define(:version => 20111027230610) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -208,6 +208,7 @@ ActiveRecord::Schema.define(:version => 20111026200223) do t.string "object_type" t.integer "target_id" t.string "target_type" + t.integer "role_id" t.datetime "created_at" t.datetime "updated_at" end @@ -243,8 +244,8 @@ ActiveRecord::Schema.define(:version => 20111026200223) do t.datetime "created_at" t.datetime "updated_at" t.text "can_see" - t.string "on" - t.string "to" + t.string "on", :default => "" + t.string "to", :default => "" t.boolean "use_default", :default => false t.boolean "use_default_for_owner", :default => false end @@ -270,8 +271,9 @@ ActiveRecord::Schema.define(:version => 20111026200223) do t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" - t.text "ssh_key" t.string "uname" + t.text "ssh_key" + t.integer "role_id" t.integer "global_role_id" end