Fixed bug with roles seeding.
This commit is contained in:
parent
812711b144
commit
a833964952
|
@ -7,11 +7,23 @@ class Role < ActiveRecord::Base
|
||||||
|
|
||||||
validate :name, :presence => true
|
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_acter, lambda {|obj|
|
||||||
scope :exclude_target, lambda {|targ| {:conditions => (targ != :system and targ != '') ? ['"on" <> ?', targ.to_s] : '"on" NOT NULL OR "to" <> \'\''}}
|
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_acter, lambda {|obj|
|
||||||
scope :by_target, lambda {|targ| {:conditions => (targ != :system and targ != '') ? ['"on" = ?', targ.to_s] : '"on" ISNULL OR "on" = \'\''}}
|
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)
|
scope :default, where(:use_default => true)
|
||||||
|
|
||||||
|
@ -33,7 +45,6 @@ class Role < ActiveRecord::Base
|
||||||
def check_default
|
def check_default
|
||||||
if on_changed? and !on || on == ''
|
if on_changed? and !on || on == ''
|
||||||
roles = Role.by_acter(to).by_target('').default
|
roles = Role.by_acter(to).by_target('').default
|
||||||
puts roles.inspect
|
|
||||||
if roles and roles.size > 0
|
if roles and roles.size > 0
|
||||||
roles.each {|r| r.update_attributes(:use_default => false)}
|
roles.each {|r| r.update_attributes(:use_default => false)}
|
||||||
end
|
end
|
||||||
|
|
|
@ -171,9 +171,9 @@
|
||||||
rights: {}
|
rights: {}
|
||||||
|
|
||||||
id: 6
|
id: 6
|
||||||
to:
|
to: ''
|
||||||
can_see:
|
can_see:
|
||||||
"on":
|
"on": ''
|
||||||
- name: !binary |
|
- name: !binary |
|
||||||
0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA=
|
0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA=
|
||||||
|
|
||||||
|
|
|
@ -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
|
10
db/schema.rb
10
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "arches", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
|
@ -208,6 +208,7 @@ ActiveRecord::Schema.define(:version => 20111026200223) do
|
||||||
t.string "object_type"
|
t.string "object_type"
|
||||||
t.integer "target_id"
|
t.integer "target_id"
|
||||||
t.string "target_type"
|
t.string "target_type"
|
||||||
|
t.integer "role_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
@ -243,8 +244,8 @@ ActiveRecord::Schema.define(:version => 20111026200223) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.text "can_see"
|
t.text "can_see"
|
||||||
t.string "on"
|
t.string "on", :default => ""
|
||||||
t.string "to"
|
t.string "to", :default => ""
|
||||||
t.boolean "use_default", :default => false
|
t.boolean "use_default", :default => false
|
||||||
t.boolean "use_default_for_owner", :default => false
|
t.boolean "use_default_for_owner", :default => false
|
||||||
end
|
end
|
||||||
|
@ -270,8 +271,9 @@ ActiveRecord::Schema.define(:version => 20111026200223) do
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.text "ssh_key"
|
|
||||||
t.string "uname"
|
t.string "uname"
|
||||||
|
t.text "ssh_key"
|
||||||
|
t.integer "role_id"
|
||||||
t.integer "global_role_id"
|
t.integer "global_role_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue