diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6402a3da7..69a0d0e8e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -12,7 +12,7 @@ **Sistem/Ops etkileri:** -[//]: # (Bu PR merge edildiğinde sunucular üzerinde bir değişiklik - paket kurulması, buildpack eklenmesi vb. - yapılması gerekecekmi, açıklayın.) +[//]: # (Bu PR merge edildiğinde sunucular üzerinde bir değişiklik - paket kurulması, buildpack eklenmesi vb. - yapılması gerekecek mi, açıklayın.) **Kontrol listesi:** diff --git a/.travis.yml b/.travis.yml index 35c0835f2..a5f5b609d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,3 +58,6 @@ notifications: on_failure: change rooms: - secure: ljbXmcdLA/wv+j3+RCE0qF/mZd/3PbHI0VOSBkeyJDXWcHHMduIyZlodzliuXL/8mfLbmcJ8MZT5tV9l0OGSgiFI/Ngz1fadsf+0Pim4MtREkp4yKRzfDbQqj8iQwzAAcIAxbIQhenVZtaadwBAM8Jawcjs0m2+iWXaiREU1IlRaK1NzGtkDx8gy5PnVgJhtWmhV7/l6a0Sg94shr53bchkuGwH/ugqgq9L+ec1gGKVpSOHhS0W5WjojMU+3K5/HCP/r9V2J2jYUjtzDSbEDFd18rH0qJjNq1hoaVeaW1uJzidSH7f7B6xXxJfUt4e2CiY+2CkR5LUbFx5V+6fNscEAA9u+zGh6Rn9rxciWkFfzKck6Eomoq5G+d+q/ItVagAMSIUELYCOup2+H/KtRNFTBWBqwECsvXZn7WwaZOdMXDfiTnI9eSWxJqaiwFMtC1A+bnKM7DX2qoZoGCNJAzzQ93EuXdxA1w1oYVs7lfh70qLx5OraXtcTUtfrv4tzms35S9JNNnEQyWN7neuPCS0Yh4QIFf4NX7aaYbwFD66uS25Iq2ochJ4oicFd8s+DxnaXc925GYXFVHk7wZWK/mFlGnZTuTbk4ElByqzRUN2sI5r7xYijv9cBcUM/1RqzXI3B/91Ft/kyCaYDrg3W1j79zLo+G5uIHU2/F1AQBIYlI= + template: + - "Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository_slug}@%{branch}" + - "by %{author} %{result} in %{elapsed_time}" diff --git a/Gemfile.lock b/Gemfile.lock index e1f88da14..a879e7942 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 16e235126ef0187a93b81ee959a8127097e2f394 + revision: 907280ddfd78c53e2eb5af6f12512dc38df38bd8 specs: actioncable (6.0.0.beta1) actionpack (= 6.0.0.beta1) @@ -63,7 +63,7 @@ GIT i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 1.0) + zeitwerk (~> 1.2) rails (6.0.0.beta1) actioncable (= 6.0.0.beta1) actionmailbox (= 6.0.0.beta1) @@ -107,7 +107,7 @@ GIT GIT remote: https://github.com/rollbar/rollbar-gem.git - revision: e3a35525d1b14fab587e317548ed4f5c1052240d + revision: ada82d619e848ad6b64a33acd10b03730b4c3d41 specs: rollbar (2.18.2) multi_json @@ -142,7 +142,7 @@ GEM io-like (~> 0.3.0) ast (2.4.0) aws-eventstream (1.0.1) - aws-partitions (1.138.0) + aws-partitions (1.139.0) aws-sdk-core (3.46.1) aws-eventstream (~> 1.0) aws-partitions (~> 1.0) @@ -173,7 +173,7 @@ GEM bundler-audit (0.6.1) bundler (>= 1.2.0, < 3) thor (~> 0.18) - byebug (10.0.2) + byebug (11.0.0) capybara (3.13.2) addressable mini_mime (>= 0.1.3) @@ -411,7 +411,7 @@ GEM wicked_pdf (1.1.0) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (1.1.0) + zeitwerk (1.2.0) PLATFORMS ruby diff --git a/Vagrantfile b/Vagrantfile index 5947e1db6..413ac07d3 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -37,6 +37,14 @@ Vagrant.configure('2') do |config| # rubocop:disable Metrics/BlockLength end end + config.vm.define 'ldap', autostart: false do |ldap| + ldap.vm.box = 'omu/debian-stable-server' + + ldap.vm.network :forwarded_port, guest: 389, host: 1389 + + ldap.vm.provision 'shell', path: 'lib/scripts/ldap.sh' + end + config.vm.define 'paas', autostart: false do |paas| paas.vm.box = 'omu/debian-stable-paas' @@ -47,16 +55,4 @@ Vagrant.configure('2') do |config| # rubocop:disable Metrics/BlockLength trigger.run = { inline: 'bash lib/scripts/paas.sh' } end end - - config.vm.define 'ldap', autostart: true do |ldap| - ldap.vm.box = 'omu/debian-stable-server' - - ldap.vm.network :forwarded_port, guest: 389, host: 1389 - - ldap.vm.provider :lxc do |lxc| - lxc.customize 'cgroup.memory.limit_in_bytes', '2048M' - end - - ldap.vm.provision 'shell', path: 'lib/scripts/ldap.sh' - end end diff --git a/app/controllers/account/addresses_controller.rb b/app/controllers/account/addresses_controller.rb index 519282f80..fc6aef710 100644 --- a/app/controllers/account/addresses_controller.rb +++ b/app/controllers/account/addresses_controller.rb @@ -2,7 +2,7 @@ module Account class AddressesController < ApplicationController - include LastUpdateFromMernis + include UpdateableFromMernis before_action :set_user before_action :set_address, only: %i[edit update destroy] @@ -58,7 +58,7 @@ def redirect_with(message) end def address_params - params.require(:address).permit(:phone_number, :full_address, :district_id) + params.require(:address).permit(:country, :phone_number, :full_address, :district_id) end end end diff --git a/app/controllers/user/confirmations_controller.rb b/app/controllers/account/confirmations_controller.rb similarity index 97% rename from app/controllers/user/confirmations_controller.rb rename to app/controllers/account/confirmations_controller.rb index 01441f1fe..7bec25ff9 100644 --- a/app/controllers/user/confirmations_controller.rb +++ b/app/controllers/account/confirmations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class ConfirmationsController < Devise::ConfirmationsController # GET /resource/confirmation/new # def new diff --git a/app/controllers/account/identities_controller.rb b/app/controllers/account/identities_controller.rb index 4cc011356..ff2cd2658 100644 --- a/app/controllers/account/identities_controller.rb +++ b/app/controllers/account/identities_controller.rb @@ -2,7 +2,7 @@ module Account class IdentitiesController < ApplicationController - include LastUpdateFromMernis + include UpdateableFromMernis before_action :set_user before_action :set_identity, only: %i[edit update destroy] diff --git a/app/controllers/user/omniauth_callbacks_controller.rb b/app/controllers/account/omniauth_callbacks_controller.rb similarity index 97% rename from app/controllers/user/omniauth_callbacks_controller.rb rename to app/controllers/account/omniauth_callbacks_controller.rb index 94ae33f34..b6ba88702 100644 --- a/app/controllers/user/omniauth_callbacks_controller.rb +++ b/app/controllers/account/omniauth_callbacks_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class OmniauthCallbacksController < Devise::OmniauthCallbacksController # You should configure your model like this: # devise :omniauthable, omniauth_providers: [:twitter] diff --git a/app/controllers/user/passwords_controller.rb b/app/controllers/account/passwords_controller.rb similarity index 97% rename from app/controllers/user/passwords_controller.rb rename to app/controllers/account/passwords_controller.rb index d0b526b3b..f2c1d9e71 100644 --- a/app/controllers/user/passwords_controller.rb +++ b/app/controllers/account/passwords_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class PasswordsController < Devise::PasswordsController layout 'guest' diff --git a/app/controllers/account/profile_controller.rb b/app/controllers/account/profile_controller.rb deleted file mode 100644 index e4b09e739..000000000 --- a/app/controllers/account/profile_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Account - class ProfileController < ApplicationController - before_action :purge_avatar, only: :update - - def edit; end - - def update - if current_user.update_without_password(profile_params) - redirect_to user_profile_path(current_user), notice: t('.success') - else - render(:edit) - end - end - - private - - def purge_avatar - current_user.avatar.purge - end - - def profile_params - params.require(:user).permit( - :avatar, :phone_number, :extension_number, :website, :twitter, :linkedin, :skype, :orcid, :public_photo, - :public_studies - ) - end - end -end diff --git a/app/controllers/account/profile_settings_controller.rb b/app/controllers/account/profile_settings_controller.rb new file mode 100644 index 000000000..3781b6ff6 --- /dev/null +++ b/app/controllers/account/profile_settings_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Account + class ProfileSettingsController < ApplicationController + # before_action :purge_avatar, only: :update + + def edit; end + + def update + if current_user.update_without_password(profile_params) + redirect_to profile_path, notice: t('.success') + else + render(:edit) + end + end + + private + + # def purge_avatar + # current_user.avatar.purge + # end + + def profile_params + params.require(:user).permit( + :avatar, :country, :phone_number, :extension_number, :website, :twitter, :linkedin, :skype, :orcid, + :public_photo, :public_studies + ) + end + end +end diff --git a/app/controllers/user/registrations_controller.rb b/app/controllers/account/registrations_controller.rb similarity index 98% rename from app/controllers/user/registrations_controller.rb rename to app/controllers/account/registrations_controller.rb index 245d617d0..5783508ea 100644 --- a/app/controllers/user/registrations_controller.rb +++ b/app/controllers/account/registrations_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class RegistrationsController < Devise::RegistrationsController layout 'guest', except: %i[edit update] @@ -65,6 +65,8 @@ def update # super(resource) # end + private + def update_password_change_time current_user.update!(password_changed_at: Time.zone.now) end diff --git a/app/controllers/user/sessions_controller.rb b/app/controllers/account/sessions_controller.rb similarity index 84% rename from app/controllers/user/sessions_controller.rb rename to app/controllers/account/sessions_controller.rb index e8270039d..2345fce48 100644 --- a/app/controllers/user/sessions_controller.rb +++ b/app/controllers/account/sessions_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class SessionsController < Devise::SessionsController layout 'guest' # before_action :configure_sign_in_params, only: [:create] @@ -20,7 +20,11 @@ class SessionsController < Devise::SessionsController # super # end - # protected + protected + + def after_sign_out_path_for(_resource_or_scope) + login_path + end # If you have extra params to permit, append them to the sanitizer. # def configure_sign_in_params diff --git a/app/controllers/user/unlocks_controller.rb b/app/controllers/account/unlocks_controller.rb similarity index 97% rename from app/controllers/user/unlocks_controller.rb rename to app/controllers/account/unlocks_controller.rb index 93610b8c0..6f46d0325 100644 --- a/app/controllers/user/unlocks_controller.rb +++ b/app/controllers/account/unlocks_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class User +module Account class UnlocksController < Devise::UnlocksController # GET /resource/unlock/new # def new diff --git a/app/controllers/admin/administrative_functions_controller.rb b/app/controllers/admin/administrative_functions_controller.rb new file mode 100644 index 000000000..80344afeb --- /dev/null +++ b/app/controllers/admin/administrative_functions_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Admin + class AdministrativeFunctionsController < ApplicationController + include ReferenceResource + + private + + def secure_params + params.require(:administrative_function).permit(:name, :code) + end + end +end diff --git a/app/controllers/admin/cities_controller.rb b/app/controllers/admin/cities_controller.rb index 1c678f794..f3f039632 100644 --- a/app/controllers/admin/cities_controller.rb +++ b/app/controllers/admin/cities_controller.rb @@ -2,7 +2,7 @@ module Admin class CitiesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_country before_action :set_city, only: %i[show edit update destroy] diff --git a/app/controllers/admin/countries_controller.rb b/app/controllers/admin/countries_controller.rb index 49fdc8fb2..16eb980ce 100644 --- a/app/controllers/admin/countries_controller.rb +++ b/app/controllers/admin/countries_controller.rb @@ -2,7 +2,7 @@ module Admin class CountriesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_country, only: %i[show edit update destroy] diff --git a/app/controllers/calendar_management/calendar_event_types_controller.rb b/app/controllers/calendar_management/calendar_event_types_controller.rb index 199468ab3..46166c3ac 100644 --- a/app/controllers/calendar_management/calendar_event_types_controller.rb +++ b/app/controllers/calendar_management/calendar_event_types_controller.rb @@ -2,7 +2,7 @@ module CalendarManagement class CalendarEventTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_calendar_event_type, only: %i[edit update destroy] diff --git a/app/controllers/calendar_management/calendars_controller.rb b/app/controllers/calendar_management/calendars_controller.rb index e4c745957..777884551 100644 --- a/app/controllers/calendar_management/calendars_controller.rb +++ b/app/controllers/calendar_management/calendars_controller.rb @@ -2,7 +2,7 @@ module CalendarManagement class CalendarsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_calendar, only: %i[show edit update destroy] diff --git a/app/controllers/committee/agenda_types_controller.rb b/app/controllers/committee/agenda_types_controller.rb index 0fbdaa779..ef5304d83 100644 --- a/app/controllers/committee/agenda_types_controller.rb +++ b/app/controllers/committee/agenda_types_controller.rb @@ -2,7 +2,7 @@ module Committee class AgendaTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_agenda_type, only: %i[edit update destroy] diff --git a/app/controllers/committee/agendas_controller.rb b/app/controllers/committee/agendas_controller.rb index f948015d9..ec70cbf27 100644 --- a/app/controllers/committee/agendas_controller.rb +++ b/app/controllers/committee/agendas_controller.rb @@ -2,7 +2,7 @@ module Committee class AgendasController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_committee before_action :set_agenda, only: %i[edit update destroy] diff --git a/app/controllers/committee/dashboard_controller.rb b/app/controllers/committee/dashboard_controller.rb index 34dcb6137..99108e29f 100644 --- a/app/controllers/committee/dashboard_controller.rb +++ b/app/controllers/committee/dashboard_controller.rb @@ -2,7 +2,7 @@ module Committee class DashboardController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule def index @committees = pagy_by_search( diff --git a/app/controllers/concerns/reference_resource.rb b/app/controllers/concerns/reference_resource.rb index 5a82a7ecb..cc98b4764 100644 --- a/app/controllers/concerns/reference_resource.rb +++ b/app/controllers/concerns/reference_resource.rb @@ -2,7 +2,7 @@ module ReferenceResource extend ActiveSupport::Concern - include PagyBackendWithHelpers + include SearchableModule # rubocop:disable Metrics/BlockLength # rubocop:disable Rails/LexicallyScopedActionFilter diff --git a/app/controllers/concerns/pagy_backend_with_helpers.rb b/app/controllers/concerns/searchable_module.rb similarity index 88% rename from app/controllers/concerns/pagy_backend_with_helpers.rb rename to app/controllers/concerns/searchable_module.rb index 6607bb398..9ffecc8ff 100644 --- a/app/controllers/concerns/pagy_backend_with_helpers.rb +++ b/app/controllers/concerns/searchable_module.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module PagyBackendWithHelpers +module SearchableModule extend ActiveSupport::Concern include Pagy::Backend diff --git a/app/controllers/concerns/last_update_from_mernis.rb b/app/controllers/concerns/updateable_from_mernis.rb similarity index 91% rename from app/controllers/concerns/last_update_from_mernis.rb rename to app/controllers/concerns/updateable_from_mernis.rb index 54c53d70b..726abcc8e 100644 --- a/app/controllers/concerns/last_update_from_mernis.rb +++ b/app/controllers/concerns/updateable_from_mernis.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module LastUpdateFromMernis +module UpdateableFromMernis extend ActiveSupport::Concern def elapsed_time(resource) diff --git a/app/controllers/course_management/available_courses_controller.rb b/app/controllers/course_management/available_courses_controller.rb index 974a1251d..dcc565eff 100644 --- a/app/controllers/course_management/available_courses_controller.rb +++ b/app/controllers/course_management/available_courses_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class AvailableCoursesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_available_course, only: %i[show edit update destroy] diff --git a/app/controllers/course_management/course_group_types_controller.rb b/app/controllers/course_management/course_group_types_controller.rb index ca8176819..cd0c3bb17 100644 --- a/app/controllers/course_management/course_group_types_controller.rb +++ b/app/controllers/course_management/course_group_types_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CourseGroupTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course_group_type, only: %i[edit update destroy] diff --git a/app/controllers/course_management/course_types_controller.rb b/app/controllers/course_management/course_types_controller.rb index feec4ba63..eb78a1b8e 100644 --- a/app/controllers/course_management/course_types_controller.rb +++ b/app/controllers/course_management/course_types_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CourseTypesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course_type, only: %i[edit update destroy] diff --git a/app/controllers/course_management/courses_controller.rb b/app/controllers/course_management/courses_controller.rb index 6b7119353..839084d02 100644 --- a/app/controllers/course_management/courses_controller.rb +++ b/app/controllers/course_management/courses_controller.rb @@ -2,7 +2,7 @@ module CourseManagement class CoursesController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_course, only: %i[show edit update destroy] diff --git a/app/controllers/course_management/curriculums_controller.rb b/app/controllers/course_management/curriculums_controller.rb index 4553a6c94..fa6042c36 100644 --- a/app/controllers/course_management/curriculums_controller.rb +++ b/app/controllers/course_management/curriculums_controller.rb @@ -2,7 +2,8 @@ module CourseManagement class CurriculumsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule + before_action :set_curriculum, only: %i[show edit update destroy openable_courses] def index diff --git a/app/controllers/first_registration/prospective_students_controller.rb b/app/controllers/first_registration/prospective_students_controller.rb index d6b3aa2d4..9cb0b920d 100644 --- a/app/controllers/first_registration/prospective_students_controller.rb +++ b/app/controllers/first_registration/prospective_students_controller.rb @@ -2,7 +2,7 @@ module FirstRegistration class ProspectiveStudentsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_prospective_student, only: %i[show register] before_action :can_register?, only: :register diff --git a/app/controllers/first_registration/registration_documents_controller.rb b/app/controllers/first_registration/registration_documents_controller.rb index 2dd659032..18ea656b8 100644 --- a/app/controllers/first_registration/registration_documents_controller.rb +++ b/app/controllers/first_registration/registration_documents_controller.rb @@ -2,7 +2,7 @@ module FirstRegistration class RegistrationDocumentsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_registration_document, only: %i[edit update destroy] diff --git a/app/controllers/public_profile_controller.rb b/app/controllers/public_profile_controller.rb index 356e9ecf7..b7336e931 100644 --- a/app/controllers/public_profile_controller.rb +++ b/app/controllers/public_profile_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class PublicProfileController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule skip_before_action :authenticate_user! before_action :set_user, only: %i[show vcard] diff --git a/app/controllers/references/academic_terms_controller.rb b/app/controllers/references/academic_terms_controller.rb index be7325f1f..7d6116247 100644 --- a/app/controllers/references/academic_terms_controller.rb +++ b/app/controllers/references/academic_terms_controller.rb @@ -2,7 +2,7 @@ module References class AcademicTermsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule before_action :set_academic_term, only: %i[edit update destroy] diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index cce3d70aa..7e58b8d64 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class UnitsController < ApplicationController - include PagyBackendWithHelpers + include SearchableModule + before_action :set_unit, only: %i[edit update destroy show courses programs curriculums employees] def index diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 67763ccb9..c907a7d90 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true class UsersController < ApplicationController - include PagyBackendWithHelpers - include LastUpdateFromMernis + include SearchableModule + include UpdateableFromMernis - before_action :set_user, except: %i[index new create] + before_action :set_user, except: :index 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 @@ -21,15 +21,6 @@ def show @positions = @user.positions.includes(:administrative_function, :duty) end - def new - @user = User.new - end - - def create - @user = User.new(user_params) - @user.save ? redirect_with('.success') : render(:new) - end - def edit; end def update diff --git a/app/lib/nokul/version.rb b/app/lib/nokul/version.rb index e7839ee68..0abf7c9b7 100644 --- a/app/lib/nokul/version.rb +++ b/app/lib/nokul/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Nokul - VERSION = '0.5.3' + VERSION = '0.5.4' end diff --git a/app/models/academic_term.rb b/app/models/academic_term.rb index f86197d04..84cac2806 100644 --- a/app/models/academic_term.rb +++ b/app/models/academic_term.rb @@ -4,7 +4,7 @@ class AcademicTerm < ApplicationRecord include EnumForTerm # callbacks - after_save -> { AcademicTerm.where.not(id: id).update(active: false) }, if: :active? + after_save :deactivate_academic_terms # relations has_many :calendars, dependent: :nullify @@ -19,4 +19,10 @@ class AcademicTerm < ApplicationRecord # scopes scope :active, -> { where(active: true) } + + private + + def deactivate_academic_terms + AcademicTerm.where.not(id: id).update(active: false) if active? + end end diff --git a/app/models/address.rb b/app/models/address.rb index 778ca8bb3..66c3edba6 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -3,6 +3,12 @@ class Address < ApplicationRecord self.inheritance_column = nil + # virtual attributes + attr_accessor :country + + # callbacks + before_save :capitalize_attributes + # enums enum type: { formal: 1, informal: 2 } @@ -12,10 +18,16 @@ class Address < ApplicationRecord # validations validates :full_address, presence: true, length: { maximum: 255 } - validates :phone_number, length: { maximum: 255 } + validates :phone_number, length: { maximum: 255 }, + allow_nil: true, + allow_blank: true, + telephone_number: { country: proc { |record| record.country }, types: [:mobile] } validates :type, uniqueness: { scope: :user }, inclusion: { in: types.keys } validates_with AddressAndIdentityValidator, on: :create - # callbacks - before_save { self.full_address = full_address.capitalize_turkish } + private + + def capitalize_attributes + self.full_address = full_address.capitalize_turkish + end end diff --git a/app/models/administrative_function.rb b/app/models/administrative_function.rb index aa964424a..89a8268e9 100644 --- a/app/models/administrative_function.rb +++ b/app/models/administrative_function.rb @@ -1,14 +1,11 @@ # frozen_string_literal: true class AdministrativeFunction < ApplicationRecord + include ReferenceCallbacks + include ReferenceSearch + include ReferenceValidations + # relations has_many :positions, dependent: :destroy has_many :duties, through: :positions - - # validations - validates :code, uniqueness: true, numericality: { only_integer: true, greater_than: 0 } - validates :name, presence: true, uniqueness: true, length: { maximum: 255 } - - # callbacks - before_validation { self.name = name.capitalize_turkish if name } end diff --git a/app/models/agenda_type.rb b/app/models/agenda_type.rb index 1f5e5ac7e..d960553a1 100644 --- a/app/models/agenda_type.rb +++ b/app/models/agenda_type.rb @@ -5,12 +5,18 @@ class AgendaType < ApplicationRecord include PgSearch pg_search_scope(:search, against: :name, using: { tsearch: { prefix: true } }) + # callbacks + before_save :capitalize_attributes + # relations has_many :agendas, dependent: :nullify # validations validates :name, presence: true, length: { maximum: 255 } - # callbacks - before_save { self.name = name.capitalize_turkish } + private + + def capitalize_attributes + self.name = name.capitalize_turkish + end end diff --git a/app/models/assessment_method.rb b/app/models/assessment_method.rb index 36e40365c..3f6793e37 100644 --- a/app/models/assessment_method.rb +++ b/app/models/assessment_method.rb @@ -3,7 +3,9 @@ class AssessmentMethod < ApplicationRecord # search include ReferenceSearch - include ReferenceCallbacks + + # callbacks + before_validation :capitalize_attributes # relations has_many :course_assessment_methods, dependent: :destroy @@ -12,4 +14,10 @@ class AssessmentMethod < ApplicationRecord # validations validates :name, presence: true, uniqueness: true, length: { maximum: 255 } + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/available_course.rb b/app/models/available_course.rb index 609dabdb9..daca6b956 100644 --- a/app/models/available_course.rb +++ b/app/models/available_course.rb @@ -14,6 +14,9 @@ class AvailableCourse < ApplicationRecord # dynamic_search search_keys :unit_id, :curriculum_id, :academic_term_id + # validations + before_validation :assign_academic_term, on: :create + # relations belongs_to :academic_term belongs_to :coordinator, class_name: 'Employee' @@ -27,13 +30,14 @@ class AvailableCourse < ApplicationRecord validates :assessments_approved, inclusion: { in: [true, false] } validates :course, uniqueness: { scope: %i[academic_term curriculum] } - # callbacks - before_validation(on: :create) do - self.academic_term = AcademicTerm.active.last - end - # delegates delegate :code, :name, :theoric, :practice, :laboratory, :credit, :program_type, to: :course delegate :name, to: :curriculum, prefix: true delegate :name, to: :unit, prefix: true + + private + + def assign_academic_term + self.academic_term = AcademicTerm.active.last + end end diff --git a/app/models/city.rb b/app/models/city.rb index eaaef40d6..43dec1cb3 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class City < ApplicationRecord - # alpha_2_code field follows the ISO3166-2 standard - # search include PgSearch pg_search_scope( @@ -11,6 +9,9 @@ class City < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :country has_many :districts, dependent: :destroy @@ -22,7 +23,7 @@ class City < ApplicationRecord validates :name, presence: true, uniqueness: { scope: %i[country_id] }, length: { maximum: 255 } # callbacks - before_validation do + def capitalize_attributes self.alpha_2_code = alpha_2_code.upcase(:turkic) if alpha_2_code self.name = name.capitalize_turkish if name end diff --git a/app/models/committee_decision.rb b/app/models/committee_decision.rb index 70b93aa02..330262c6a 100644 --- a/app/models/committee_decision.rb +++ b/app/models/committee_decision.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true class CommitteeDecision < ApplicationRecord + # callbacks + before_validation :assign_year_and_decision_no, on: :create + after_create :change_status_to_decided + # relations belongs_to :meeting_agenda has_one :agenda, through: :meeting_agenda @@ -15,10 +19,6 @@ class CommitteeDecision < ApplicationRecord less_than_or_equal_to: 2050 } - # callbacks - before_validation :set_year_and_decision_no, on: :create - after_create { agenda.update(status: :decided) } - # delegates delegate :meeting_no, :meeting_date, :year, :unit, to: :meeting_agenda, prefix: true @@ -28,8 +28,12 @@ def count_of_decisions_by_year(year) private - def set_year_and_decision_no + def assign_year_and_decision_no self.year = meeting_agenda_year self.decision_no = "#{year}/#{count_of_decisions_by_year(year) + 1}" end + + def change_status_to_decided + agenda.update(status: :decided) + end end diff --git a/app/models/committee_meeting.rb b/app/models/committee_meeting.rb index 5c3c56b54..b9b6f228c 100644 --- a/app/models/committee_meeting.rb +++ b/app/models/committee_meeting.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class CommitteeMeeting < ApplicationRecord + # callbacks + before_validation :assign_year + # relations belongs_to :unit has_many :meeting_agendas, dependent: :destroy @@ -18,6 +21,9 @@ class CommitteeMeeting < ApplicationRecord less_than_or_equal_to: 2050 } - # callbacks - before_validation { self.year = meeting_date.try(:year) } + private + + def assign_year + self.year = meeting_date.try(:year) + end end diff --git a/app/models/concerns/reference_callbacks.rb b/app/models/concerns/reference_callbacks.rb index 8ad84bed0..5963a4bff 100644 --- a/app/models/concerns/reference_callbacks.rb +++ b/app/models/concerns/reference_callbacks.rb @@ -4,6 +4,12 @@ module ReferenceCallbacks extend ActiveSupport::Concern included do - before_validation { self.name = name.capitalize_turkish if name } + before_validation :capitalize_attributes + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end end diff --git a/app/models/concerns/reference_validations.rb b/app/models/concerns/reference_validations.rb index 5feab986a..7d861badc 100644 --- a/app/models/concerns/reference_validations.rb +++ b/app/models/concerns/reference_validations.rb @@ -4,7 +4,7 @@ module ReferenceValidations extend ActiveSupport::Concern included do - validates :name, presence: true, uniqueness: true, length: { maximum: 255 } validates :code, uniqueness: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :name, presence: true, uniqueness: true, length: { maximum: 255 } end end diff --git a/app/models/country.rb b/app/models/country.rb index bfb8fe6b1..7281bf6b5 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true class Country < ApplicationRecord - # alpha_2_code, alpha_3_code and and numeric code fields follow the ISO3166-1 standard. - # mernis_code obtained from YOKSIS - # search include PgSearch pg_search_scope( @@ -12,6 +9,9 @@ class Country < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations has_many :cities, dependent: :destroy has_many :districts, through: :cities @@ -28,8 +28,9 @@ class Country < ApplicationRecord numericality: { only_integer: true, greater_than: 0 } validates :yoksis_code, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 1 } - # callbacks - before_validation do + private + + def capitalize_attributes self.name = name.capitalize_turkish if name self.alpha_2_code = alpha_2_code.upcase(:turkic) if alpha_2_code self.alpha_3_code = alpha_3_code.upcase(:turkic) if alpha_3_code diff --git a/app/models/course.rb b/app/models/course.rb index b4cf2c881..9c16905db 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -14,6 +14,10 @@ class Course < ApplicationRecord # dynamic_search search_keys :course_type_id, :program_type, :language_id, :unit_id, :status + # callbacks + before_validation :capitalize_attributes + before_validation :assign_credit + # enumerations enum program_type: { associate: 0, undergraduate: 1, master: 2, doctoral: 3 } enum status: { passive: 0, active: 1 } @@ -33,17 +37,21 @@ class Course < ApplicationRecord validates :status, inclusion: { in: statuses.keys } validates :theoric, numericality: { greater_than_or_equal_to: 0 } - # callbacks - before_validation do - self.name = name.capitalize_turkish if name - self.credit = calculate_credit + def name_with_code + "#{code} - #{name}" end def calculate_credit theoric.to_f + ((practice.to_f + laboratory.to_f) / 2) end - def name_with_code - "#{code} - #{name}" + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end + + def assign_credit + self.credit = theoric.to_f + ((practice.to_f + laboratory.to_f) / 2) end end diff --git a/app/models/course_group.rb b/app/models/course_group.rb index 8a017ba24..0ca0d9ea1 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -14,6 +14,9 @@ class CourseGroup < ApplicationRecord # dynamic_search search_keys :unit_id, :course_group_type_id + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :course_group_type belongs_to :unit @@ -30,6 +33,9 @@ class CourseGroup < ApplicationRecord less_than_or_equal_to: 300 } - # callbacks - before_validation { self.name = name.capitalize_turkish if name } + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/course_group_type.rb b/app/models/course_group_type.rb index 56e5a85ac..3cb36462b 100644 --- a/app/models/course_group_type.rb +++ b/app/models/course_group_type.rb @@ -5,6 +5,9 @@ class CourseGroupType < ApplicationRecord include PgSearch pg_search_scope(:search, against: :name, using: { tsearch: { prefix: true } }) + # callbacks + before_validation :capitalize_attributes + # relations has_many :course_groups, dependent: :nullify @@ -12,5 +15,7 @@ class CourseGroupType < ApplicationRecord validates :name, presence: true, uniqueness: true, length: { maximum: 255 } # callbacks - before_validation { self.name = name.capitalize_turkish if name } + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/curriculum_course.rb b/app/models/curriculum_course.rb index 08d21dc0a..f8359ad7a 100644 --- a/app/models/curriculum_course.rb +++ b/app/models/curriculum_course.rb @@ -3,6 +3,9 @@ class CurriculumCourse < ApplicationRecord self.inheritance_column = :_type_disabled + # callbacks + before_validation :assign_type + # enums enum type: { compulsory: 0, elective: 1 } @@ -20,7 +23,7 @@ class CurriculumCourse < ApplicationRecord delegate :code, :credit, :course_type, :name, to: :course # callbacks - before_validation do + def assign_type self.type = curriculum_course_group.nil? ? :compulsory : :elective end end diff --git a/app/models/district.rb b/app/models/district.rb index f213b19c2..c2187fc3a 100644 --- a/app/models/district.rb +++ b/app/models/district.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class District < ApplicationRecord - # mernis_code field obtained from MERNIS - # search include PgSearch pg_search_scope( @@ -11,6 +9,9 @@ class District < ApplicationRecord using: { tsearch: { prefix: true } } ) + # callbacks + before_validation :capitalize_attributes + # relations belongs_to :city has_many :addresses, dependent: :nullify @@ -22,5 +23,7 @@ class District < ApplicationRecord validates :active, inclusion: { in: [true, false] } # callbacks - before_validation { self.name = name.capitalize_turkish if name } + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/evaluation_type.rb b/app/models/evaluation_type.rb index d5be9ac71..664994e91 100644 --- a/app/models/evaluation_type.rb +++ b/app/models/evaluation_type.rb @@ -3,7 +3,9 @@ class EvaluationType < ApplicationRecord # search include ReferenceSearch - include ReferenceCallbacks + + # callbacks + before_validation :capitalize_attributes # relations has_many :course_evaluation_types, dependent: :destroy @@ -11,4 +13,10 @@ class EvaluationType < ApplicationRecord # validations validates :name, presence: true, uniqueness: true, length: { maximum: 255 } + + private + + def capitalize_attributes + self.name = name.capitalize_turkish if name + end end diff --git a/app/models/high_school_type.rb b/app/models/high_school_type.rb index 2e5622e8b..3ba3b61b5 100644 --- a/app/models/high_school_type.rb +++ b/app/models/high_school_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class HighSchoolType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/identity.rb b/app/models/identity.rb index 713df6e71..37f2cc69d 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -3,6 +3,9 @@ class Identity < ApplicationRecord self.inheritance_column = nil + # callbacks + before_save :capitalize_attributes + # enums enum type: { formal: 1, informal: 2 } enum gender: { male: 1, female: 2, other: 3 } @@ -31,7 +34,8 @@ class Identity < ApplicationRecord scope :user_identity, -> { formal.find_by(student_id: nil) } # callbacks - before_save do + # rubocop:disable Metrics/AbcSize + def capitalize_attributes self.fathers_name = fathers_name.capitalize_turkish if fathers_name self.first_name = first_name.capitalize_turkish self.last_name = last_name.upcase(:turkic) @@ -39,4 +43,5 @@ class Identity < ApplicationRecord self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth self.type = 'informal' if type.blank? end + # rubocop:enable Metrics/AbcSize end diff --git a/app/models/language.rb b/app/models/language.rb index 00a3af52e..49941f215 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -4,6 +4,9 @@ class Language < ApplicationRecord # search include ReferenceSearch + # callbacks + before_validation :capitalize_attributes + # relations has_many :courses, dependent: :nullify has_many :prospective_students, dependent: :nullify @@ -12,8 +15,9 @@ class Language < ApplicationRecord validates :name, presence: true, uniqueness: true, length: { maximum: 255 } validates :iso, presence: true, uniqueness: true, length: { maximum: 255 } - # callbacks - before_validation do + private + + def capitalize_attributes self.name = name.capitalize_turkish if name self.iso = iso.upcase(:turkic) if iso end diff --git a/app/models/prospective_student.rb b/app/models/prospective_student.rb index f7a0850e7..9d2c4e00d 100644 --- a/app/models/prospective_student.rb +++ b/app/models/prospective_student.rb @@ -13,6 +13,9 @@ class ProspectiveStudent < ApplicationRecord search_keys :meb_status, :military_status, :obs_status, :unit_id, :student_entrance_type_id, :registered + # callbacks + before_create :capitalize_attributes + # enumerations enum additional_score: { handicapped: 1 } enum gender: { male: 1, female: 2 } @@ -64,17 +67,6 @@ class ProspectiveStudent < ApplicationRecord validates :state_of_education, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :top_student, inclusion: { in: [true, false] } - # callbacks - before_create do - self.first_name = first_name.capitalize_turkish - self.last_name = last_name.upcase(:turkic) - self.fathers_name = fathers_name.capitalize_turkish if fathers_name - self.mothers_name = mothers_name.capitalize_turkish if mothers_name - self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth - self.registration_city = registration_city.capitalize_turkish if registration_city - self.registration_district = registration_district.capitalize_turkish if registration_district - end - # custom methods def can_permanently_register? military_status && obs_status && meb_status @@ -83,4 +75,18 @@ def can_permanently_register? def can_temporarily_register? military_status end + + private + + # rubocop:disable Metrics/AbcSize + def capitalize_attributes + self.first_name = first_name.capitalize_turkish + self.last_name = last_name.upcase(:turkic) + self.fathers_name = fathers_name.capitalize_turkish if fathers_name + self.mothers_name = mothers_name.capitalize_turkish if mothers_name + self.place_of_birth = place_of_birth.capitalize_turkish if place_of_birth + self.registration_city = registration_city.capitalize_turkish if registration_city + self.registration_district = registration_district.capitalize_turkish if registration_district + end + # rubocop:enable Metrics/AbcSize end diff --git a/app/models/student.rb b/app/models/student.rb index 06f181e93..833f58d50 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -19,6 +19,8 @@ class Student < ApplicationRecord # background jobs after_create_commit :build_identity_information, if: proc { identity.nil? } + private + def build_identity_information Kps::IdentitySaveJob.perform_later(user, id) end diff --git a/app/models/student_disability_type.rb b/app/models/student_disability_type.rb index 050170fc4..e80cbe22c 100644 --- a/app/models/student_disability_type.rb +++ b/app/models/student_disability_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class StudentDisabilityType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/student_drop_out_type.rb b/app/models/student_drop_out_type.rb index 05a5ba875..a6e70b103 100644 --- a/app/models/student_drop_out_type.rb +++ b/app/models/student_drop_out_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentDropOutType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_education_level.rb b/app/models/student_education_level.rb index dcba427f4..2581492c6 100644 --- a/app/models/student_education_level.rb +++ b/app/models/student_education_level.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentEducationLevel < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_entrance_point_type.rb b/app/models/student_entrance_point_type.rb index 158b99997..c08b11384 100644 --- a/app/models/student_entrance_point_type.rb +++ b/app/models/student_entrance_point_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentEntrancePointType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_entrance_type.rb b/app/models/student_entrance_type.rb index 89ba06f11..707074f67 100644 --- a/app/models/student_entrance_type.rb +++ b/app/models/student_entrance_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class StudentEntranceType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :prospective_students, dependent: :nullify diff --git a/app/models/student_grade.rb b/app/models/student_grade.rb index e0c9c3d89..c65dc43f6 100644 --- a/app/models/student_grade.rb +++ b/app/models/student_grade.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentGrade < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_grading_system.rb b/app/models/student_grading_system.rb index ef9420f33..894d02416 100644 --- a/app/models/student_grading_system.rb +++ b/app/models/student_grading_system.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentGradingSystem < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_punishment_type.rb b/app/models/student_punishment_type.rb index 2a8239170..63bf27c6c 100644 --- a/app/models/student_punishment_type.rb +++ b/app/models/student_punishment_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentPunishmentType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/student_studentship_status.rb b/app/models/student_studentship_status.rb index fc8af3cc8..93cc096f7 100644 --- a/app/models/student_studentship_status.rb +++ b/app/models/student_studentship_status.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class StudentStudentshipStatus < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations end diff --git a/app/models/unit_instruction_language.rb b/app/models/unit_instruction_language.rb index 0909ae8af..ecff0002e 100644 --- a/app/models/unit_instruction_language.rb +++ b/app/models/unit_instruction_language.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitInstructionLanguage < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_instruction_type.rb b/app/models/unit_instruction_type.rb index 3596a279b..0cbbe9cfd 100644 --- a/app/models/unit_instruction_type.rb +++ b/app/models/unit_instruction_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitInstructionType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_status.rb b/app/models/unit_status.rb index be920f652..00a2f0fab 100644 --- a/app/models/unit_status.rb +++ b/app/models/unit_status.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitStatus < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/unit_type.rb b/app/models/unit_type.rb index 6a965e4e8..dd9f193ba 100644 --- a/app/models/unit_type.rb +++ b/app/models/unit_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UnitType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # enums enum group: { diff --git a/app/models/university_type.rb b/app/models/university_type.rb index d52308ef7..73bef52da 100644 --- a/app/models/university_type.rb +++ b/app/models/university_type.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class UniversityType < ApplicationRecord - include ReferenceValidations include ReferenceCallbacks include ReferenceSearch + include ReferenceValidations # relations has_many :units, dependent: :nullify diff --git a/app/models/user.rb b/app/models/user.rb index a9136cdb6..5e376972c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class User < ApplicationRecord + # virtual attributes + attr_accessor :country + # search include PgSearch pg_search_scope( @@ -30,8 +33,19 @@ class User < ApplicationRecord # validations validates :email, presence: true, uniqueness: true, length: { maximum: 255 } + validates :extension_number, allow_blank: true, + allow_nil: true, + length: { maximum: 8 }, + numericality: { only_integer: true } validates :id_number, uniqueness: true, numericality: { only_integer: true }, length: { is: 11 } + validates :linkedin, allow_blank: true, length: { maximum: 50 } + validates :phone_number, length: { maximum: 255 }, + allow_blank: true, + telephone_number: { country: proc { |record| record.country }, types: [:fixed_line] } validates :preferred_language, inclusion: { in: I18n.available_locales.map(&:to_s) } + validates :skype, allow_blank: true, length: { maximum: 50 } + validates :twitter, allow_blank: true, length: { maximum: 50 } + validates :website, allow_blank: true, length: { maximum: 50 } validates_with EmailAddress::ActiveRecordValidator, field: :email validates_with ImageValidator, field: :avatar, if: proc { |a| a.avatar.attached? } @@ -39,25 +53,17 @@ class User < ApplicationRecord after_create_commit :build_address_information, if: proc { addresses.formal.empty? } after_create_commit :build_identity_information, if: proc { identities.formal.empty? } - def build_address_information - Kps::AddressSaveJob.perform_later(self) - end - - def build_identity_information - Kps::IdentitySaveJob.perform_later(self) - end - # store accessors store :profile_preferences, accessors: %i[ - phone_number extension_number - website - twitter linkedin - skype orcid + phone_number public_photo public_studies + skype + twitter + website ], coder: JSON # permalinks @@ -69,6 +75,11 @@ def permalink username if domain.eql?(Tenant.configuration.email.domain) end + # send devise e-mails through active job + def send_devise_notification(notification, *args) + devise_mailer.send(notification, self, *args).deliver_later + end + # custom methods def accounts (students + employees).flatten @@ -85,4 +96,14 @@ def self.with_most_articles def self.with_most_projects where.not(projects_count: 0).order('projects_count desc').limit(10) end + + private + + def build_address_information + Kps::AddressSaveJob.perform_later(self) + end + + def build_identity_information + Kps::IdentitySaveJob.perform_later(self) + end end diff --git a/app/views/account/addresses/_form.html.erb b/app/views/account/addresses/_form.html.erb index 67c8188a7..77d0d05c2 100644 --- a/app/views/account/addresses/_form.html.erb +++ b/app/views/account/addresses/_form.html.erb @@ -12,10 +12,18 @@ <%= f.error_notification %> <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> -
<%= t('.hint') %>
+ <%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> +<%= t('.create_your_account') %>
+ <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= f.error_notification %> +<%= t('.login_to_your_account') %>
+ <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +<%= t('.registration_description') %>
+ <%= link_to t('.create_account'), register_path, class: 'btn btn-primary active mt-3', role: 'button' %> +<%= t('devise.mailer.common.hello', mail: @email) %>
-<%= t('.body', support_mail: Tenant.configuration.email.support) %>
<%= t('.new_mail', mail: @resource.email) %>
diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb index f60823131..e64bc04f1 100644 --- a/app/views/devise/mailer/unlock_instructions.html.erb +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -1,5 +1,3 @@<%= t('devise.mailer.common.hello', mail: @email) %>
-<%= t('.body') %>
-<%= link_to t('.unlock_my_account'), unlock_url(@resource, unlock_token: @token) %>
diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb deleted file mode 100644 index 9330960f6..000000000 --- a/app/views/devise/passwords/new.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<%= t('.hint') %>
- <%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> - <%= f.error_notification %> -<%= t('.create_your_account') %>
- <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> - <%= f.error_notification %> -<%= t('.login_to_your_account') %>
- <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> -<%= t('.registration_description') %>
- <%= link_to t('.create_account'), new_registration_path(resource_name), class: 'btn btn-primary active mt-3', role: 'button' %> -