Add backwards compatible accessors for ldap_cn and ldap_access

This commit is contained in:
Jan-Willem van der Meer
2014-08-15 15:40:32 +02:00
parent 3ba7a3a5ca
commit 15b248b220
3 changed files with 30 additions and 7 deletions
+17
View File
@@ -80,4 +80,21 @@ class Group < Namespace
def public_profile?
projects.public_only.any?
end
# NOTE: Backwards compatibility with old ldap situation
def ldap_cn
ldap_group_links.first.try(:cn)
end
def ldap_access
ldap_group_links.first.try(:group_access)
end
def old_ldap_cn
read_attribute(:ldap_cn)
end
def old_ldap_access
read_attribute(:ldap_access)
end
end
@@ -7,12 +7,6 @@ class AddLdapGroupsTable < ActiveRecord::Migration
t.timestamps
end
Group.where.not(ldap_cn: nil).each do |group|
group.ldap_groups.where(cn: group.ldap_cn).first_or_create do |ldap_group|
ldap_group.group_access = group.ldap_access
end
end
end
def down
@@ -1,5 +1,17 @@
class RenameLdapGroupToLdapGroupLink < ActiveRecord::Migration
def change
def up
rename_table :ldap_groups, :ldap_group_links
# NOTE: we use the old_ methods because the new methods are overloaded
# for backwards compatibility
Group.where.not(ldap_cn: nil).each do |group|
group.ldap_group_links.where(cn: group.old_ldap_cn).first_or_create do |ldap_group_link|
ldap_group_link.group_access = group.old_ldap_access
end
end
end
def down
rename_table :ldap_group_links, :ldap_groups
end
end