Fixed bug with roles seeding.

This commit is contained in:
George Vinogradov 2011-10-28 03:35:00 +04:00
parent 812711b144
commit a833964952
4 changed files with 33 additions and 11 deletions

View File

@ -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

View File

@ -171,9 +171,9 @@
rights: {}
id: 6
to:
to: ''
can_see:
"on":
"on": ''
- name: !binary |
0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA=

View File

@ -0,0 +1,9 @@
class ChangeRolesOnAndTo < ActiveRecord::Migration
def self.up
change_column :roles, :on, :string, :default => ''
change_column :roles, :to, :string, :default => ''
end
def self.down
end
end

View File

@ -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