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 @@
<%= 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' %>
diff --git a/app/views/account/identities/_form.html.erb b/app/views/account/identities/_form.html.erb index 7dc361126..b4c05d00d 100644 --- a/app/views/account/identities/_form.html.erb +++ b/app/views/account/identities/_form.html.erb @@ -34,7 +34,7 @@ <%= f.input :place_of_birth, collection: City.all, value_method: :name %>
- <%= 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 %>
<%= f.input :registered_to %> diff --git a/app/views/account/identities/index.html.erb b/app/views/account/identities/index.html.erb index 00f292678..00a81ef37 100644 --- a/app/views/account/identities/index.html.erb +++ b/app/views/account/identities/index.html.erb @@ -1,6 +1,6 @@
<%= 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' %>
diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index a0d0f46ab..c0778fdc3 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -10,7 +10,7 @@ - <%= 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' %> diff --git a/app/views/first_registration/prospective_students/_form.html.erb b/app/views/first_registration/prospective_students/_form.html.erb new file mode 100644 index 000000000..3e6c5d310 --- /dev/null +++ b/app/views/first_registration/prospective_students/_form.html.erb @@ -0,0 +1,217 @@ +
+
+
+
+ <%= fa_icon 'users' %> + <%= form_title %> +
+
+ <%= simple_form_for([:first_registration, prospective_student]) do |f| %> +
+
+
+ <%= f.error_notification %> +
+ +
+
+
+ <%= t('.personel_informations') %> +
+
+
+
+ <%= f.input :id_number, required: true %> +
+
+ <%= f.input :first_name, required: true %> +
+
+ <%= f.input :last_name, required: true %> +
+
+ <%= f.input :gender, collection: enum_options_for_select(f.object.class, :gender), required: true %> +
+
+ <%= f.input :fathers_name %> +
+
+ <%= f.input :mothers_name %> +
+
+ <%= f.input :date_of_birth, as: :date_time_picker %> +
+
+ <%= f.input :place_of_birth %> +
+
+ <%= f.input :nationality, collection: enum_options_for_select(f.object.class, :nationality) %> +
+
+
+
+
+
+
+
+ <%= t('.address_and_contact_informations') %> +
+
+
+
+ <%= f.input :mobile_phone, required: true %> +
+
+ <%= f.input :email, required: true %> +
+
+ <%= f.input :registration_city %> +
+
+ <%= f.input :registration_district %> +
+
+ <%= f.input :home_phone %> +
+
+ <%= f.input :address, as: :text %> +
+
+
+
+
+
+
+
+ <%= t('.high_school_informations') %> +
+
+
+
+ <%= f.input :high_school_code %> +
+
+ <%= f.input :high_school_branch %> +
+
+ <%= f.input :high_school_graduation_year %> +
+
+ <%= f.association :high_school_type, collection: HighSchoolType.order(:name) %> +
+
+ <%= f.input :meb_status_date, as: :date_time_picker %> +
+
+ <%= f.input :top_student %> +
+
+ <%= f.input :meb_status %> +
+
+
+
+
+
+
+
+ <%= t('.exam_informations') %> +
+
+
+
+ <%= f.input :placement_type, collection: enum_options_for_select(f.object.class, :placement_type) %> +
+
+ <%= f.input :exam_score %> +
+
+ <%= f.input :placement_score %> +
+
+ <%= f.input :placement_rank %> +
+
+ <%= f.input :preference_order %> +
+
+ <%= f.input :placement_score_type %> +
+
+ <%= f.input :additional_score, collection: enum_options_for_select(f.object.class, :additional_score) %> +
+
+
+
+
+
+
+
+ <%= t('.other_informations') %> +
+
+
+
+ <%= f.association :unit, collection: Unit.programs %> +
+
+ <%= f.association :student_entrance_type %> +
+
+ <%= f.association :academic_term, + label_method: lambda { |academic_term| full_name(academic_term) } %> +
+
+ <%= f.input :expiry_date, as: :date_time_picker %> +
+
+ <%= f.input :obs_status_date, as: :date_time_picker %> +
+
+ <%= f.input :military_status_date, as: :date_time_picker %> +
+
+ <%= f.association :language %> +
+
+ <%= f.input :obs_registered_program %> +
+
+ <%= f.association :student_disability_type %> +
+
+ <%= f.input :military_status %> + <%= f.input :obs_status %> +
+
+
+
+
+
+ <%= f.button :submit, t('save'), class: 'btn btn-outline-success btn-sm' %> + <%= link_to_back(:back) %> +
+
+
+ <% end %> +
+
+
+
+ + diff --git a/app/views/first_registration/prospective_students/_search.html.erb b/app/views/first_registration/prospective_students/_search.html.erb index 6357bc0cd..429202c3d 100644 --- a/app/views/first_registration/prospective_students/_search.html.erb +++ b/app/views/first_registration/prospective_students/_search.html.erb @@ -68,7 +68,7 @@ class: 'form-control') %>
-
+
<%= label_tag :student_entrance_type_id, t('.student_entrance_type') %> <%= select_tag(:student_entrance_type_id, @@ -77,7 +77,7 @@ class: 'form-control') %>
-
+
<%= label_tag :root_unit_id, t('.root_unit') %> <%= select_tag(:root_unit_id, @@ -87,7 +87,7 @@ style: 'width: 100%') %>
-
+
<%= label_tag :unit_id, t('.unit') %> <%= select_tag(:unit_id, @@ -98,6 +98,33 @@ class: 'form-control', style: 'width: 100%') %>
+
+
+ <%= label_tag :academic_term_id, t('.academic_term') %> + <%= select_tag(:academic_term_id, + options_from_collection_for_select(AcademicTerm.order(year: :desc), :id, lambda { |term| full_name(term) }), + include_blank: true, + class: 'form-control') %> +
+
+
+
+ <%= label_tag :system_register_type, t('.system_register_type') %> + <%= select_tag(:system_register_type, + options_for_select(enum_options_for_select(ProspectiveStudent, :system_register_type), params[:system_register_type]), + include_blank: true, + class: 'form-control') %> +
+
+
+
+ <%= label_tag :archived, t('.archived') %> + <%= select_tag(:archived, + options_for_select([[t('.archived'), true], [t('.not_archived'), false]], params[:archived]), + include_blank: true, + class: 'form-control') %> +
+
@@ -112,9 +139,14 @@