From 15b248b2202fcf08154ba313acfdb07d614434f4 Mon Sep 17 00:00:00 2001 From: Jan-Willem van der Meer Date: Fri, 15 Aug 2014 15:40:32 +0200 Subject: [PATCH] Add backwards compatible accessors for ldap_cn and ldap_access --- app/models/group.rb | 17 +++++++++++++++++ .../20140813090117_add_ldap_groups_table.rb | 6 ------ ...3925_rename_ldap_group_to_ldap_group_link.rb | 14 +++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 5e891156b3..564474d63a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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 diff --git a/db/migrate/20140813090117_add_ldap_groups_table.rb b/db/migrate/20140813090117_add_ldap_groups_table.rb index 8554824d3b..2cd7d23908 100644 --- a/db/migrate/20140813090117_add_ldap_groups_table.rb +++ b/db/migrate/20140813090117_add_ldap_groups_table.rb @@ -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 diff --git a/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb b/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb index 6b95a8fbb0..127b2d8063 100644 --- a/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb +++ b/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb @@ -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