diff --git a/.rubocop.yml b/.rubocop.yml index 8a46e5a9d..c94266d0c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +Rails: + Enabled: true Style/AsciiComments: Enabled: false Style/Lambda: @@ -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/**/* diff --git a/Gemfile.lock b/Gemfile.lock index 63997712d..389d5207b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/app/controllers/concerns/reference_resource.rb b/app/controllers/concerns/reference_resource.rb index cc98b4764..4cf4da08b 100644 --- a/app/controllers/concerns/reference_resource.rb +++ b/app/controllers/concerns/reference_resource.rb @@ -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] @@ -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 diff --git a/app/controllers/first_registration/prospective_students_controller.rb b/app/controllers/first_registration/prospective_students_controller.rb index 042272397..d1b772e46 100644 --- a/app/controllers/first_registration/prospective_students_controller.rb +++ b/app/controllers/first_registration/prospective_students_controller.rb @@ -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 @@ -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')) @@ -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 diff --git a/app/decorators/prospective_student_decorator.rb b/app/decorators/prospective_student_decorator.rb index 6ad8ef56d..d404cb0c6 100644 --- a/app/decorators/prospective_student_decorator.rb +++ b/app/decorators/prospective_student_decorator.rb @@ -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 diff --git a/app/jobs/osym/import_prospective_students_job.rb b/app/jobs/osym/import_prospective_students_job.rb index ad32eec4c..4bef8f0ab 100644 --- a/app/jobs/osym/import_prospective_students_job.rb +++ b/app/jobs/osym/import_prospective_students_job.rb @@ -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, @@ -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 diff --git a/app/models/academic_term.rb b/app/models/academic_term.rb index 84cac2806..d828cd3dd 100644 --- a/app/models/academic_term.rb +++ b/app/models/academic_term.rb @@ -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 diff --git a/app/models/prospective_student.rb b/app/models/prospective_student.rb index 9d2c4e00d..5e8ad45ad 100644 --- a/app/models/prospective_student.rb +++ b/app/models/prospective_student.rb @@ -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 @@ -21,8 +22,10 @@ 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 @@ -30,10 +33,11 @@ class ProspectiveStudent < ApplicationRecord 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 } @@ -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 diff --git a/app/views/account/addresses/index.html.erb b/app/views/account/addresses/index.html.erb index eb5cfcf2a..78822c741 100644 --- a/app/views/account/addresses/index.html.erb +++ b/app/views/account/addresses/index.html.erb @@ -1,6 +1,6 @@