diff --git a/.codebeatsettings b/.codebeatsettings new file mode 100644 index 000000000..7ff72a765 --- /dev/null +++ b/.codebeatsettings @@ -0,0 +1,5 @@ +{ + "RUBY": { + "ABC": [15, 25, 50, 70] + } +} \ No newline at end of file diff --git a/Gemfile b/Gemfile index ed8bc48cb..3fed47413 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'devise' # assets: core asset dependencies gem 'coffee-rails', '~> 4.2' -gem 'sass-rails', '~> 5.0' +gem 'sassc-rails' gem 'uglifier', '>= 1.3.0' # view helpers: tools for forms, views, etc. @@ -48,7 +48,7 @@ gem 'pg_search' gem 'rollbar' # permalinks -gem 'friendly_id', '~> 5.1.0' +gem 'friendly_id', '~> 5.2.0' group :development, :test do gem 'brakeman', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 5e9ab9146..83d06c68b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,7 +70,7 @@ GEM bundler (~> 1.2) thor (~> 0.18) byebug (10.0.2) - capybara (3.3.1) + capybara (3.4.2) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -123,7 +123,7 @@ GEM ffi (1.9.25) font-awesome-rails (4.7.0.4) railties (>= 3.2, < 6.0) - friendly_id (5.1.0) + friendly_id (5.2.4) activerecord (>= 4.0.0) globalid (0.4.1) activesupport (>= 4.2.0) @@ -172,7 +172,7 @@ GEM mini_portile2 (~> 2.3.0) nori (2.6.0) orm_adapter (0.5.0) - pagy (0.13.1) + pagy (0.15.0) parallel (1.12.1) parser (2.5.1.2) ast (~> 2.4.0) @@ -192,7 +192,7 @@ GEM rack (2.0.5) rack-protection (2.0.3) rack - rack-test (1.0.0) + rack-test (1.1.0) rack (>= 1.0, < 3) rails (5.2.0) actioncable (= 5.2.0) @@ -232,9 +232,9 @@ GEM responders (2.4.0) actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) - rollbar (2.16.3) + rollbar (2.16.4) multi_json - rubocop (0.58.1) + rubocop (0.58.2) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) @@ -245,17 +245,21 @@ GEM ruby-progressbar (1.9.0) ruby_dep (1.5.0) rubyzip (1.2.1) - sass (3.5.6) + sass (3.5.7) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) + sassc (1.12.1) + ffi (~> 1.9.6) + sass (>= 3.3.0) + sassc-rails (1.3.0) + railties (>= 4.0.0) + sass + sassc (~> 1.9) + sprockets (> 2.11) + sprockets-rails + tilt savon (2.12.0) akami (~> 1.2) builder (>= 2.1.2) @@ -264,7 +268,7 @@ GEM nokogiri (>= 1.8.1) nori (~> 2.4) wasabi (~> 3.4) - selenium-webdriver (3.13.0) + selenium-webdriver (3.13.1) childprocess (~> 0.5) rubyzip (~> 1.2) sidekiq (5.1.3) @@ -300,7 +304,7 @@ GEM tilt (2.0.8) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.15) + uglifier (4.1.17) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext @@ -349,7 +353,7 @@ DEPENDENCIES dotenv-rails email_address font-awesome-rails - friendly_id (~> 5.1.0) + friendly_id (~> 5.2.0) groupdate jbuilder (~> 2.5) letter_opener @@ -364,7 +368,7 @@ DEPENDENCIES reek rollbar rubocop - sass-rails (~> 5.0) + sassc-rails savon (~> 2.12.0) selenium-webdriver sidekiq diff --git a/LICENCE.md b/LICENSE.md similarity index 100% rename from LICENCE.md rename to LICENSE.md diff --git a/README.md b/README.md index 7f47d26cd..12f06a7d2 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ export SECRET_KEY_BASE=GENERATED_SECRET_VALUE ## HowTo -See [Wiki pages](https://github.com/omu/nokul-bati/wiki) for how-to documents. +See [Wiki pages](https://github.com/omu/nokul/wiki) for how-to documents. ## Code Quality @@ -97,11 +97,13 @@ rake test ## Rake Tasks -- [OPTIONAL]. `setup` or `seed` already does it, but if you want to externally create YOKSIS references and departments inside your app, run the tasks shown below: +- [OPTIONAL]. `setup` or `seed` already does it, but if you want to externally create YOKSIS references, departments, country codes and academic staffs inside your app, run the tasks shown below: ```bash rake yoksis:fetch_references +rake yoksis:fetch_academic_staff rake yoksis:import_departments +rake yoksis:import_yoksis_country_codes ``` * `fetch` prefix has used for API operations, `import` prefix has used for local CSV importing operations. diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 72681dacd..c09bd4411 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -2,8 +2,11 @@ module Account class AddressesController < ApplicationController - before_action :set_address, only: %i[edit update destroy mernis] + 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] def index @addresses = current_user.addresses.includes(district: [:city]) @@ -28,27 +31,29 @@ def destroy @address.destroy ? redirect_with('success') : redirect_with('warning') end - def mernis - if (Time.zone.now - @address.updated_at) / 1.day < 7 - redirect_with('wait') - else - KpsAddressUpdateJob.perform_later(address) - redirect_with('will_update') - end + def save_from_mernis + KpsAddressSaveJob.perform_later(current_user) + redirect_with('will_update') end private + 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 if formal_address.blank? + elapsed_time(formal_address) 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 b958bc235..8c5f65e4e 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -2,8 +2,11 @@ module Account class IdentitiesController < ApplicationController - before_action :set_identity, only: %i[edit update destroy mernis] + 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] def index @identities = current_user.identities @@ -28,27 +31,29 @@ def destroy @identity.destroy ? redirect_with('success') : redirect_with('warning') end - def mernis - if (Time.zone.now - @identity.updated_at) / 1.day < 7 - redirect_with('wait') - else - # TODO: KpsIdentityUpdateJob.perform_later(identity) - redirect_with('will_update') - end + def save_from_mernis + KpsIdentitySaveJob.perform_later(current_user) + redirect_with('will_update') end private + 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 if formal_identity.blank? + elapsed_time(formal_identity) 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 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 diff --git a/app/jobs/kps_address_create_job.rb b/app/jobs/kps_address_save_job.rb similarity index 54% rename from app/jobs/kps_address_create_job.rb rename to app/jobs/kps_address_save_job.rb index 86525350e..efa5e3e9c 100644 --- a/app/jobs/kps_address_create_job.rb +++ b/app/jobs/kps_address_save_job.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class KpsAddressCreateJob < ApplicationJob +class KpsAddressSaveJob < ApplicationJob queue_as :high # slow operation @@ -11,6 +11,8 @@ def perform(user) # 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]) + address = job.arguments.first.addresses.formal + response = { district: district, full_address: @response[:full_address] } + address.present? ? address.update(response) : address.create(response) 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/jobs/kps_identity_create_job.rb b/app/jobs/kps_identity_save_job.rb similarity index 51% rename from app/jobs/kps_identity_create_job.rb rename to app/jobs/kps_identity_save_job.rb index c0013be17..99ae43cc3 100644 --- a/app/jobs/kps_identity_create_job.rb +++ b/app/jobs/kps_identity_save_job.rb @@ -1,17 +1,18 @@ # frozen_string_literal: true -class KpsIdentityCreateJob < ApplicationJob +class KpsIdentitySaveJob < ApplicationJob queue_as :high # 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 # callbacks after_perform do |_job| - @user.identities.formal.create(@response.merge(student_id: @student_id)) + response = @response.merge(student_id: @student_id) + formal_address = job.arguments.first.identities.formal + formal_address.present? ? formal_address.update(response) : formal_address.create(response) end end diff --git a/app/models/accounts/student.rb b/app/models/accounts/student.rb index cc49805a9..97ea0b805 100644 --- a/app/models/accounts/student.rb +++ b/app/models/accounts/student.rb @@ -17,6 +17,6 @@ class Student < ApplicationRecord after_create_commit :build_identity_information, if: proc { identity.nil? } def build_identity_information - KpsIdentityCreateJob.perform_later(user, id) + KpsIdentitySaveJob.perform_later(user, id) end end diff --git a/app/models/user.rb b/app/models/user.rb index 7612fb2da..43b5453c6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,11 +38,11 @@ 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 - KpsIdentityCreateJob.perform_later(self) + KpsIdentitySaveJob.perform_later(self) end # custom methods diff --git a/app/services/kps/omu/adres.rb b/app/services/kps/omu/adres.rb index 550c45b4f..ee81a4edd 100644 --- a/app/services/kps/omu/adres.rb +++ b/app/services/kps/omu/adres.rb @@ -15,24 +15,23 @@ def sorgula(queried_id_number) :adres_sorgula, message: message ).body[:adres_sorgula_response][:return][:sorgula_result][:sorgu_sonucu][:kimlik_noile_kisi_adres_bilgileri] - if response[:hata_bilgisi].present? - raise IdNumberError i - else - yerlesim_yeri = response[:yerlesim_yeri_adresi] - address_root = if yerlesim_yeri[:il_ilce_merkez_adresi].present? - yerlesim_yeri[:il_ilce_merkez_adresi] - elsif yerlesim_yeri[:koy_adresi].present? - yerlesim_yeri[:koy_adresi] - elsif yerlesim_yeri[:yurt_disi_adresi].present? - yerlesim_yeri[:yurt_disi_adresi] - end - # return a hash, ready to use for building an Address. - address_information = { - full_address: yerlesim_yeri[:acik_adres], - district_id: address_root[:ilce_kodu].to_i - } - address_information - end + raise IdNumberError if response[:hata_bilgisi].present? + + yerlesim_yeri = response[:yerlesim_yeri_adresi] + address_root = if yerlesim_yeri[:il_ilce_merkez_adresi].present? + yerlesim_yeri[:il_ilce_merkez_adresi] + elsif yerlesim_yeri[:koy_adresi].present? + yerlesim_yeri[:koy_adresi] + elsif yerlesim_yeri[:yurt_disi_adresi].present? + yerlesim_yeri[:yurt_disi_adresi] + end + + # return a hash, ready to use for building an Address. + address_information = { + full_address: yerlesim_yeri[:acik_adres], + district_id: address_root[:ilce_kodu].to_i + } + address_information end end end diff --git a/app/views/account/addresses/index.html.erb b/app/views/account/addresses/index.html.erb index 87b7cc158..115f767c9 100644 --- a/app/views/account/addresses/index.html.erb +++ b/app/views/account/addresses/index.html.erb @@ -1,5 +1,7 @@