diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index c9e072395..599658936 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -3,7 +3,7 @@ class DomainMailer < ApplicationMailer @domain = domain return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email) - # turn on delivery on specific request only, thus rake tasks does not deliver anything + # turn on delivery on specific EPP request only, thus rake tasks does not deliver anything return if @domain.deliver_emails != true if @domain.registrant_verification_token.blank? @@ -25,11 +25,22 @@ class DomainMailer < ApplicationMailer subject: "#{I18n.t(:domain_registrant_pending_updated_subject, name: @domain.name)} [#{@domain.name}]") end + def registrant_updated(domain) + @domain = domain + return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email) + + # turn on delivery on specific EPP request only, thus rake tasks does not deliver anything + return if @domain.deliver_emails != true + + mail(to: @domain.registrant_email, + subject: "#{I18n.t(:domain_registrant_updated, name: @domain.name)} [#{@domain.name}]") + end + def pending_deleted(domain) @domain = domain return if Rails.env.production? ? false : !TEST_EMAILS.include?(@domain.registrant_email) - # turn on delivery on specific request only, thus rake tasks does not deliver anything + # turn on delivery on specific EPP request only, thus rake tasks does not deliver anything return if @domain.deliver_emails != true if @domain.registrant_verification_token.blank? diff --git a/app/models/domain.rb b/app/models/domain.rb index f21e00f4e..eca6a66af 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -186,13 +186,10 @@ class Domain < ActiveRecord::Base def start_expire_period STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test? - d = Domain.where('valid_to <= ?', Time.zone.now) - d.each do |x| - next unless x.expirable? - x.statuses << DomainStatus::EXPIRED - # TODO: This should be managed by automatic_statuses - x.statuses.delete(DomainStatus::OK) - x.save(validate: false) + domains = Domain.where('valid_to <= ?', Time.zone.now) + domains.each do |domain| + next unless domain.expirable? + domain.set_expired! end STDOUT << "#{Time.zone.now.utc} - Successfully expired #{d.count} domains\n" unless Rails.env.test? @@ -517,6 +514,19 @@ class Domain < ActiveRecord::Base save(validate: false) end + def set_expired + # TODO: currently valid_to attribute update logic is open + # self.valid_to = valid_from + self.class.convert_period_to_time(period, period_unit) + self.outzone_at = Time.zone.now + Setting.expire_warning_period.days + self.delete_at = Time.zone.now + Setting.redemption_grace_period.days + statuses << DomainStatus::EXPIRED + end + + def set_expired! + set_expired + save(validate: false) + end + def manage_automatic_statuses # domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable? if statuses.empty? && valid? diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index bb9ab55ce..505c30397 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -398,7 +398,11 @@ class Epp::Domain < Domain frame = Nokogiri::XML(pending_json['frame']) statuses.delete(DomainStatus::PENDING_UPDATE) - clean_pendings! if update(frame, user, false) + if update(frame, user, false) + clean_pendings! + self.deliver_emails = true # turn on email delivery for epp + DomainMailer.registrant_updated(self).deliver_now + end end def apply_pending_delete! @@ -429,7 +433,7 @@ class Epp::Domain < Domain manage_automatic_statuses true # aka 1001 pending_delete else - destroy + set_expired! end end diff --git a/app/views/domain_mailer/pending_deleted.html.erb b/app/views/domain_mailer/pending_deleted.html.erb index a6ba283e0..41f71dceb 100644 --- a/app/views/domain_mailer/pending_deleted.html.erb +++ b/app/views/domain_mailer/pending_deleted.html.erb @@ -4,7 +4,7 @@ Registrisse laekus taotlus domeeni <%= @domain.name %> kustutamiseks. Palun veen

Muudatuse kinnitamiseks külastage palun allolevat võrgulehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:

-Taotlus on aktiivne <48> tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.
+Taotlus on aktiivne 48 tundi ja lükatakse automaatselt tagasi kui te seda enne ise ei kinnita või tagasi lükka.
<%= link_to @verification_url, @verification_url %>

Lugupidamisega
diff --git a/app/views/domain_mailer/registrant_updated.html.erb b/app/views/domain_mailer/registrant_updated.html.erb new file mode 100644 index 000000000..eb8352b8e --- /dev/null +++ b/app/views/domain_mailer/registrant_updated.html.erb @@ -0,0 +1,39 @@ +Tere, +

+Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud. +

+Uued registreerija andmed:
+Nimi: <%= @domain.registrant_name %>
+<% if @domain.registrant.priv? %> +Isikukood: <%= @domain.registrant_ident %>
+<% else %> +Äriregistrikood: <%= @domain.registrant_ident %>
+<% end %> +Epost: <%= @domain.registrant_email %>
+Tänav: <%= @domain.registrant_street %>
+Linn: <%= @domain.registrant_city %>
+Riik: <%= @domain.registrant_country %> +

+Lugupidamisega
+Eesti Interneti SA +

+
+

+Hi, +

+Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated. +

+New registrant:
+Name: <%= @domain.registrant_name %>
+<% if @domain.registrant.priv? %> +Personal code: <%= @domain.registrant_ident %>
+<% else %> +Business Registry code: <%= @domain.registrant_ident %>
+<% end %> +E-mail: <%= @domain.registrant_email %>
+Street: <%= @domain.registrant_street %>
+City: <%= @domain.registrant_city %>
+Country: <%= @domain.registrant_country %> +

+Best Regards,
+Estonian Internet Foundation diff --git a/app/views/domain_mailer/registrant_updated.text.erb b/app/views/domain_mailer/registrant_updated.text.erb new file mode 100644 index 000000000..503c111f6 --- /dev/null +++ b/app/views/domain_mailer/registrant_updated.text.erb @@ -0,0 +1,39 @@ +Tere, + +Domeeni <%= @domain.name %> registreerija vahetuse taotlus on kinnitatud ning andmed registris uuendatud. + +Uued registreerija andmed: +Nimi: <%= @domain.registrant_name %> +<% if @domain.registrant.priv? %> +Isikukood: <%= @domain.registrant_ident %> +<% else %> +Äriregistrikood: <%= @domain.registrant_ident %> +<% end %> +Epost: <%= @domain.registrant_email %> +Tänav: <%= @domain.registrant_street %> +Linn: <%= @domain.registrant_city %> +Riik: <%= @domain.registrant_country %> + +Lugupidamisega +Eesti Interneti SA + +-------------------------------------- + +Hi, + +Process for changing registrant of the domain <%= @domain.name %> has been approved and the data in the registry is updated. + +New registrant: +Name: <%= @domain.registrant_name %> +<% if @domain.registrant.priv? %> +Personal code: <%= @domain.registrant_ident %> +<% else %> +Business Registry code: <%= @domain.registrant_ident %> +<% end %> +E-mail: <%= @domain.registrant_email %> +Street: <%= @domain.registrant_street %> +City: <%= @domain.registrant_city %> +Country: <%= @domain.registrant_country %> + +Best Regards, +Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index 23f97b5e2..0b71bf267 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -869,3 +869,4 @@ en: reserved_pw: 'Reserved pw' no_transfers_found: 'No transfers found' parameter_value_range_error: 'Parameter value range error: %{key}' + domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' diff --git a/db/schema-read-only.rb b/db/schema-read-only.rb index d835c73c7..7880fe213 100644 --- a/db/schema-read-only.rb +++ b/db/schema-read-only.rb @@ -199,6 +199,7 @@ ActiveRecord::Schema.define(version: 20150713113436) do t.string "country_code" t.string "state" t.integer "legacy_id" + t.string "statuses", array: true end add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree @@ -1029,7 +1030,7 @@ ActiveRecord::Schema.define(version: 20150713113436) do t.text "crt" t.string "type" t.string "registrant_ident" - t.string "encrypted_password", default: "", null: false + t.string "encrypted_password", default: "" t.datetime "remember_created_at" t.integer "failed_attempts", default: 0, null: false t.datetime "locked_at" diff --git a/db/structure.sql b/db/structure.sql index dd524fc00..f8e53da5d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -631,7 +631,8 @@ CREATE TABLE contacts ( zip character varying, country_code character varying, state character varying, - legacy_id integer + legacy_id integer, + statuses character varying[] ); @@ -2383,7 +2384,7 @@ CREATE TABLE pricelists ( id integer NOT NULL, "desc" character varying, category character varying, - price_cents numeric(10,2) DEFAULT 0.0 NOT NULL, + price_cents numeric(10,2) DEFAULT 0 NOT NULL, price_currency character varying DEFAULT 'EUR'::character varying NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, @@ -2647,7 +2648,7 @@ CREATE TABLE users ( crt text, type character varying, registrant_ident character varying, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying, remember_created_at timestamp without time zone, failed_attempts integer DEFAULT 0 NOT NULL, locked_at timestamp without time zone @@ -4740,6 +4741,8 @@ INSERT INTO schema_migrations (version) VALUES ('20150227092508'); INSERT INTO schema_migrations (version) VALUES ('20150227113121'); +INSERT INTO schema_migrations (version) VALUES ('20150302130224'); + INSERT INTO schema_migrations (version) VALUES ('20150302161712'); INSERT INTO schema_migrations (version) VALUES ('20150303130729'); @@ -4798,6 +4801,8 @@ INSERT INTO schema_migrations (version) VALUES ('20150417082723'); INSERT INTO schema_migrations (version) VALUES ('20150421134820'); +INSERT INTO schema_migrations (version) VALUES ('20150422090645'); + INSERT INTO schema_migrations (version) VALUES ('20150422092514'); INSERT INTO schema_migrations (version) VALUES ('20150422132631'); @@ -4842,6 +4847,8 @@ INSERT INTO schema_migrations (version) VALUES ('20150519115050'); INSERT INTO schema_migrations (version) VALUES ('20150519140853'); +INSERT INTO schema_migrations (version) VALUES ('20150519142542'); + INSERT INTO schema_migrations (version) VALUES ('20150519144118'); INSERT INTO schema_migrations (version) VALUES ('20150520163237'); @@ -4858,6 +4865,8 @@ INSERT INTO schema_migrations (version) VALUES ('20150601083516'); INSERT INTO schema_migrations (version) VALUES ('20150601083800'); +INSERT INTO schema_migrations (version) VALUES ('20150603141054'); + INSERT INTO schema_migrations (version) VALUES ('20150603141549'); INSERT INTO schema_migrations (version) VALUES ('20150603211318'); @@ -4882,12 +4891,14 @@ INSERT INTO schema_migrations (version) VALUES ('20150612125720'); INSERT INTO schema_migrations (version) VALUES ('20150701074344'); -INSERT INTO schema_migrations (version) VALUES ('20150703084206'); - INSERT INTO schema_migrations (version) VALUES ('20150703084632'); INSERT INTO schema_migrations (version) VALUES ('20150706091724'); +INSERT INTO schema_migrations (version) VALUES ('20150707103241'); + +INSERT INTO schema_migrations (version) VALUES ('20150707103801'); + INSERT INTO schema_migrations (version) VALUES ('20150707104937'); INSERT INTO schema_migrations (version) VALUES ('20150707154543'); diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 8734153ee..ada60a741 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -112,4 +112,29 @@ describe DomainMailer do @mail.body.encoded.should =~ %r{registrant\/domain_delete_con} # somehowe delete_confirms not matching end end + + describe 'registrant successfully changed confirmation' do + before :all do + @registrant = Fabricate(:registrant, email: 'test@example.com') + @domain = Fabricate(:domain, registrant: @registrant) + @domain.deliver_emails = true + @mail = DomainMailer.registrant_updated(@domain) + end + + it 'should render email subject' do + @mail.subject.should =~ /registreerija vahetus teostatud/ + end + + it 'should have sender email' do + @mail.from.should == ["noreply@internet.ee"] + end + + it 'should send to registrant email' do + @mail.to.should == ["test@example.com"] + end + + it 'should render body' do + @mail.body.encoded.should =~ /registreerija vahetuse taotlus on kinnitatud/ + end + end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 30531bff0..161eae0e5 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -182,6 +182,16 @@ describe Domain do @domain.force_delete_at.should be_nil end + it 'should set expired status and update outzone_at and delete_at' do + domain = Fabricate(:domain) + domain.statuses.should == ['ok'] + domain.set_expired + domain.changes.keys.should == ['statuses', 'outzone_at', 'delete_at'] + domain.save + + domain.statuses.should == ['expired'] + end + it 'should know its create price' do Fabricate(:pricelist, { category: 'ee',