From e04d49cd6cd2a6a97f1c07ec06e54a7a2e14efa2 Mon Sep 17 00:00:00 2001 From: usernaimandrey Date: Wed, 4 Sep 2024 00:34:25 +0300 Subject: [PATCH] [745] send moderate vacancy --- .../web/account/vacancies_controller.rb | 18 +++++++++++------- app/models/vacancy.rb | 6 +++++- .../web/account/vacancies/_form.html.slim | 6 ++++-- config/locales/en.views.yml | 2 ++ config/locales/ru.views.yml | 2 ++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/web/account/vacancies_controller.rb b/app/controllers/web/account/vacancies_controller.rb index ae721b4ef..97dc0ecf3 100644 --- a/app/controllers/web/account/vacancies_controller.rb +++ b/app/controllers/web/account/vacancies_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/app/models/vacancy.rb b/app/models/vacancy.rb index 898effe9b..d08e5edaf 100644 --- a/app/models/vacancy.rb +++ b/app/models/vacancy.rb @@ -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 @@ -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 diff --git a/app/views/web/account/vacancies/_form.html.slim b/app/views/web/account/vacancies/_form.html.slim index 99efbbce0..1de6e60a1 100644 --- a/app/views/web/account/vacancies/_form.html.slim +++ b/app/views/web/account/vacancies/_form.html.slim @@ -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' diff --git a/config/locales/en.views.yml b/config/locales/en.views.yml index 59db2e1ab..6564403b7 100644 --- a/config/locales/en.views.yml +++ b/config/locales/en.views.yml @@ -227,6 +227,8 @@ en: form: archive: Archive cancel: Cancel + idle: Draft + on_moderate: On moderate new: header: New vacancy edit: diff --git a/config/locales/ru.views.yml b/config/locales/ru.views.yml index f76b47ad0..aaa2bfb4d 100644 --- a/config/locales/ru.views.yml +++ b/config/locales/ru.views.yml @@ -325,6 +325,8 @@ ru: form: archive: В архив cancel: Отмена + idle: Черновик + on_moderate: На модерацию new: header: Новая вакансия edit: