Skip to content

Commit

Permalink
Merge pull request #768 from usernaimandrey/feat/745/add_send_to_mode…
Browse files Browse the repository at this point in the history
…rate

[745] send moderate vacancy
  • Loading branch information
fey authored Dec 27, 2024
2 parents 592468d + 3d4c086 commit 28ba151
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ GEM
websocket-extensions (0.1.5)
wicked_pdf (2.8.0)
activesupport
wkhtmltopdf-binary (0.12.6.7)
wkhtmltopdf-binary (0.12.6.8)
wkhtmltopdf-heroku (3.0.0)
xpath (3.2.0)
nokogiri (~> 1.8)
Expand Down
18 changes: 11 additions & 7 deletions app/controllers/web/account/vacancies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def create
@vacancy = Web::Account::VacancyForm.new(params[:vacancy])
@vacancy.creator = current_user

change_visibility(@vacancy)
if @vacancy.save
f(:success)
redirect_to account_vacancies_path
Expand All @@ -31,15 +32,14 @@ def create
end

def update
@vacancy = current_user.vacancies.find params[:id]
authorize @vacancy
vacancy = @vacancy.becomes(Web::Account::VacancyForm)
if vacancy.update(params[:vacancy])
change_visibility(@vacancy)
vacancy = current_user.vacancies.find params[:id]
authorize vacancy
@vacancy = vacancy.becomes(Web::Account::VacancyForm)
change_visibility(@vacancy)
if @vacancy.update(params[:vacancy])
f(:success)
redirect_to account_vacancies_path
else
@vacancy = vacancy.becomes(Vacancy)
f(:error)
render :edit, status: :unprocessable_entity
end
Expand All @@ -50,6 +50,10 @@ def destroy; end
private

def change_visibility(vacancy)
vacancy.archive! if params[:archive]
if params[:on_moderate]
vacancy.send_to_moderate
else
vacancy.send_to_draft
end
end
end
6 changes: 5 additions & 1 deletion app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Vacancy < ApplicationRecord
belongs_to :country, optional: true

aasm :state, column: :state, timestamps: true do
state :idle
state :idle, initial: true
state :on_moderate
state :published
state :archived
Expand All @@ -108,6 +108,10 @@ class Vacancy < ApplicationRecord
transitions from: %i[idle canceled], to: :on_moderate
end

event :send_to_draft do
transitions to: :idle
end

event :archive do
transitions to: :archived
end
Expand Down
2 changes: 1 addition & 1 deletion app/policies/vacancy_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ def edit?
end

def update?
@user.admin? || !@record.published?
@user.admin? || (!@record.published? && !@record.archived?)
end
end
6 changes: 4 additions & 2 deletions app/views/web/account/vacancies/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
= f.input :direction_list, input_html: { value: f.object.direction_list.to_s }
.row.mt-5
.col-sm.d-flex.mb-3
.me-3 = f.button :submit, class: 'btn-primary'
- if local_assigns.fetch(:show_archive_button, false)
.me-3 = f.submit t('.idle'), class: 'btn btn-success me-1 me-sm-3', name: 'idle'
- if vacancy.may_send_to_moderate?
.me-3 = f.submit t('.on_moderate'), class: 'btn btn-outline-primary', name: 'on_moderate'
/ - if local_assigns.fetch(:show_archive_button, false)
.me-3 = f.button :submit, t('.archive'), data: { confirm: t('confirm') }, class: 'btn-outline-primary', name: 'archive'
.col-sm.d-flex.justify-content-end.mb-3
= link_to t('.cancel'), url_for(:back), class: 'btn btn-outline-secondary'
1 change: 1 addition & 0 deletions config/locales/en.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ en:
restore: Restore from archive
send_to_moderate: Send to moderate
cancel: Cancel
send_to_draft: To draft
attributes:
resume/answer:
content: Answer
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ en:
form:
archive: Archive
cancel: Cancel
idle: Draft
on_moderate: On moderate
new:
header: New vacancy
edit:
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ru:
restore: Восстановить из архива
send_to_moderate: Отправить на модерацию
cancel: Отклонить
send_to_draft: В черновик

models:
career: Карьерный трек
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ru.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ ru:
form:
archive: В архив
cancel: Отмена
idle: Черновик
on_moderate: На модерацию
new:
header: Новая вакансия
edit:
Expand Down
41 changes: 41 additions & 0 deletions test/controllers/web/account/vacancies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ class Web::Account::VacanciesControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to root_path
end

test 'can not edit a archived job' do
user = users(:one)
archived_vacancy = vacancies(:archived_one)
sign_out @hr
sign_in user

get edit_account_vacancy_path(archived_vacancy)

assert_redirected_to root_path
end

test 'can not update archived job' do
attrs = FactoryBot.attributes_for :vacancy
user = users(:one)
archived_vacancy = vacancies(:archived_one)
sign_out @hr
sign_in user

patch account_vacancy_path(archived_vacancy), params: { vacancy: attrs }
assert_response :redirect

archived_vacancy.reload

assert { archived_vacancy.title != attrs[:title] }
end

test '#update' do
attrs = FactoryBot.attributes_for :vacancy
vacancy = vacancies(:one)
Expand All @@ -79,4 +105,19 @@ class Web::Account::VacanciesControllerTest < ActionDispatch::IntegrationTest

assert { published_vacancy.title != attrs[:title] }
end

test '#send_to_moderate' do
vacancy = vacancies(:draft_full)
attrs = FactoryBot.attributes_for(:vacancy)
params = {
on_moderate: true,
vacancy: attrs
}

patch(account_vacancy_path(vacancy), params:)
vacancy.reload

assert_redirected_to account_vacancies_path
assert { vacancy.on_moderate? }
end
end
4 changes: 2 additions & 2 deletions test/controllers/web/admin/vacancies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Web::Admin::VacanciesControllerTest < ActionDispatch::IntegrationTest
end

test '#publish' do
vacancy = vacancies(:archived)
vacancy = vacancies(:archived_one)
state_event = :publish
attrs = vacancy.attributes.merge(state_event:)
previous_published_at = vacancy.published_at
Expand Down Expand Up @@ -91,7 +91,7 @@ class Web::Admin::VacanciesControllerTest < ActionDispatch::IntegrationTest
end

test '#restore' do
vacancy = vacancies(:archived)
vacancy = vacancies(:archived_one)

patch restore_admin_vacancy_path(vacancy), params: { go_to: admin_vacancies_path(locale: I18n.locale) }

Expand Down
20 changes: 18 additions & 2 deletions test/fixtures/vacancies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,23 @@ without_city_name:
salary_from: 1000
salary_to: 2000

archived:
archived_full:
<<: *DEFAULTS
title: Archeved vacancy
title: Archeved vacancy full
state: archived
salary_from: 1000
salary_to: 2000
salary_currency: rub

archived_one:
<<: *DEFAULTS
title: Archeved vacancy one
state: archived
salary_from: 1000
salary_to: 2000
salary_currency: rub
creator: one

on_moderate:
<<: *DEFAULTS
title: On moderate vacancy
Expand All @@ -151,3 +160,10 @@ over_month_old:
title: Фронтендер
salary_to: 2000
published_at: <%= 2.month.ago.to_fs(:db) %>

draft_full:
<<: *DEFAULTS
title: Draft
state: idle
salary_from: 1000
salary_to: 2000

0 comments on commit 28ba151

Please sign in to comment.