Skip to content

Commit

Permalink
WEB-2264 fixed. Migration changes, mostly.
Browse files Browse the repository at this point in the history
  • Loading branch information
JRice committed May 25, 2011
1 parent 75ffeb8 commit 4f1c193
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/models/community.rb
Expand Up @@ -40,7 +40,14 @@ def self.create_special
special_roles.keys.each do |key|
role = Role.find(:first, :conditions => ['title = ? and community_id = ?', key, special.id])
role ||= Role.create(:community_id => special.id, :title => key)
role.privileges = Privilege.find(:all, :conditions => ["level <= ? and special = ?", special_roles[key], true])
# TODO - we really should change Language#english to Language#default and have it set in a config file.
# TODO - this is stupid, but migrations break because Language (the model) doesn't point to the right DB when
# this runs, so it is undefined after recreating the DB (in which case we hardly need it anyway):
begin
role.privileges = Privilege.find(:all, :conditions => ["level <= ? and special = ?", special_roles[key], true])
rescue ActiveRecord::StatementInvalid => e
# Do nothing; this should only happen when developers recreate the databases and thus it hardly matters now.
end
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/models/privilege.rb
Expand Up @@ -49,7 +49,14 @@ def self.create_all_for_type(hash, special = false)
hash.keys.each do |key|
priv = Privilege.create(:level => hash[key], :special => special)
# TODO - we really should change Language#english to Language#default and have it set in a config file.
TranslatedPrivilege.create(:name => key, :privilege_id => priv.id, :language_id => Language.english.id)
# TODO - this is stupid, but migrations break because Language (the model) doesn't point to the right DB when
# this runs, so it is undefined after recreating the DB (in which case we hardly need it anyway):
begin
TranslatedPrivilege.create(:name => key, :privilege_id => priv.id, :language_id => Language.english.id)
rescue ActiveRecord::StatementInvalid => e
priv.name = key
priv.save!
end
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/models/role.rb
Expand Up @@ -38,7 +38,14 @@ def self.add_defaults_to_community(community)
default_roles.keys.each do |key|
unless self.exists?(['title = ? and community_id = ?', key, community.id])
new_roles << self.create(:community_id => community.id, :title => key)
new_roles.last.privileges = Privilege.find(:all, :conditions => ["special != 1 and level <= ?", default_roles[key]])
# TODO - we really should change Language#english to Language#default and have it set in a config file.
# TODO - this is stupid, but migrations break because Language (the model) doesn't point to the right DB when
# this runs, so it is undefined after recreating the DB (in which case we hardly need it anyway):
begin
new_roles.last.privileges = Privilege.find(:all, :conditions => ["special != 1 and level <= ?", default_roles[key]])
rescue ActiveRecord::StatementInvalid => e
# Do nothing; this only happens when devs recreate databases and hardly matters, then.
end
new_roles.last.save!
end
end
Expand Down
@@ -1,7 +1,7 @@
class CreateStartingCommunityPrivileges < ActiveRecord::Migration

def self.up
Privilege.create_all
Privilege.create_defaults
end

def self.down
Expand Down

0 comments on commit 4f1c193

Please sign in to comment.