From 68b6989af0efa78d6ebdbe41dd2aa8d8660cb999 Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Fri, 20 Jul 2018 11:16:48 +0300 Subject: [PATCH 01/10] =?UTF-8?q?butonlar=C4=B1=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/account/addresses/index.html.erb | 1 + app/views/account/identities/index.html.erb | 1 + config/locales/models/addresses/en.yml | 1 + config/locales/models/addresses/tr.yml | 1 + config/locales/models/identities/en.yml | 1 + config/locales/models/identities/tr.yml | 1 + 6 files changed, 6 insertions(+) diff --git a/app/views/account/addresses/index.html.erb b/app/views/account/addresses/index.html.erb index 87b7cc158..8be4adc77 100644 --- a/app/views/account/addresses/index.html.erb +++ b/app/views/account/addresses/index.html.erb @@ -1,5 +1,6 @@
<%= link_to_new(new_address_path, t('.new_address')) %> + <%= link_to_new(new_address_path, t('.get_from_mernis')) unless @addresses.present? %>
diff --git a/app/views/account/identities/index.html.erb b/app/views/account/identities/index.html.erb index b23df90fb..7f6c7b7bb 100644 --- a/app/views/account/identities/index.html.erb +++ b/app/views/account/identities/index.html.erb @@ -1,5 +1,6 @@
<%= link_to_new(new_identity_path, t('.new_identity')) %> + <%= link_to_new(new_address_path, t('.get_from_mernis')) unless @identities.present? %>
diff --git a/config/locales/models/addresses/en.yml b/config/locales/models/addresses/en.yml index 0595fccce..a5e4a667e 100644 --- a/config/locales/models/addresses/en.yml +++ b/config/locales/models/addresses/en.yml @@ -34,6 +34,7 @@ en: card_header: Address Information district_and_city: District / City update_from_mernis: Update from MERNİS + get_from_mernis: Get from MERNIS new: form_title: Create Address edit: diff --git a/config/locales/models/addresses/tr.yml b/config/locales/models/addresses/tr.yml index 27120d3d3..6cf09fc86 100644 --- a/config/locales/models/addresses/tr.yml +++ b/config/locales/models/addresses/tr.yml @@ -34,6 +34,7 @@ tr: card_header: Adres Bilgileri district_and_city: İlçe / İl update_from_mernis: MERNİS'ten Güncelle + get_from_mernis: MERNİS'ten Getir new: form_title: Adres Oluştur edit: diff --git a/config/locales/models/identities/en.yml b/config/locales/models/identities/en.yml index ce363ef46..d8e146444 100644 --- a/config/locales/models/identities/en.yml +++ b/config/locales/models/identities/en.yml @@ -42,6 +42,7 @@ en: new_identity: Add a New Identity card_header: Identity Information update_from_mernis: Update from MERNIS + get_from_mernis: Get from MERNIS edit: warning: You can not edit your formal identity! form_title: Edit Identity diff --git a/config/locales/models/identities/tr.yml b/config/locales/models/identities/tr.yml index 91fa95823..eaea30b6e 100644 --- a/config/locales/models/identities/tr.yml +++ b/config/locales/models/identities/tr.yml @@ -42,6 +42,7 @@ tr: new_identity: Yeni Kimlik Ekle card_header: Kimlik Bilgileri update_from_mernis: MERNİS'ten Güncelle + get_from_mernis: MERNİS'ten Getir edit: warning: Yasal kimlik bilgilerinizi düzenleyemezsiniz! form_title: Kimliği Düzenle From 479cf1464d74752bca7dc61495e57e18bc84b0f7 Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Tue, 24 Jul 2018 17:50:41 +0300 Subject: [PATCH 02/10] Add: Import from MERNIS --- app/controllers/account/addresses_controller.rb | 9 +++++++++ app/controllers/account/identities_controller.rb | 9 +++++++++ app/views/account/addresses/index.html.erb | 2 +- app/views/account/identities/index.html.erb | 2 +- config/locales/models/addresses/en.yml | 5 ++++- config/locales/models/addresses/tr.yml | 5 ++++- config/locales/models/identities/en.yml | 5 ++++- config/locales/models/identities/tr.yml | 5 ++++- config/routes.rb | 6 ++++++ 9 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 72681dacd..28c90e218 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -37,6 +37,15 @@ def mernis end end + def import_from_mernis + if current_user.addresses.formal.blank? + KpsAddressCreateJob.perform_later(current_user) + redirect_with('will_update') + else + redirect_with('wait') + end + end + private def check_formality diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index b958bc235..6c46c0fdc 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -37,6 +37,15 @@ def mernis end end + def import_from_mernis + if current_user.identities.formal.blank? + KpsIdentitySaveJob.perform_later(current_user) + redirect_with('will_update') + else + redirect_with('wait') + end + end + private def check_formality diff --git a/app/views/account/addresses/index.html.erb b/app/views/account/addresses/index.html.erb index 8be4adc77..540631326 100644 --- a/app/views/account/addresses/index.html.erb +++ b/app/views/account/addresses/index.html.erb @@ -1,6 +1,6 @@
<%= link_to_new(new_address_path, t('.new_address')) %> - <%= link_to_new(new_address_path, t('.get_from_mernis')) unless @addresses.present? %> + <%= link_to_new(import_from_mernis_addresses_path, t('.import_from_mernis')) unless @addresses.present? %>
diff --git a/app/views/account/identities/index.html.erb b/app/views/account/identities/index.html.erb index 7f6c7b7bb..b5ea95032 100644 --- a/app/views/account/identities/index.html.erb +++ b/app/views/account/identities/index.html.erb @@ -1,6 +1,6 @@
<%= link_to_new(new_identity_path, t('.new_identity')) %> - <%= link_to_new(new_address_path, t('.get_from_mernis')) unless @identities.present? %> + <%= link_to_new(import_from_mernis_identities_path, t('.import_from_mernis')) unless @identities.present? %>
diff --git a/config/locales/models/addresses/en.yml b/config/locales/models/addresses/en.yml index a5e4a667e..30044d044 100644 --- a/config/locales/models/addresses/en.yml +++ b/config/locales/models/addresses/en.yml @@ -34,7 +34,7 @@ en: card_header: Address Information district_and_city: District / City update_from_mernis: Update from MERNİS - get_from_mernis: Get from MERNIS + import_from_mernis: Import from MERNIS new: form_title: Create Address edit: @@ -50,3 +50,6 @@ en: mernis: wait: You recently created or updated your address. You can update your address once every week. will_update: We got your address update request. In a couple of seconds/minutes you will be able to see your new address. + import_from_mernis: + wait: We got your address update request. In a couple of seconds/minutes you will be able to see your new address. + will_update: Your address information has been transferred to the system via MERNIS. diff --git a/config/locales/models/addresses/tr.yml b/config/locales/models/addresses/tr.yml index 6cf09fc86..fd1baacf4 100644 --- a/config/locales/models/addresses/tr.yml +++ b/config/locales/models/addresses/tr.yml @@ -34,7 +34,7 @@ tr: card_header: Adres Bilgileri district_and_city: İlçe / İl update_from_mernis: MERNİS'ten Güncelle - get_from_mernis: MERNİS'ten Getir + import_from_mernis: MERNİS'ten Getir new: form_title: Adres Oluştur edit: @@ -50,3 +50,6 @@ tr: mernis: wait: Adresinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Adresinizi haftada bir güncelleyebilirsiniz. will_update: Adres güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. + import_from_mernis: + wait: Adresinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Adresinizi haftada bir güncelleyebilirsiniz. + will_update: Adres bilginiz MERNİS üzerinden sisteme aktarım işlemi başlatılmıştır. diff --git a/config/locales/models/identities/en.yml b/config/locales/models/identities/en.yml index d8e146444..6f652ebcf 100644 --- a/config/locales/models/identities/en.yml +++ b/config/locales/models/identities/en.yml @@ -42,7 +42,7 @@ en: new_identity: Add a New Identity card_header: Identity Information update_from_mernis: Update from MERNIS - get_from_mernis: Get from MERNIS + import_from_mernis: Import from MERNIS edit: warning: You can not edit your formal identity! form_title: Edit Identity @@ -58,3 +58,6 @@ en: mernis: wait: You recently created or updated your identity. You can only update your identity once a week from MERNIS. will_update: We have received your identity update request. Your identity will be updated in a couple of seconds/minutes. + import_from_mernis: + wait: We have received your identity update request. Your identity will be updated in a couple of seconds/minutes. + will_update: Your identity information has been transferred to the system via MERNIS. diff --git a/config/locales/models/identities/tr.yml b/config/locales/models/identities/tr.yml index eaea30b6e..c576c3bfe 100644 --- a/config/locales/models/identities/tr.yml +++ b/config/locales/models/identities/tr.yml @@ -42,7 +42,7 @@ tr: new_identity: Yeni Kimlik Ekle card_header: Kimlik Bilgileri update_from_mernis: MERNİS'ten Güncelle - get_from_mernis: MERNİS'ten Getir + import_from_mernis: MERNİS'ten Getir edit: warning: Yasal kimlik bilgilerinizi düzenleyemezsiniz! form_title: Kimliği Düzenle @@ -58,3 +58,6 @@ tr: mernis: wait: Kimliğinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Kimliğinizi haftada bir güncelleyebilirsiniz. will_update: Kimlik güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. + import_from_mernis: + wait: Kimliğinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Kimliğinizi haftada bir güncelleyebilirsiniz. + will_update: Kimlik bilginiz MERNİS üzerinden sisteme aktarım işlemi başlatılmıştır. diff --git a/config/routes.rb b/config/routes.rb index f18707308..d683e05ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,9 +21,15 @@ scope module: :account do resources :identities, except: [:show] do get 'mernis', on: :member + collection do + get 'import_from_mernis' + end end resources :addresses, except: :show do get 'mernis', on: :member + collection do + get 'import_from_mernis' + end end end From 5cfc86df0fc4cda65bc9e591272ce84fb35ed4bf Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Thu, 26 Jul 2018 15:06:17 +0300 Subject: [PATCH 03/10] Merge KpsAddressCreateJob and KpsAddressUpdateJob jobs with name KpsAddressSaveJob --- .../account/addresses_controller.rb | 4 +- app/jobs/kps_address_create_job.rb | 16 ------ app/jobs/kps_address_save_job.rb | 21 ++++++++ app/jobs/kps_address_update_job.rb | 16 ------ app/models/user.rb | 2 +- test/jobs/kps_address_job_test.rb | 51 +++++++------------ test/models/user_test.rb | 4 +- 7 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 app/jobs/kps_address_create_job.rb create mode 100644 app/jobs/kps_address_save_job.rb delete mode 100644 app/jobs/kps_address_update_job.rb diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 28c90e218..e5560fe26 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -32,14 +32,14 @@ def mernis if (Time.zone.now - @address.updated_at) / 1.day < 7 redirect_with('wait') else - KpsAddressUpdateJob.perform_later(address) + KpsAddressSaveJob.perform_later(current_user) redirect_with('will_update') end end def import_from_mernis if current_user.addresses.formal.blank? - KpsAddressCreateJob.perform_later(current_user) + KpsAddressSaveJob.perform_later(current_user) redirect_with('will_update') else redirect_with('wait') diff --git a/app/jobs/kps_address_create_job.rb b/app/jobs/kps_address_create_job.rb deleted file mode 100644 index 86525350e..000000000 --- a/app/jobs/kps_address_create_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class KpsAddressCreateJob < ApplicationJob - queue_as :high - - # slow operation - def perform(user) - @response = Services::Kps::Omu::Adres.new.sorgula(user.id_number.to_i) - end - - # callbacks - after_perform do |job| - district = District.find_by(mernis_code: @response[:district_id]) - job.arguments.first.addresses.formal.create(district: district, full_address: @response[:full_address]) - end -end diff --git a/app/jobs/kps_address_save_job.rb b/app/jobs/kps_address_save_job.rb new file mode 100644 index 000000000..9bd3f8511 --- /dev/null +++ b/app/jobs/kps_address_save_job.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class KpsAddressSaveJob < ApplicationJob + queue_as :high + + # slow operation + def perform(user) + @response = Services::Kps::Omu::Adres.new.sorgula(user.id_number.to_i) + end + + # callbacks + after_perform do |job| + district = District.find_by(mernis_code: @response[:district_id]) + formal = job.arguments.first.addresses.formal + if formal.present? + formal.update(district: district, full_address: @response[:full_address]) + else + formal.create(district: district, full_address: @response[:full_address]) + end + end +end diff --git a/app/jobs/kps_address_update_job.rb b/app/jobs/kps_address_update_job.rb deleted file mode 100644 index b8f27c6a2..000000000 --- a/app/jobs/kps_address_update_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class KpsAddressUpdateJob < ApplicationJob - queue_as :low - - # slow operation - def perform(address) - @params = Services::Kps::Omu::Adres.new.sorgula(address.id_number.to_i) - end - - # callbacks - after_perform do |job| - district = District.find_by(mernis_code: @params[:district_id]) - job.arguments.first.update(district: district, name: :formal, full_address: @params[:full_address]) - end -end diff --git a/app/models/user.rb b/app/models/user.rb index 605dd8e4c..43b5453c6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,7 +38,7 @@ class User < ApplicationRecord after_create_commit :build_identity_information, if: proc { identities.formal.empty? } def build_address_information - KpsAddressCreateJob.perform_later(self) + KpsAddressSaveJob.perform_later(self) end def build_identity_information diff --git a/test/jobs/kps_address_job_test.rb b/test/jobs/kps_address_job_test.rb index a1d849910..2f7206634 100644 --- a/test/jobs/kps_address_job_test.rb +++ b/test/jobs/kps_address_job_test.rb @@ -3,44 +3,29 @@ require 'test_helper' class KpsAddressJobTest < ActiveJob::TestCase - %w[ - KpsAddressCreateJob - KpsAddressUpdateJob - ].each do |property| - test "can enqueue #{property}" do - assert_enqueued_jobs 0 - property.constantize.perform_later(addresses(:formal)) - assert_enqueued_jobs 1 - end + test 'can enqueue KpsAddressSaveJob' do + assert_enqueued_jobs 0 + KpsAddressSaveJob.perform_later(users(:serhat)) + assert_enqueued_jobs 1 + end - test "can initialize KPS queries as #{property} for given user and address" do - client = Minitest::Mock.new - def client.sorgula - true - end + test 'can initialize KPS queries as KpsAddressSaveJob for given user and address' do + client = Minitest::Mock.new + def client.sorgula + true + end - Services::Kps::Omu::Adres.stub :new, client do - assert property.constantize.perform_later({}) # dummy hash - end + Services::Kps::Omu::Adres.stub :new, client do + assert KpsAddressSaveJob.perform_later({}) # dummy hash end end - %w[ - KpsAddressCreateJob - KpsAddressUpdateJob - ].each do |property| - test "can perform enqueued jobs for #{property}" do - skip 'this block on CircleCI since it needs IP permissions to run.' if ENV['CI'] - assert_performed_jobs 0 - args = if property.eql?('KpsAddressCreateJob') - users(:serhat) - else - addresses(:formal) - end - perform_enqueued_jobs do - property.constantize.perform_later(args) - end - assert_performed_jobs 1 + test 'can perform enqueued jobs for KpsAddressSaveJob' do + skip 'this block on CircleCI since it needs IP permissions to run.' if ENV['CI'] + assert_performed_jobs 0 + perform_enqueued_jobs do + KpsAddressSaveJob.perform_later(users(:serhat)) end + assert_performed_jobs 1 end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index fb8b9c19b..e144a7c7f 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -84,8 +84,8 @@ class UserTest < ActiveSupport::TestCase end # callback tests - test 'user runs KpsAddressCreateJob after being created' do - assert_enqueued_with(job: KpsAddressCreateJob) do + test 'user runs KpsAddressSaveJob after being created' do + assert_enqueued_with(job: KpsAddressSaveJob) do User.create( id_number: '12345678912', email: 'fakeuser@fakemail.com', From 407b9c80ea4e43607b5b98f9993c7bad3df51b1a Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Thu, 26 Jul 2018 16:03:20 +0300 Subject: [PATCH 04/10] Tidy up kps_address_save_job --- app/jobs/kps_address_save_job.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/jobs/kps_address_save_job.rb b/app/jobs/kps_address_save_job.rb index 9bd3f8511..efa5e3e9c 100644 --- a/app/jobs/kps_address_save_job.rb +++ b/app/jobs/kps_address_save_job.rb @@ -11,11 +11,8 @@ def perform(user) # callbacks after_perform do |job| district = District.find_by(mernis_code: @response[:district_id]) - formal = job.arguments.first.addresses.formal - if formal.present? - formal.update(district: district, full_address: @response[:full_address]) - else - formal.create(district: district, full_address: @response[:full_address]) - end + address = job.arguments.first.addresses.formal + response = { district: district, full_address: @response[:full_address] } + address.present? ? address.update(response) : address.create(response) end end From 126e236e294edb6cf198a07e66b97a00a8eda500 Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Tue, 31 Jul 2018 10:34:19 +0300 Subject: [PATCH 05/10] Merge mernis and import_from_mernis methods with name save_from_mernis --- .../account/addresses_controller.rb | 21 +++++++++-------- .../account/identities_controller.rb | 23 ++++++++++--------- app/views/account/addresses/index.html.erb | 13 ++--------- app/views/account/identities/index.html.erb | 12 +--------- config/locales/models/addresses/en.yml | 9 +++----- config/locales/models/addresses/tr.yml | 9 +++----- config/locales/models/identities/en.yml | 9 +++----- config/locales/models/identities/tr.yml | 9 +++----- config/routes.rb | 6 ++--- 9 files changed, 40 insertions(+), 71 deletions(-) diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index e5560fe26..1d901bf4f 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -4,6 +4,8 @@ module Account class AddressesController < ApplicationController before_action :set_address, only: %i[edit update destroy mernis] before_action :check_formality, only: %i[edit update destroy] + before_action :set_formal_address, only: %i[save_from_mernis] + before_action :set_elapsed_time, only: %i[save_from_mernis] def index @addresses = current_user.addresses.includes(district: [:city]) @@ -28,8 +30,8 @@ def destroy @address.destroy ? redirect_with('success') : redirect_with('warning') end - def mernis - if (Time.zone.now - @address.updated_at) / 1.day < 7 + def save_from_mernis + if @elapsed_time.present? && @elapsed_time < 7 redirect_with('wait') else KpsAddressSaveJob.perform_later(current_user) @@ -37,16 +39,15 @@ def mernis end end - def import_from_mernis - if current_user.addresses.formal.blank? - KpsAddressSaveJob.perform_later(current_user) - redirect_with('will_update') - else - redirect_with('wait') - end + private + + def set_formal_address + @address = current_user.addresses.formal.present? ? current_user.addresses.formal : nil end - private + def set_elapsed_time + @elapsed_time = (Time.zone.now - current_user.addresses.formal.first.updated_at) / 1.day if @address.present? + end def check_formality redirect_with('warning') if @address.formal? diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 6c46c0fdc..68db4b04c 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -4,6 +4,8 @@ module Account class IdentitiesController < ApplicationController before_action :set_identity, only: %i[edit update destroy mernis] before_action :check_formality, only: %i[edit update destroy] + before_action :set_formal_identities, only: %i[save_from_mernis] + before_action :set_elapsed_time, only: %i[save_from_mernis] def index @identities = current_user.identities @@ -28,26 +30,25 @@ def destroy @identity.destroy ? redirect_with('success') : redirect_with('warning') end - def mernis - if (Time.zone.now - @identity.updated_at) / 1.day < 7 + def save_from_mernis + if @elapsed_time.present? && @elapsed_time < 7 redirect_with('wait') else - # TODO: KpsIdentityUpdateJob.perform_later(identity) - redirect_with('will_update') - end - end - - def import_from_mernis - if current_user.identities.formal.blank? KpsIdentitySaveJob.perform_later(current_user) redirect_with('will_update') - else - redirect_with('wait') end end private + def set_formal_identities + @identities = current_user.identities.formal.present? ? current_user.identities.formal : nil + end + + def set_elapsed_time + @elapsed_time = (Time.zone.now - current_user.identities.formal.first.updated_at) / 1.day if @identities.present? + end + def check_formality redirect_with('warning') if @identity.formal? end diff --git a/app/views/account/addresses/index.html.erb b/app/views/account/addresses/index.html.erb index 540631326..115f767c9 100644 --- a/app/views/account/addresses/index.html.erb +++ b/app/views/account/addresses/index.html.erb @@ -1,6 +1,7 @@
<%= link_to_new(new_address_path, t('.new_address')) %> - <%= link_to_new(import_from_mernis_addresses_path, t('.import_from_mernis')) unless @addresses.present? %> + <%= link_to (@addresses.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis') ), save_from_mernis_addresses_path, class: "btn btn-outline-primary btn-sm" %> +
@@ -36,16 +37,6 @@ <%= t('.district_and_city') %> <%= address.district.name %> / <%= address.district.city.name %> - - - <% if address.formal? %> - <%= link_to(t('.update_from_mernis'), mernis_address_path(address), class: 'btn btn-outline-primary btn-sm') %> - <% else %> - <%= link_to_edit(edit_address_path(address)) %> - <%= link_to_destroy(address) %> - <% end %> - -
diff --git a/app/views/account/identities/index.html.erb b/app/views/account/identities/index.html.erb index b5ea95032..8aaf6c1eb 100644 --- a/app/views/account/identities/index.html.erb +++ b/app/views/account/identities/index.html.erb @@ -1,6 +1,6 @@
<%= link_to_new(new_identity_path, t('.new_identity')) %> - <%= link_to_new(import_from_mernis_identities_path, t('.import_from_mernis')) unless @identities.present? %> + <%= link_to (@identities.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis') ), save_from_mernis_identities_path, class: "btn btn-outline-primary btn-sm" %>
@@ -58,16 +58,6 @@ <%= t('.registered_to') %> <%= identity.registered_to %> - - - <% if identity.formal? %> - <%= link_to(t('.update_from_mernis'), mernis_identity_path(identity), class: 'btn btn-outline-primary btn-sm') %> - <% else %> - <%= link_to_edit(edit_identity_path(identity)) %> - <%= link_to_destroy(identity) %> - <% end %> - -
diff --git a/config/locales/models/addresses/en.yml b/config/locales/models/addresses/en.yml index 30044d044..002e49c0d 100644 --- a/config/locales/models/addresses/en.yml +++ b/config/locales/models/addresses/en.yml @@ -34,7 +34,7 @@ en: card_header: Address Information district_and_city: District / City update_from_mernis: Update from MERNİS - import_from_mernis: Import from MERNIS + create_from_mernis: Create from MERNIS new: form_title: Create Address edit: @@ -47,9 +47,6 @@ en: destroy: success: Address successfully deleted! warning: Address can not be deleted! - mernis: + save_from_mernis: wait: You recently created or updated your address. You can update your address once every week. - will_update: We got your address update request. In a couple of seconds/minutes you will be able to see your new address. - import_from_mernis: - wait: We got your address update request. In a couple of seconds/minutes you will be able to see your new address. - will_update: Your address information has been transferred to the system via MERNIS. + will_update: We got your address create or update request. In a couple of seconds/minutes you will be able to see your new address. diff --git a/config/locales/models/addresses/tr.yml b/config/locales/models/addresses/tr.yml index fd1baacf4..a4eece299 100644 --- a/config/locales/models/addresses/tr.yml +++ b/config/locales/models/addresses/tr.yml @@ -34,7 +34,7 @@ tr: card_header: Adres Bilgileri district_and_city: İlçe / İl update_from_mernis: MERNİS'ten Güncelle - import_from_mernis: MERNİS'ten Getir + create_from_mernis: MERNİS'ten Oluştur new: form_title: Adres Oluştur edit: @@ -47,9 +47,6 @@ tr: destroy: success: Adres başarıyla silindi! warning: Adres silinemedi! - mernis: + save_from_mernis: wait: Adresinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Adresinizi haftada bir güncelleyebilirsiniz. - will_update: Adres güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. - import_from_mernis: - wait: Adresinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Adresinizi haftada bir güncelleyebilirsiniz. - will_update: Adres bilginiz MERNİS üzerinden sisteme aktarım işlemi başlatılmıştır. + will_update: Adres oluşturma veya güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. diff --git a/config/locales/models/identities/en.yml b/config/locales/models/identities/en.yml index 6f652ebcf..a318e601d 100644 --- a/config/locales/models/identities/en.yml +++ b/config/locales/models/identities/en.yml @@ -42,7 +42,7 @@ en: new_identity: Add a New Identity card_header: Identity Information update_from_mernis: Update from MERNIS - import_from_mernis: Import from MERNIS + create_from_mernis: Create from MERNIS edit: warning: You can not edit your formal identity! form_title: Edit Identity @@ -55,9 +55,6 @@ en: destroy: success: Identity successfully deleted! warning: Identity can not be deleted! - mernis: + save_from_mernis: wait: You recently created or updated your identity. You can only update your identity once a week from MERNIS. - will_update: We have received your identity update request. Your identity will be updated in a couple of seconds/minutes. - import_from_mernis: - wait: We have received your identity update request. Your identity will be updated in a couple of seconds/minutes. - will_update: Your identity information has been transferred to the system via MERNIS. + will_update: We have received your identity create or update request. Your identity will be updated in a couple of seconds/minutes. diff --git a/config/locales/models/identities/tr.yml b/config/locales/models/identities/tr.yml index c576c3bfe..60c336749 100644 --- a/config/locales/models/identities/tr.yml +++ b/config/locales/models/identities/tr.yml @@ -42,7 +42,7 @@ tr: new_identity: Yeni Kimlik Ekle card_header: Kimlik Bilgileri update_from_mernis: MERNİS'ten Güncelle - import_from_mernis: MERNİS'ten Getir + create_from_mernis: MERNİS'ten Oluştur edit: warning: Yasal kimlik bilgilerinizi düzenleyemezsiniz! form_title: Kimliği Düzenle @@ -55,9 +55,6 @@ tr: destroy: success: Kimlik başarıyla silindi! warning: Kimlik silinemedi! - mernis: + save_from_mernis: wait: Kimliğinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Kimliğinizi haftada bir güncelleyebilirsiniz. - will_update: Kimlik güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. - import_from_mernis: - wait: Kimliğinizi yakın bir zamanda oluşturdunuz veya güncellediniz. Kimliğinizi haftada bir güncelleyebilirsiniz. - will_update: Kimlik bilginiz MERNİS üzerinden sisteme aktarım işlemi başlatılmıştır. + will_update: Kimlik oluşturma veya güncelleme talebinizi aldık, bir kaç saniye/dakika içerisinde adresiniz güncellenecek. diff --git a/config/routes.rb b/config/routes.rb index d683e05ba..9bae1d305 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,15 +20,13 @@ # Account home page scope module: :account do resources :identities, except: [:show] do - get 'mernis', on: :member collection do - get 'import_from_mernis' + get 'save_from_mernis' end end resources :addresses, except: :show do - get 'mernis', on: :member collection do - get 'import_from_mernis' + get 'save_from_mernis' end end end From aa190e088e957566006f3495de5d9546e167025b Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Tue, 31 Jul 2018 10:38:24 +0300 Subject: [PATCH 06/10] fix rubocop offences --- app/controllers/account/addresses_controller.rb | 4 ++-- app/controllers/account/identities_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 1d901bf4f..922530c19 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -2,7 +2,7 @@ module Account class AddressesController < ApplicationController - before_action :set_address, only: %i[edit update destroy mernis] + before_action :set_address, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] before_action :set_formal_address, only: %i[save_from_mernis] before_action :set_elapsed_time, only: %i[save_from_mernis] @@ -42,7 +42,7 @@ def save_from_mernis private def set_formal_address - @address = current_user.addresses.formal.present? ? current_user.addresses.formal : nil + @address = current_user.addresses.formal.presence ? current_user.addresses.formal : nil end def set_elapsed_time diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 68db4b04c..7690d6351 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -2,7 +2,7 @@ module Account class IdentitiesController < ApplicationController - before_action :set_identity, only: %i[edit update destroy mernis] + before_action :set_identity, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] before_action :set_formal_identities, only: %i[save_from_mernis] before_action :set_elapsed_time, only: %i[save_from_mernis] @@ -42,7 +42,7 @@ def save_from_mernis private def set_formal_identities - @identities = current_user.identities.formal.present? ? current_user.identities.formal : nil + @identities = current_user.identities.formal.presence ? current_user.identities.formal : nil end def set_elapsed_time From f55e1c25148278ead42ce8394fef2a317029aead Mon Sep 17 00:00:00 2001 From: Sinan Sahin Date: Tue, 31 Jul 2018 11:00:51 +0300 Subject: [PATCH 07/10] fix codebeat offences --- app/controllers/account/addresses_controller.rb | 2 +- app/controllers/account/identities_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 922530c19..869d40362 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -46,7 +46,7 @@ def set_formal_address end def set_elapsed_time - @elapsed_time = (Time.zone.now - current_user.addresses.formal.first.updated_at) / 1.day if @address.present? + @elapsed_time = (Time.zone.now - @address.first.updated_at) / 1.day if @address.present? end def check_formality diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 7690d6351..95d865db7 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -46,7 +46,7 @@ def set_formal_identities end def set_elapsed_time - @elapsed_time = (Time.zone.now - current_user.identities.formal.first.updated_at) / 1.day if @identities.present? + @elapsed_time = (Time.zone.now - @identities.first.updated_at) / 1.day if @identities.present? end def check_formality From 821c01e11728535882f5b163741a66a783410c72 Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 1 Aug 2018 02:26:31 +0300 Subject: [PATCH 08/10] Tidy up identities_controller. Prefer guard clause --- .../account/addresses_controller.rb | 29 ++++++++----------- .../account/identities_controller.rb | 29 ++++++++----------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 869d40362..86dbaada5 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -4,7 +4,6 @@ module Account class AddressesController < ApplicationController before_action :set_address, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] - before_action :set_formal_address, only: %i[save_from_mernis] before_action :set_elapsed_time, only: %i[save_from_mernis] def index @@ -31,34 +30,30 @@ def destroy end def save_from_mernis - if @elapsed_time.present? && @elapsed_time < 7 - redirect_with('wait') - else - KpsAddressSaveJob.perform_later(current_user) - redirect_with('will_update') - end + KpsAddressSaveJob.perform_later(current_user) + redirect_with('will_update') end private - def set_formal_address - @address = current_user.addresses.formal.presence ? current_user.addresses.formal : nil - end - - def set_elapsed_time - @elapsed_time = (Time.zone.now - @address.first.updated_at) / 1.day if @address.present? + def set_address + @address = current_user.addresses.find(params[:id]) end def check_formality redirect_with('warning') if @address.formal? end - def redirect_with(message) - redirect_to(addresses_path, notice: t(".#{message}")) + def set_elapsed_time + formal_address = current_user.addresses.formal + return unless formal_address.present? + + elapsed_time = (Time.zone.now - formal_address.first.updated_at) / 1.day + redirect_with('wait') if elapsed_time.present? && elapsed_time < 7 end - def set_address - @address = current_user.addresses.find(params[:id]) + def redirect_with(message) + redirect_to(addresses_path, notice: t(".#{message}")) end def address_params diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 95d865db7..a56a86552 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -4,7 +4,6 @@ module Account class IdentitiesController < ApplicationController before_action :set_identity, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] - before_action :set_formal_identities, only: %i[save_from_mernis] before_action :set_elapsed_time, only: %i[save_from_mernis] def index @@ -31,34 +30,30 @@ def destroy end def save_from_mernis - if @elapsed_time.present? && @elapsed_time < 7 - redirect_with('wait') - else - KpsIdentitySaveJob.perform_later(current_user) - redirect_with('will_update') - end + KpsIdentitySaveJob.perform_later(current_user) + redirect_with('will_update') end private - def set_formal_identities - @identities = current_user.identities.formal.presence ? current_user.identities.formal : nil - end - - def set_elapsed_time - @elapsed_time = (Time.zone.now - @identities.first.updated_at) / 1.day if @identities.present? + def set_identity + @identity = current_user.identities.find(params[:id]) end def check_formality redirect_with('warning') if @identity.formal? end - def redirect_with(message) - redirect_to(identities_path, notice: t(".#{message}")) + def set_elapsed_time + formal_identity = current_user.identities.formal + return unless formal_identity.present? + + elapsed_time = (Time.zone.now - formal_identity.first.updated_at) / 1.day + redirect_with('wait') if elapsed_time.present? && elapsed_time < 7 end - def set_identity - @identity = current_user.identities.find(params[:id]) + def redirect_with(message) + redirect_to(identities_path, notice: t(".#{message}")) end def identity_params From a75d5ec8b89ed78832e61b88e6fc2d598625e794 Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 1 Aug 2018 02:47:47 +0300 Subject: [PATCH 09/10] Remove extra instant variables from kps_identity_save_job. Use one-liner style in routes --- app/jobs/kps_identity_save_job.rb | 6 ++---- config/routes.rb | 8 ++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/jobs/kps_identity_save_job.rb b/app/jobs/kps_identity_save_job.rb index 5574d1dfc..99ae43cc3 100644 --- a/app/jobs/kps_identity_save_job.rb +++ b/app/jobs/kps_identity_save_job.rb @@ -5,7 +5,6 @@ class KpsIdentitySaveJob < ApplicationJob # slow operation def perform(user, student_id = nil) - @user = user @student_id = student_id @response = Services::Kps::Omu::Kimlik.new.sorgula(user.id_number.to_i) end @@ -13,8 +12,7 @@ def perform(user, student_id = nil) # callbacks after_perform do |_job| response = @response.merge(student_id: @student_id) - formal = @user.identities.formal - # Eğer kişinin formal kimliği varsa; kimlik bilgilerini güncelle, yoksa formal kimlik oluştur. - formal.present? ? formal.update(response) : formal.create(response) + formal_address = job.arguments.first.identities.formal + formal_address.present? ? formal_address.update(response) : formal_address.create(response) end end diff --git a/config/routes.rb b/config/routes.rb index 9bae1d305..1efee9e59 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,14 +20,10 @@ # Account home page scope module: :account do resources :identities, except: [:show] do - collection do - get 'save_from_mernis' - end + get 'save_from_mernis', on: :collection end resources :addresses, except: :show do - collection do - get 'save_from_mernis' - end + get 'save_from_mernis', on: :collection end end From 853bcf1ee9ae0bb3e1e541f30e3dffde21185f25 Mon Sep 17 00:00:00 2001 From: msdundar Date: Wed, 1 Aug 2018 03:11:01 +0300 Subject: [PATCH 10/10] Move common behavior to concern --- app/controllers/account/addresses_controller.rb | 8 ++++---- app/controllers/account/identities_controller.rb | 8 ++++---- app/controllers/concerns/last_update_from_mernis.rb | 10 ++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 app/controllers/concerns/last_update_from_mernis.rb diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 86dbaada5..c09bd4411 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -2,6 +2,8 @@ module Account class AddressesController < ApplicationController + include LastUpdateFromMernis + before_action :set_address, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] before_action :set_elapsed_time, only: %i[save_from_mernis] @@ -46,10 +48,8 @@ def check_formality def set_elapsed_time formal_address = current_user.addresses.formal - return unless formal_address.present? - - elapsed_time = (Time.zone.now - formal_address.first.updated_at) / 1.day - redirect_with('wait') if elapsed_time.present? && elapsed_time < 7 + return if formal_address.blank? + elapsed_time(formal_address) end def redirect_with(message) diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index a56a86552..8c5f65e4e 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -2,6 +2,8 @@ module Account class IdentitiesController < ApplicationController + include LastUpdateFromMernis + before_action :set_identity, only: %i[edit update destroy] before_action :check_formality, only: %i[edit update destroy] before_action :set_elapsed_time, only: %i[save_from_mernis] @@ -46,10 +48,8 @@ def check_formality def set_elapsed_time formal_identity = current_user.identities.formal - return unless formal_identity.present? - - elapsed_time = (Time.zone.now - formal_identity.first.updated_at) / 1.day - redirect_with('wait') if elapsed_time.present? && elapsed_time < 7 + return if formal_identity.blank? + elapsed_time(formal_identity) end def redirect_with(message) diff --git a/app/controllers/concerns/last_update_from_mernis.rb b/app/controllers/concerns/last_update_from_mernis.rb new file mode 100644 index 000000000..0a00b2944 --- /dev/null +++ b/app/controllers/concerns/last_update_from_mernis.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module LastUpdateFromMernis + extend ActiveSupport::Concern + + def elapsed_time(resource) + elapsed_time = (Time.zone.now - resource.first.updated_at) / 1.day + redirect_with('wait') if elapsed_time.present? && elapsed_time < 7 + end +end