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 #860 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Mar 14, 2019
2 parents 29e01cf + 2474a1f commit 55812ee
Show file tree
Hide file tree
Showing 40 changed files with 898 additions and 321 deletions.
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Rails:
Enabled: true
Style/AsciiComments:
Enabled: false
Style/Lambda:
Expand All @@ -21,9 +23,11 @@ Metrics/BlockLength:
Metrics/ClassLength:
Exclude:
- test/**/*.rb
# Do not exclude files from ALL COPS unless it's really necessary!
AllCops:
TargetRubyVersion: 2.6
# Do not exclude files from ALL COPS unless it's really necessary!
Exclude:
- app/controllers/concerns/reference_resource.rb
- bin/**/*
- vendor/bundle/**/*
- node_modules/**/*
Expand Down
27 changes: 15 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GIT

GIT
remote: https://github.com/rails/rails.git
revision: a783e4171241480324be575259de32a49d59405d
revision: 43fc7b476b483a89dacf9964ccf288f6bc6e1595
specs:
actioncable (6.0.0.beta3)
actionpack (= 6.0.0.beta3)
Expand Down Expand Up @@ -134,19 +134,21 @@ GEM
ast (2.4.0)
aws-eventstream (1.0.2)
aws-partitions (1.144.0)
aws-sdk-core (3.46.2)
aws-eventstream (~> 1.0)
aws-sdk-core (3.47.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
aws-sigv4 (~> 1.1)
http-2 (~> 0.10)
jmespath (~> 1.0)
aws-sdk-kms (1.13.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sigv4 (~> 1.0)
aws-sdk-s3 (1.31.0)
aws-sdk-core (~> 3, >= 3.39.0)
aws-sdk-kms (1.14.0)
aws-sdk-core (~> 3, >= 3.47.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.32.0)
aws-sdk-core (~> 3, >= 3.47.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.3)
aws-sigv4 (1.1.0)
aws-eventstream (~> 1.0, >= 1.0.2)
bcrypt (3.1.12)
better_html (1.0.13)
actionview (>= 4.0)
Expand Down Expand Up @@ -219,8 +221,8 @@ GEM
erubi (1.8.0)
execjs (2.7.0)
ffi (1.10.0)
fit-commit (3.8.0)
swearjar (~> 1.0)
fit-commit (3.8.1)
swearjar (~> 1.3)
font-awesome-rails (4.7.0.4)
railties (>= 3.2, < 6.0)
friendly_id (5.2.5)
Expand All @@ -231,6 +233,7 @@ GEM
activesupport (>= 4.2)
hashdiff (0.3.8)
html_tokenizer (0.0.7)
http-2 (0.10.1)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
image_processing (1.8.0)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/concerns/reference_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module ReferenceResource
extend ActiveSupport::Concern
include SearchableModule

# rubocop:disable Metrics/BlockLength
# rubocop:disable Rails/LexicallyScopedActionFilter
included do
before_action :set_variables
before_action :set_resource, only: %i[edit update destroy]
Expand Down Expand Up @@ -52,6 +50,4 @@ def redirect_with(message)
redirect_to(send("admin_#{controller_name}_path"), notice: t(".#{message}"))
end
end
# rubocop:enable Metrics/BlockLength
# rubocop:enable Rails/LexicallyScopedActionFilter
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module FirstRegistration
class ProspectiveStudentsController < ApplicationController
include SearchableModule

before_action :set_prospective_student, only: %i[show register]
before_action :set_prospective_student, only: %i[show edit update register]
before_action :can_register?, only: :register

def index
Expand All @@ -17,11 +17,30 @@ def show
@prospective_student = ProspectiveStudentDecorator.new(@prospective_student)
end

def new
@prospective_student = ProspectiveStudent.new
end

def create
@prospective_student = ProspectiveStudent.new(prospective_student_params)
@prospective_student.save ? redirect_to(index_path, notice: t('.success')) : render(:new)
end

def edit; end

def update
if @prospective_student.update(prospective_student_params)
redirect_to([:first_registration, @prospective_student], notice: t('.success'))
else
render(:edit)
end
end

def register
prospective_student = FirstRegistration::ProspectiveStudentService.new(@prospective_student)

if prospective_student.register
@prospective_student.update(registered: true)
@prospective_student.update(registered: true, archived: true)
redirect_to(index_path, notice: t('.success'))
else
redirect_to(index_path, alert: t('.warning'))
Expand All @@ -41,5 +60,53 @@ def set_prospective_student
def can_register?
redirect_to(index_path, alert: t('.can_not_register')) unless @prospective_student.can_temporarily_register?
end

# rubocop:disable Metrics/MethodLength
def prospective_student_params
params.require(:prospective_student).permit(
:academic_term_id,
:additional_score,
:address,
:date_of_birth,
:email,
:exam_score,
:expiry_date,
:fathers_name,
:first_name,
:gender,
:high_school_branch,
:high_school_code,
:high_school_graduation_year,
:high_school_type_id,
:home_phone,
:id_number,
:language_id,
:last_name,
:meb_status,
:meb_status_date,
:military_status,
:military_status_date,
:mobile_phone,
:mothers_name,
:nationality,
:obs_registered_program,
:obs_status,
:obs_status_date,
:place_of_birth,
:placement_rank,
:placement_score,
:placement_score_type,
:placement_type,
:preference_order,
:registration_city,
:registration_district,
:state_of_education,
:student_disability_type_id,
:student_entrance_type_id,
:top_student,
:unit_id
)
end
# rubocop:enable Metrics/MethodLength
end
end
6 changes: 1 addition & 5 deletions app/decorators/prospective_student_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ def calendar
)
end

def academic_term
@academic_term ||= AcademicTerm.active.last
end

def registration_documents
@registration_documents ||= unit.registration_documents
.includes(:document)
.includes(:document_type)
.where(academic_term: academic_term)
end

Expand Down
6 changes: 5 additions & 1 deletion app/jobs/osym/import_prospective_students_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def perform(file_path)
additional_score = find_additional_score(additional_score)
obs_registered_program = find_obs_registered_program(obs_registered_program)
high_school_type = find_high_school_type(high_school_type)
academic_term = AcademicTerm.find_by(year: '2017 - 2018', term: 'fall')

ProspectiveStudent.create(
id_number: id_number,
Expand Down Expand Up @@ -70,7 +71,10 @@ def perform(file_path)
obs_status: obs_status.eql?('0') ? true : false,
obs_status_date: parse_date(obs_status_date),
obs_registered_program: obs_registered_program,
student_entrance_type: StudentEntranceType.find_by(code: 1) # TODO: will be dynamic in the future
student_entrance_type: StudentEntranceType.find_by(code: 1), # TODO: will be dynamic in the future
academic_term: academic_term,
expiry_date: academic_term.end_of_term,
system_register_type: :bulk
)
progress_bar&.increment
end
Expand Down
1 change: 1 addition & 0 deletions app/models/academic_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AcademicTerm < ApplicationRecord

# relations
has_many :calendars, dependent: :nullify
has_many :prospective_students, dependent: :nullify
has_many :registration_documents, dependent: :nullify

# validations
Expand Down
13 changes: 11 additions & 2 deletions app/models/prospective_student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class ProspectiveStudent < ApplicationRecord
using: { tsearch: { prefix: true } }
)

search_keys :meb_status, :military_status, :obs_status, :unit_id, :student_entrance_type_id, :registered
search_keys :meb_status, :military_status, :obs_status, :unit_id, :student_entrance_type_id,
:registered, :academic_term_id, :system_register_type, :archived

# callbacks
before_create :capitalize_attributes
Expand All @@ -21,19 +22,22 @@ class ProspectiveStudent < ApplicationRecord
enum gender: { male: 1, female: 2 }
enum nationality: { turkish: 1, kktc: 2, foreign: 3 }
enum placement_type: { general_score: 1, additional_score: 2 }
enum system_register_type: { manual: 0, bulk: 1 }

# relations
belongs_to :academic_term
belongs_to :high_school_type, optional: true
belongs_to :language, optional: true
belongs_to :student_entrance_type
belongs_to :student_disability_type, optional: true
belongs_to :unit

# validations
validates :additional_score, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :additional_score, allow_nil: true, inclusion: { in: additional_scores.keys }
validates :address, length: { maximum: 255 }
validates :email, length: { maximum: 255 }
validates :exam_score, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
validates :expiry_date, presence: true
validates :fathers_name, length: { maximum: 255 }
validates :first_name, presence: true, length: { maximum: 255 }
validates :gender, inclusion: { in: genders.keys }
Expand Down Expand Up @@ -65,8 +69,13 @@ class ProspectiveStudent < ApplicationRecord
validates :registered, inclusion: { in: [true, false] }
validates :registration_district, length: { maximum: 255 }
validates :state_of_education, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :system_register_type, inclusion: { in: system_register_types.keys }
validates :top_student, inclusion: { in: [true, false] }

# scopes
scope :archived, -> { where(archived: true) }
scope :not_archived, -> { where(archived: false) }

# custom methods
def can_permanently_register?
military_status && obs_status && meb_status
Expand Down
2 changes: 1 addition & 1 deletion app/views/account/addresses/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-light">
<%= link_to_back user_path(@user) %>
<%= link_to_new(t('.new_address'), new_user_address_path(@user)) unless @user.addresses.informal.present? %>
<%= link_to_new(t('.new_address'), new_user_address_path(@user)) if @user.addresses.informal.blank? %>
<%= link_to (@addresses.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis')), save_from_mernis_user_addresses_path, class: 'btn btn-outline-primary btn-sm' %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/account/identities/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<%= f.input :place_of_birth, collection: City.all, value_method: :name %>
</div>
<div class='form-group col-sm-6'>
<%= f.input :date_of_birth, start_year: Date.today.year - 90, end_year: Date.today.year - 10 %>
<%= f.input :date_of_birth, start_year: Time.zone.today.year - 90, end_year: Time.zone.today.year - 10 %>
</div>
<div class='form-group col-sm-12'>
<%= f.input :registered_to %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/account/identities/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-light">
<%= link_to_back user_path(@user) %>
<%= link_to_new(t('.new_identity'), new_user_identity_path(@user)) unless @user.identities.informal.present? %>
<%= link_to_new(t('.new_identity'), new_user_identity_path(@user)) if @user.identities.informal.blank? %>
<%= link_to (@identities.formal.present? ? t('.update_from_mernis') : t('.create_from_mernis')), save_from_mernis_user_identities_path, class: 'btn btn-outline-primary btn-sm' %>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tbody>
<tr>
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top; background-color: #3498db; border-radius: 5px; text-align: center;">
<%= link_to t('.reset_password'), edit_password_url(@resource, reset_password_token: @token), target: '_blank', style: 'display: inline-block; color: #ffffff; background-color: #3498db; border: solid 1px #3498db; border-radius: 5px; box-sizing: border-box; cursor: pointer; text-decoration: none; font-size: 14px; font-weight: bold; margin: 0; padding: 12px 25px; text-transform: capitalize; border-color: #3498db;' %>
<%= link_to t('.reset_password'), edit_password_url(@resource, reset_password_token: @token), target: '_blank', style: 'display: inline-block; color: #ffffff; background-color: #3498db; border: solid 1px #3498db; border-radius: 5px; box-sizing: border-box; cursor: pointer; text-decoration: none; font-size: 14px; font-weight: bold; margin: 0; padding: 12px 25px; text-transform: capitalize; border-color: #3498db;', rel: 'noopener' %>
</td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit 55812ee

Please sign in to comment.