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

[745] send moderate vacancy #768

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -227,6 +227,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 @@ -325,6 +325,8 @@ ru:
form:
archive: В архив
cancel: Отмена
idle: Черновик
on_moderate: На модерацию
new:
header: Новая вакансия
edit:
Expand Down
26 changes: 26 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 Down
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
13 changes: 11 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 Down
Loading