Skip to content

Commit

Permalink
[745] send moderate vacancy
Browse files Browse the repository at this point in the history
  • Loading branch information
usernaimandrey committed Sep 3, 2024
1 parent fb36e9b commit e04d49c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
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
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'
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
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

0 comments on commit e04d49c

Please sign in to comment.