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 #438 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Oct 4, 2018
2 parents f774eea + b5b4e1e commit 3c56f79
Show file tree
Hide file tree
Showing 51 changed files with 298 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ AllCops:
- config/initializers/simple_form_bootstrap.rb
- config/environments/*.rb
- config/routes.rb
- lib/api/kps/omu/adres.rb # WIP
- lib/api/kps/omu/kimlik.rb # WIP
- app/services/kps/omu/adres.rb # WIP
- app/services/kps/omu/kimlik.rb # WIP
- Vagrantfile
7 changes: 2 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,19 @@ gem 'rollbar'
# permalinks
gem 'friendly_id', '~> 5.2.0'

# progressbar
gem 'ruby-progressbar'

group :development, :test do
gem 'brakeman', require: false
gem 'bundler-audit'
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'codacy-coverage', require: false
gem 'dotenv-rails'
gem 'reek'
gem 'rubocop'
gem 'simplecov', require: false
end

group :test do
gem 'capybara'
gem 'chromedriver-helper'
gem 'codacy-coverage', require: false
gem 'selenium-webdriver'
end

Expand All @@ -78,6 +74,7 @@ group :development do
gem 'letter_opener'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'pry-rails'
gem 'ruby-progressbar'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '>= 3.3.0' # call <%= console %> anywhere in the code.
Expand Down
24 changes: 0 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ GEM
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.3)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.12)
bindex (0.5.0)
bootsnap (1.3.2)
Expand Down Expand Up @@ -101,16 +97,10 @@ GEM
cocoon (1.2.11)
codacy-coverage (2.1.0)
simplecov
codeclimate-engine-rb (0.4.1)
virtus (~> 1.0)
coderay (1.1.2)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.0.5)
connection_pool (2.2.2)
crass (1.0.4)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -125,7 +115,6 @@ GEM
email_address (0.1.11)
netaddr (~> 2.0)
simpleidn
equalizer (0.0.11)
erubi (1.7.1)
execjs (2.7.0)
ffi (1.9.25)
Expand All @@ -146,7 +135,6 @@ GEM
socksify
i18n (1.1.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
image_processing (1.7.1)
mini_magick (~> 4.0)
ruby-vips (>= 2.0.13, < 3)
Expand All @@ -157,7 +145,6 @@ GEM
multi_json (>= 1.2)
jmespath (1.4.0)
json (2.1.0)
kwalify (0.7.2)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.6.0)
Expand Down Expand Up @@ -239,11 +226,6 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redis (4.0.2)
reek (5.1.0)
codeclimate-engine-rb (~> 0.4.0)
kwalify (~> 0.7.0)
parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
rainbow (>= 2.0, < 4.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
Expand Down Expand Up @@ -328,11 +310,6 @@ GEM
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)
uniform_notifier (1.11.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.7)
rack (>= 1.0)
wasabi (3.5.0)
Expand Down Expand Up @@ -384,7 +361,6 @@ DEPENDENCIES
puma (~> 3.11)
rails (~> 5.2.1)
redis
reek
rollbar
rubocop
ruby-progressbar
Expand Down
27 changes: 14 additions & 13 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ class UsersController < ApplicationController
include PagyBackendWithHelpers
include LastUpdateFromMernis

before_action :set_user, only: %i[show edit update destroy save_address_from_mernis save_identity_from_mernis]
before_action :set_identities, only: :show
before_action :set_addresses, only: :show
before_action :set_user, except: %i[index new create]
before_action :set_address_elapsed_time, only: %i[save_address_from_mernis]
before_action :set_identity_elapsed_time, only: %i[save_identity_from_mernis]
before_action :nullify_slug, only: :update

def index
@users = pagy_by_search(User.all)
end

def show
@identities = @user.identities
@addresses = @user.addresses
@employees = @user.employees.includes(:title).order(active: :desc)
@duties = @user.duties.includes(:unit)
@positions = @user.positions.includes(:administrative_function, :duty)
Expand All @@ -32,8 +33,11 @@ def create
def edit; end

def update
@user.slug = nil if user_params[:email].present?
@user.update_without_password(user_params) ? redirect_with('.success') : render(:edit)
if user_params[:password].blank? || user_params[:password_confirmation].blank?
@user.update_without_password(user_params) ? redirect_with('.success') : render(:edit)
else
@user.update(user_params) ? redirect_with('.success') : render(:edit)
end
end

def destroy
Expand All @@ -56,14 +60,6 @@ def set_user
@user = User.friendly.find(params[:id])
end

def set_identities
@identities = @user.identities
end

def set_addresses
@addresses = @user.addresses
end

def set_address_elapsed_time
formal_address = @user.addresses.formal
return if formal_address.blank?
Expand All @@ -78,6 +74,11 @@ def set_identity_elapsed_time
elapsed_time(formal_identity)
end

def nullify_slug
# generate a new slug when the e-mail changes
@user.slug = nil if user_params[:email].present?
end

def user_params
params.require(:user).permit(:id_number, :email, :password, :password_confirmation, :preferred_language)
end
Expand Down
12 changes: 4 additions & 8 deletions app/jobs/osym/import_prospective_students_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ class ImportProspectiveStudentsJob < ApplicationJob
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/BlockLength
def perform
content = FileEncryptor.decrypt_lines('db/encrypted_data/prospective_students.csv.enc')
def perform(file_path)
content = FileEncryptor.decrypt_lines(file_path)

progress_bar = ProgressBar.create(
title: 'Prospective Students',
total: content.count,
format: '%t %B %c/%C %a'
)
progress_bar = ProgressBar.spawn('Prospective Students', content.count)

content.each do |prospective_student|
id_number, first_name, last_name, fathers_name, mothers_name, d, m, y, gender, turkish, kktc, foreign,
Expand Down Expand Up @@ -76,7 +72,7 @@ def perform
obs_registered_program: obs_registered_program,
student_entrance_type: StudentEntranceType.find_by(code: 1) # TODO: will be dynamic in the future
)
progress_bar.increment
progress_bar&.increment
end
end
# rubocop:enable Metrics/AbcSize
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion app/views/units/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
<%= f.input :name, required: true %>
</div>
<div class='form-group col-sm-6'>
<%= f.input :yoksis_id, required: true %>
<%= f.input :yoksis_id %>
</div>
<div class='form-group col-sm-6'>
<%= f.input :detsis_id %>
</div>
<div class='form-group col-sm-6'>
<%= f.input :founded_at, required: true, start_year: Date.today.year - 50 %>
Expand Down
17 changes: 6 additions & 11 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

module Nokul
class Application < Rails::Application
# support libraries are used for tenant configuration and Rakefile,
# therefore they have to required in the first place.
Dir[
Rails.root.join('lib', 'support', '**', '*.rb')
].each { |file| require file }

# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2

Expand All @@ -24,12 +30,6 @@ class Application < Rails::Application
# auto-load nested translation folders ie: locales/models/foo.yml
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.yml').to_s]

Dir[
Rails.root.join('app', 'services', '**', '*.rb'),
Rails.root.join('lib', 'support', '**', '*.rb'),
Rails.root.join('lib', 'api', '**', '*.rb')
].each { |file| require file }

# use app-wide e-mail template for devise
config.to_prepare { Devise::Mailer.layout 'mailer' }

Expand All @@ -38,10 +38,5 @@ class Application < Rails::Application

# tenant configuration
config.tenant = config_for("tenants/#{ENV['RAILS_TENANT'] || 'omu'}").to_deep_ostruct

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.default_url_options = { host: 'localhost:3000' }
config.action_mailer.delivery_method = :test

# Print deprecation notices to the stderr.
Expand Down
3 changes: 1 addition & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'f3f90e74367d8a1aeac154b55f4039b4a6629da6649e63884a944578e89f1453cb97afd2ec03764c2f4af9b3585\
# 81aa3aec97d3a53b1023726441876bd13e32f'
config.secret_key = Rails.application.credentials.devise[:secret_key]

# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
Rake::Task['fetch:academic_staff'].invoke

# Import prospective students of 2018
Osym::ImportProspectiveStudentsJob.perform_later
Osym::ImportProspectiveStudentsJob.perform_later('db/encrypted_data/prospective_students.csv.enc')
Empty file removed lib/assets/.keep
Empty file.
1 change: 0 additions & 1 deletion lib/support/core_ext/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Hash
# Stolen and refactored from https://stackoverflow.com/a/11137694

def to_deep_ostruct
internal_hashes = {}
each do |key, value|
Expand Down
2 changes: 1 addition & 1 deletion lib/support/ext/progress_bar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

class ProgressBar
def self.spawn(title, total, output = $stdout)
ProgressBar.create(title: title, total: total, format: '%t %B %c/%C %a', output: output)
ProgressBar.create(title: title, total: total, format: '%t %B %c/%C %a', output: output) if Rails.env.development?
end
end
2 changes: 1 addition & 1 deletion lib/support/import_from_yml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.parse(klass)

file.each do |line|
klass.constantize.create(line)
progress_bar.increment
progress_bar&.increment
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/fetch/fetch_academic_staff.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace :fetch do

next unless user.save

progress_bar.increment
progress_bar&.increment

title = Title.find_by(name: academic_staff[:kadro_unvan].capitalize_all)
unit = Unit.find_by(yoksis_id: academic_staff[:birim_id])
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/fetch/fetch_references.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace :fetch do
Rake::Task['fetch:reference'].invoke(action, klass)
# https://stackoverflow.com/questions/4822020/why-does-a-rake-task-in-a-loop-execute-only-once
Rake::Task['fetch:reference'].reenable
progress_bar.increment
progress_bar&.increment
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/import/administrative_units.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace :import do
name: 'Aktif'
).id
Unit.create(unit.except('parent_yoksis_id'))
progress_bar.increment
progress_bar&.increment
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/import/cities.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :import do
file.each do |city|
country = Country.find_by(alpha_2_code: city['alpha_2_code'].split('-').first)
country.cities.create(city)
progress_bar.increment
progress_bar&.increment
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/import/districts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :import do
file.each do |district|
city = City.find_by(alpha_2_code: district['alpha_2_code'])
city.districts.create(district.except('alpha_2_code'))
progress_bar.increment
progress_bar&.increment
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/import/units.rake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace :import do
name: 'Atakum'
).id
Unit.create(unit.except('parent_yoksis_id'))
progress_bar.increment
progress_bar&.increment
end
end
end
2 changes: 1 addition & 1 deletion lib/tasks/import/yoksis_country_codes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :import do
file.each do |yoksis_country|
country = Country.find_by(name: yoksis_country['name'])
country&.update(yoksis_code: yoksis_country['yoksis_code'])
progress_bar.increment
progress_bar&.increment
end
end
end
9 changes: 0 additions & 9 deletions lib/tasks/quality.rake
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# frozen_string_literal: true

namespace :quality do
desc 'Runs Ruby specific code quality testing'
task :ruby do
sh 'bundle exec rubocop -f fu -D'
sh 'bundle exec rubycritic --format console'
end

desc 'Runs Rails specific code quality testing'
task :rails do
sh 'bundle exec rubocop -f fu -R -D'
end

desc 'Runs both rubocop and reek'
task all: %w[ruby rails]
end
Loading

0 comments on commit 3c56f79

Please sign in to comment.