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

[TL-4694] add buttons for sending vacancy to moderation and to archive #753

Open
wants to merge 1 commit 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
15 changes: 9 additions & 6 deletions app/controllers/web/account/vacancies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def update
authorize @vacancy
vacancy = @vacancy.becomes(Web::Account::VacancyForm)
if vacancy.update(params[:vacancy])
change_visibility(@vacancy)
f(:success)
redirect_to account_vacancies_path
else
Expand All @@ -45,11 +44,15 @@ def update
end
end

def destroy; end

private
def archive
vacancy = current_user.vacancies.find params[:id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужен редирект так как сейчас когда отправляешь вакансию в архив страница не обновляется и кнопка архивации остается активна и при повторном нажатии страница падает

vacancy.archive!
end

def change_visibility(vacancy)
vacancy.archive! if params[:archive]
def send_to_moderate
vacancy = current_user.vacancies.find params[:id]
Copy link
Contributor

@usernaimandrey usernaimandrey Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и было бы не плохо флешь сообщение пользователю об успешной архивации

vacancy.send_to_moderate!
end

def destroy; end
end
2 changes: 1 addition & 1 deletion app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Vacancy < ApplicationRecord
end

event :archive do
transitions to: :archived
transitions from: %i[idle on_moderate published], to: :archived
end

event :restore do
Expand Down
6 changes: 6 additions & 0 deletions app/views/web/account/vacancies/_actions.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.fs-5 = t('.additional_actions')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю если вакансию нельзя за архивировать или отправить на модерацию не показывать эти кнопки

.row.mt-3
.col-auto.d-flex.mb-3
.me-3 = link_to t('.archive'), archive_account_vacancy_path(vacancy), method: :patch, class: class_names('btn btn-success', disabled: !vacancy.may_archive?), data: { confirm: 'Are you sure?' }
.col-auto.mb-3
.me-3 = link_to t('.send_to_moderate'), send_to_moderate_account_vacancy_path(vacancy), method: :patch, class: class_names('btn btn-danger', disabled: !vacancy.may_send_to_moderate?), data: { confirm: 'Are you sure?' }
8 changes: 3 additions & 5 deletions app/views/web/account/vacancies/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
.mb-3
= 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.button :submit, t('.archive'), data: { confirm: t('confirm') }, class: 'btn-outline-primary', name: 'archive'
.col-sm.d-flex.justify-content-end.mb-3
.col-auto.d-flex.mb-3
= f.button :submit, class: 'btn-primary'
.col-auto.mb-3
= link_to t('.cancel'), url_for(:back), class: 'btn btn-outline-secondary'
3 changes: 2 additions & 1 deletion app/views/web/account/vacancies/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.alert.alert-secondary
= t('.vacancy_archived')

= render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy), show_archive_button: [email protected]?
= render 'form', vacancy: @vacancy, url: account_vacancy_path(@vacancy)
= render 'actions', vacancy: @vacancy, url: account_vacancy_path(@vacancy)
2 changes: 1 addition & 1 deletion app/views/web/account/vacancies/new.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- content_for :header do
= t('.header')

= render 'form', vacancy: @vacancy, url: account_vacancies_path, show_archive_button: false
= render 'form', vacancy: @vacancy, url: account_vacancies_path
5 changes: 5 additions & 0 deletions config/locales/en.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ en:
vacancies:
form:
archive: Archive
send_to_moderate: Send to moderate
cancel: Cancel
new:
header: New vacancy
Expand All @@ -235,6 +236,10 @@ en:
index:
resume: Look for candidates in the Resume section
header: My vacancies
actions:
archive: Archive
send_to_moderate: Send to moderate
additional_actions: Additional actions
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
2 changes: 2 additions & 0 deletions config/locales/ru.helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ru:
submit:
create: Создать
update: Изменить
archive: Архивировать
send_to_moderate: Отправить на модерацию
web_lead_form:
create: Получить консультацию
5 changes: 5 additions & 0 deletions config/locales/ru.views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ ru:
vacancies:
form:
archive: В архив
send_to_moderate: На модерацию
cancel: Отмена
new:
header: Новая вакансия
Expand All @@ -333,6 +334,10 @@ ru:
index:
resume: Ищите кандидатов в разделе Резюме
header: Мои вакансии
actions:
archive: В архив
send_to_moderate: На модерацию
additional_actions: Дополнительные действия
resumes:
new:
info_for_user: Обращаем ваше внимание если вы планируете искать работу в России и СНГ, создавайте резюме в русскоязычной версии сайта
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@

namespace :account do
resources :resumes
resources :vacancies
resources :vacancies do
member do
patch :archive
patch :send_to_moderate
end
end
resources :notifications, only: %i[index update]
resource :newsletters, only: %i[edit update]
resource :profile, only: %i[edit update destroy]
Expand Down
20 changes: 17 additions & 3 deletions test/controllers/web/account/vacancies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,24 @@ class Web::Account::VacanciesControllerTest < ActionDispatch::IntegrationTest
assert { vacancy }
end

test '#edit' do
vacancy = vacancies(:one)
get edit_account_vacancy_path(vacancy)
test '#archive' do
vacancy = vacancies(:state_idle)
patch archive_account_vacancy_path(vacancy)
assert_response :success

vacancy.reload

assert { vacancy.archived? }
end

test '#send_to_moderate' do
vacancy = vacancies(:state_idle)
patch send_to_moderate_account_vacancy_path(vacancy)
assert_response :success

vacancy.reload

assert { vacancy.on_moderate? }
end

test 'can not edit a posted job' do
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/vacancies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,11 @@ over_month_old:
title: Фронтендер
salary_to: 2000
published_at: <%= 2.month.ago.to_fs(:db) %>

state_idle:
<<: *DEFAULTS
title: Черновик
state: idle
salary_from: 1000
salary_to: 2000
salary_currency: rub
Loading