Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #142 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Aug 1, 2018
2 parents f2054d9 + 266aeaa commit ab84e7c
Show file tree
Hide file tree
Showing 26 changed files with 202 additions and 161 deletions.
5 changes: 5 additions & 0 deletions .codebeatsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"RUBY": {
"ABC": [15, 25, 50, 70]
}
}
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
38 changes: 21 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -364,7 +368,7 @@ DEPENDENCIES
reek
rollbar
rubocop
sass-rails (~> 5.0)
sassc-rails
savon (~> 2.12.0)
selenium-webdriver
sidekiq
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
29 changes: 17 additions & 12 deletions app/controllers/account/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down
29 changes: 17 additions & 12 deletions app/controllers/account/identities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/concerns/last_update_from_mernis.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class KpsAddressCreateJob < ApplicationJob
class KpsAddressSaveJob < ApplicationJob
queue_as :high

# slow operation
Expand All @@ -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
16 changes: 0 additions & 16 deletions app/jobs/kps_address_update_job.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/models/accounts/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ab84e7c

Please sign in to comment.