Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cancel process from vacancies #760

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.2.2
3.3.4
48 changes: 35 additions & 13 deletions app/controllers/web/admin/vacancies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ def new
end

def edit
vacancy = Vacancy.find params[:id]
@vacancy = vacancy.becomes(Web::Admin::VacancyForm)
@vacancy = resource_vacancy.becomes(Web::Admin::VacancyForm)
end

def new_cancelation
@go_to = params[:go_to]
@vacancy = resource_vacancy.becomes(Web::Admin::VacancyForm)
end

def create
@vacancy = Web::Account::VacancyForm.new(params[:vacancy])
@vacancy = Web::Admin::VacancyForm.new(params[:vacancy])
@vacancy.creator = current_user

if @vacancy.save
Expand All @@ -54,13 +58,15 @@ def create
end

def update
vacancy = Vacancy.find params[:id]
@vacancy = vacancy.becomes(Web::Admin::VacancyForm)
if @vacancy.update(params[:vacancy])
f(:success)
redirect_to edit_admin_vacancy_path(@vacancy)
else
vacancy = resource_vacancy.becomes(Web::Admin::VacancyForm)
@vacancy = Admin::VacancyMutator.update(vacancy, params[:vacancy])

if @vacancy.invalid?
f(:error, now: true, values: { messages: @vacancy.errors.messages })
render :edit, status: :unprocessable_entity
else
f(:success)
redirect_to params[:go_to] || edit_admin_vacancy_path(@vacancy)
end
end

Expand All @@ -72,22 +78,38 @@ def on_moderate
end

def archive
vacancy = Vacancy.find params[:id]
vacancy.archive!
resource_vacancy.archive!
f(:success)
redirect_to params[:go_to] || admin_vacancies_path(page: params[:page])
end

def restore
vacancy = Vacancy.find params[:id]
vacancy.restore!
resource_vacancy.restore!
f(:success)
redirect_to params[:go_to] || admin_vacancies_path(page: params[:page])
end

def cancel
vacancy = resource_vacancy.becomes(Web::Admin::VacancyForm)

@vacancy = Admin::VacancyMutator.cancel!(vacancy, params[:vacancy])

if @vacancy.canceled?
f(:success)
redirect_to params[:go_to] || new_cancelation_admin_vacancy_path(@vacancy)
usernaimandrey marked this conversation as resolved.
Show resolved Hide resolved
else
f(:error, now: true, values: { messages: @vacancy.errors.messages })
render :new_cancelation, status: :unprocessable_entity
end
end

private

def query_params(default_params = {})
default_params.merge(params.permit![:q] || {})
end

def resource_vacancy
@resource_vacancy ||= Vacancy.find params[:id]
end
end
3 changes: 2 additions & 1 deletion app/forms/web/admin/vacancy_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Web::Admin::VacancyForm < Vacancy
:technology_list,
:direction_list,
:employment_type,
:state_event
:state_event,
:cancelation_reason

enumerize :salary_amount_type, in: %w[gross net depends]

Expand Down
13 changes: 13 additions & 0 deletions app/lib/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,18 @@ def next_step_open_source_params(resource)
career_path: career_member_path(career.slug, resource, locale: I18n.locale)
}
end

def vacancy_publish_params(resource)
{
vacancy_path: vacancy_path(resource, locale: I18n.locale)
}
end

def vacancy_cancel_params(resource)
{
vacancy_path: vacancy_path(resource, locale: I18n.locale),
cancelation_reason: resource.cancelation_reason_text
}
end
end
end
19 changes: 16 additions & 3 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,23 @@
#
class Notification < ApplicationRecord
include AASM
extend Enumerize

KINDS_NOTIFICATION = %i[
new_answer
new_comment
new_answer_like
new_answer_comment
answer_applied
new_career_member
career_member_finish
next_step_open_source
vacancy_publish
vacancy_cancel
].freeze

enumerize :kind, in: KINDS_NOTIFICATION

validates :kind, inclusion: {
in: %w[new_answer new_comment new_answer_like new_answer_comment answer_applied new_career_member career_member_finish next_step_open_source]
}
validates :resource_type, presence: true

belongs_to :user
Expand Down
10 changes: 9 additions & 1 deletion app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# id :integer not null, primary key
# about_company :string
# about_project :string
# cancelation_reason :string
# city_name :string
# company_name :string
# conditions_description :text
Expand Down Expand Up @@ -65,6 +66,7 @@ class Vacancy < ApplicationRecord
enumerize :location_of_position, in: %w[remote onsite hybrid], default: 'onsite'
enumerize :locale, in: %i[en ru], default: :ru
enumerize :kind, in: %i[hr habr], predicates: true, scope: true
enumerize :cancelation_reason, in: %i[high_requirements stack_irrelevant low_wage vacancy_competitors education_required], predicates: true, scope: true
# Ex:- scope :active, -> {where(:active => true)}
# enumerize :programming_language, in: PROGRAMMING_LANGAUGES, default: 'full-time', predicates: true, scope: true
# enumerize :country_name, in: COUNTRIES, default: :user, predicates: true, scope: true
Expand All @@ -86,6 +88,7 @@ class Vacancy < ApplicationRecord
unless: -> { salary_amount_type == :depends || salary_from&.positive? }
validates :salary_currency, presence: true
# validates :programming_language, presence: true
validates :cancelation_reason, presence: true, if: -> { canceled? || state_event == 'cancel' }

belongs_to :creator, class_name: 'User'
belongs_to :country, optional: true
Expand All @@ -95,13 +98,14 @@ class Vacancy < ApplicationRecord
state :on_moderate
state :published
state :archived
state :canceled

event :publish do
transitions to: :published
end

event :send_to_moderate do
transitions from: :idle, to: :on_moderate
transitions from: %i[idle canceled], to: :on_moderate
end

event :archive do
Expand All @@ -111,6 +115,10 @@ class Vacancy < ApplicationRecord
event :restore do
transitions from: %i[archived], to: :on_moderate
end

event :cancel do
transitions from: %i[on_moderate], to: :canceled
usernaimandrey marked this conversation as resolved.
Show resolved Hide resolved
end
end

def initialize(attribute = nil)
Expand Down
30 changes: 30 additions & 0 deletions app/mutators/admin/vacancy_mutator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class Admin::VacancyMutator
usernaimandrey marked this conversation as resolved.
Show resolved Hide resolved
class << self
def cancel!(vacancy, params = {})
return vacancy if vacancy.canceled?

user = vacancy.creator
cancelation_reason = params[:cancelation_reason]
vacancy.assign_attributes(cancelation_reason:)

if vacancy.cancel!
user.notifications.create!(kind: :vacancy_cancel, resource: vacancy)
end

vacancy
usernaimandrey marked this conversation as resolved.
Show resolved Hide resolved
end

def update(vacancy, params = {})
user = vacancy.creator
change_to_published = params[:state_event] == 'publish' && !vacancy.published?

if vacancy.update(params) && change_to_published
user.notifications.create!(kind: :vacancy_publish, resource: vacancy)
end

vacancy
end
end
end
3 changes: 3 additions & 0 deletions app/views/web/account/vacancies/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- if policy(vacancy).update?
= link_to edit_account_vacancy_path(vacancy) do
span.bi.bi-pencil-square.text-muted
- if vacancy.canceled?
span.ms-3
= t('.cancelation_reason', reason: vacancy.cancelation_reason_text)
.card-body
h5.card-title
= link_to vacancy, vacancy_path(vacancy)
Expand Down
3 changes: 3 additions & 0 deletions app/views/web/admin/vacancies/_vacancies_table.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ table.table
span.bi.bi-eye-fill
= link_to edit_admin_vacancy_path(vacancy), class: 'btn btn-outline-primary btn-sm', title: t('.edit') do
span.bi.bi-gear-fill
- if vacancy.may_cancel?
= link_to new_cancelation_admin_vacancy_path(vacancy, go_to: @go_to), class: 'btn btn-outline-warning btn-sm', title: t('.cancel') do
span.bi.bi-x-circle
- if vacancy.may_restore?
= link_to restore_admin_vacancy_path(vacancy, go_to: @go_to), method: :patch, class: 'btn btn-outline-success btn-sm', data: { confirm: t('.confirm_restore') }, title: t('.restore') do
span.bi.bi-arrow-counterclockwise
Expand Down
7 changes: 7 additions & 0 deletions app/views/web/admin/vacancies/new_cancelation.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= simple_form_for @vacancy, as: :vacancy, url: cancel_admin_vacancy_path(go_to: @go_to), wrapper: 'horizontal_form' do |f|
.mb-3
.mb-3
= f.input :cancelation_reason, include_blank: false
.row.mt-5
.col-sm.d-flex.mb-3
.me-3 = f.button :submit, class: 'btn-primary'
5 changes: 4 additions & 1 deletion config/locales/admin/en.flash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ en:
success: Resume published successfully
update:
success: Resume updated successfully
error: Failed to save changes. Please check form fields and try again.
error: "Failed to update job vacancy. Please correct errors in the form: %{messages}"
vacancies:
cancel:
success: Vacancy canceled successfull
error: "Failed to decline the job. Please correct errors in the form: %{messages}"
archive:
success: Vacancy archived successfully
restore:
Expand Down
1 change: 1 addition & 0 deletions config/locales/admin/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ en:
confirm_restore: Are you sure you want to post your selected vacancy?
vacancies_table:
edit: Editing Job
cancel: Cancel
home:
index:
admins: Administrators
Expand Down
4 changes: 4 additions & 0 deletions config/locales/admin/ru.flash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ ru:
success: Вакансия успешно возвращена на модерацию
update:
success: Вакансия успешно обновлена
error: "Не удалось обновить вакансию. Исправьте ошибки в форме: %{messages}"
create:
success: Вакансия созданна
cancel:
success: Вакансия отклонена
error: "Не удалось отклонить вакансию. Исправьте ошибки в форме: %{messages}"
users:
update:
success: Данные пользователя успешно обновлены
Expand Down
1 change: 1 addition & 0 deletions config/locales/admin/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ru:
restore: Вернуть на модерацию
confirm_archive: Вы уверенны что хотите отправить вакансию в архив
confirm_restore: Вы уверенны что хотите вернуть вакансию на модерацию
cancel: Отклонить
home:
menu:
list: Список
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ en:
archive: To archive
restore: Restore from archive
send_to_moderate: Send to moderate
cancel: Cancel
attributes:
resume/answer:
content: Answer
Expand Down Expand Up @@ -87,6 +88,8 @@ en:
state/on_moderate: On moderate
state/published: Published
state/archived: Archived
state/canceled: Canceled
cancelation_reason: Cancelation reason
name: Name
company: Company
notification:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.enumerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ en:
fluent: Speak fluently
notification_kind:
next_step_open_source: Open source
cancelation_reason:
high_requirements: high requirements for work experience
stack_irrelevant: non-revenant technology stack
low_wage: wages too low
vacancy_competitors: competitors' vacancy
education_required: requires compulsory higher education or to be a university student
2 changes: 2 additions & 0 deletions config/locales/en.notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ en:
next_step_open_source_html: |
The first half of the <a href="%{career_path}" class="fw-bolder">Career Track</a> is over! A very important step lies ahead - Participation in Open Source projects<br>
<a href="https://ru.hexlet.io/blog/posts/kak-vybrat-svoy-pervyy-open-sors-proekt-instruktsiya-ot-heksleta class="fw-bolder">How to choose your first open source project</a>
vacancy_publish_html: Your <a href="%{vacancy_path}" class="fw-bolder">vacancy</a> has been published
vacancy_cancel_html: Your <a href="%{vacancy_path}" class="fw-bolder">vacancy</a> was rejected due to %{cancelation_reason}

1 change: 1 addition & 0 deletions config/locales/en.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ en:
index:
resume: Look for candidates in the Resume section
header: My vacancies
cancelation_reason: "Reason: %{reason}"
resumes:
new:
info_for_user: Please note that if you plan to look for a job abroad, create a resume in the English version of the site
Expand Down
3 changes: 3 additions & 0 deletions config/locales/ru.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ru:
archive: Архивировать
restore: Восстановить из архива
send_to_moderate: Отправить на модерацию
cancel: Отклонить

models:
career: Карьерный трек
Expand Down Expand Up @@ -110,8 +111,10 @@ ru:
state/published: Опубликована
state/archived: В архиве
state/on_moderate: На модерации
state/canceled: Отклонена
name: Имя
company: компания
cancelation_reason: Причина отклонения
resume:
name: Позиция
summary: Описание
Expand Down
6 changes: 6 additions & 0 deletions config/locales/ru.enumerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ ru:
kind:
habr: Хабр
hr: Консультант
cancelation_reason:
high_requirements: высокие требования к опыту работы
stack_irrelevant: нерелевантный стек технологий
low_wage: слишком низкая заработная плата
vacancy_competitors: вакансия конкурентов
education_required: требуется обязательное высшее образование или быть студентом ВУЗа
2 changes: 2 additions & 0 deletions config/locales/ru.notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ ru:
next_step_open_source_html: |
Первая половина <a href="%{career_path}" class="fw-bolder">Карьерного трека</a> позади! Впереди очень важный шаг - Участие в Open Source проектах<br>
<a href="https://ru.hexlet.io/blog/posts/kak-vybrat-svoy-pervyy-open-sors-proekt-instruktsiya-ot-heksleta class="fw-bolder">Как выбрать свой первый опенсорс проект</a>
vacancy_publish_html: Ваша <a href="%{vacancy_path}" class="fw-bolder">вакансия</a> опубликована
vacancy_cancel_html: Ваша <a href="%{vacancy_path}" class="fw-bolder">вакансия</a> отклонена по причине - %{cancelation_reason}
1 change: 1 addition & 0 deletions config/locales/ru.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ ru:
index:
resume: Ищите кандидатов в разделе Резюме
header: Мои вакансии
cancelation_reason: "Причина: %{reason}"
resumes:
new:
info_for_user: Обращаем ваше внимание если вы планируете искать работу в России и СНГ, создавайте резюме в русскоязычной версии сайта
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@
get :on_moderate
end
member do
get :new_cancelation
patch :archive
patch :restore
patch :cancel
end
end
resources :careers, only: [] do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColumnCancelationReasonToVacancy < ActiveRecord::Migration[7.1]
def change
add_column :vacancies, :cancelation_reason, :string
end
end
Loading
Loading