From 573349d0b61a1ff4ecbca7243167fe7a3d77e168 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Thu, 28 May 2015 12:07:18 +0300 Subject: [PATCH] Allow removing contacts one by one #2596 --- app/models/depp/domain.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/depp/domain.rb b/app/models/depp/domain.rb index 857f74fb2..4a13d5ba5 100644 --- a/app/models/depp/domain.rb +++ b/app/models/depp/domain.rb @@ -192,10 +192,10 @@ module Depp end def construct_edit_hash(domain_params, old_domain_params) - contacts = create_contacts_hash(domain_params) - create_contacts_hash(old_domain_params) + contacts = array_difference(create_contacts_hash(domain_params), create_contacts_hash(old_domain_params)) add_anon = contacts - contacts = create_contacts_hash(old_domain_params) - create_contacts_hash(domain_params) + contacts = array_difference(create_contacts_hash(old_domain_params), create_contacts_hash(domain_params)) rem_anon = contacts if domain_params[:registrant] != old_domain_params[:registrant] @@ -284,6 +284,15 @@ module Depp pubKey: { value: key_data_params['public_key'] } } end + + def array_difference(x, y) + ret = x.dup + y.each do |element| + index = ret.index(element) + ret.delete_at(index) if index + end + ret + end end end end