From 4557690eab8a5bb525ef92e856a05678feed7122 Mon Sep 17 00:00:00 2001 From: beherit197777 Date: Thu, 28 Nov 2024 13:51:58 +0300 Subject: [PATCH 1/2] Add controller and route for resume preview --- app/controllers/web/account/resumes_controller.rb | 11 +++++++++++ config/routes.rb | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/web/account/resumes_controller.rb b/app/controllers/web/account/resumes_controller.rb index 20860d93..532a71a0 100644 --- a/app/controllers/web/account/resumes_controller.rb +++ b/app/controllers/web/account/resumes_controller.rb @@ -47,6 +47,17 @@ def update def destroy; end + def preview + @resume = current_user.resumes.find(params[:id]) + @resume_educations = @resume.educations.web + @resume_works = @resume.works.web + if @resume.draft? + render :preview + else + redirect_to account_resumes_path, alert: t('.not_accessible') + end + end + private def change_state(resume) diff --git a/config/routes.rb b/config/routes.rb index b67fd374..7571e731 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,11 +72,15 @@ end namespace :account do - resources :resumes resources :vacancies resources :notifications, only: %i[index update] resource :newsletters, only: %i[edit update] resource :profile, only: %i[edit update destroy] + resources :resumes do + member do + get :preview + end + end scope module: :careers do resources :members, only: %i[index] end From 39d9bfa38e656b6c61ade17f83a73a9adaff1fdc Mon Sep 17 00:00:00 2001 From: beherit197777 Date: Thu, 28 Nov 2024 13:52:55 +0300 Subject: [PATCH 2/2] Add views and translations for resume preview --- app/views/web/account/resumes/index.html.slim | 3 ++ .../web/account/resumes/preview.html.slim | 28 +++++++++++++++++++ config/locales/ru.views.yml | 2 ++ .../web/account/resumes_controller_test.rb | 17 +++++++++++ test/fixtures/resumes.yml | 6 ++++ 5 files changed, 56 insertions(+) create mode 100644 app/views/web/account/resumes/preview.html.slim diff --git a/app/views/web/account/resumes/index.html.slim b/app/views/web/account/resumes/index.html.slim index 6d66b94c..1a310647 100644 --- a/app/views/web/account/resumes/index.html.slim +++ b/app/views/web/account/resumes/index.html.slim @@ -8,6 +8,9 @@ span.ms-3 = link_to edit_account_resume_path(resume) do span.bi.bi-pencil-square.text-muted + span.ms-3 + = link_to preview_account_resume_path(resume) do + span.bi.bi-eye-fill.text-muted .card-body h5.card-title = link_to_unless resume.draft?, resume, resume_path(resume) diff --git a/app/views/web/account/resumes/preview.html.slim b/app/views/web/account/resumes/preview.html.slim new file mode 100644 index 00000000..d375041b --- /dev/null +++ b/app/views/web/account/resumes/preview.html.slim @@ -0,0 +1,28 @@ += content_for :meta do + = structured_data_tag 'resume', + resume: @resume, educations: @resume_educations, works: @resume_works + += content_for :header do + .d-flex.justify-content-center + .m-1 + = link_to @resume.user.full_name, user_path(@resume.user) + - if current_user_or_guest.admin? + .m-1 + = link_to edit_admin_resume_path(@resume), class: 'btn btn-outline-primary' do + span.bi.bi-gear + +h3.text-center = @resume + +- if @resume.archived? + .alert.alert-warning = t('.archived') + +- if policy(@resume).download? + .mb-2.d-flex.justify-content-end + = link_to resume_pdf_path(@resume, 'base', format: :pdf), + class: 'me-3', title: t('web.resumes.show.print'), target: :_blank, rel: 'noopener' do + i.bi.bi-printer-fill + = link_to resume_pdf_path(@resume, 'base'), title: t('web.resumes.show.download') do + i.bi.bi-download + +.mb-5 + = render 'web/resumes/information' diff --git a/config/locales/ru.views.yml b/config/locales/ru.views.yml index 57bbfe07..b5d475bc 100644 --- a/config/locales/ru.views.yml +++ b/config/locales/ru.views.yml @@ -273,6 +273,8 @@ ru: header: Редактирование резюме index: header: Мои резюме + preview: + not_accessible: Нет Доступа profiles: form: info_for_user: Давайте познакомимся =). Заполните, пожалуйста, фамилию, имя и можете рассказать немного о себе. diff --git a/test/controllers/web/account/resumes_controller_test.rb b/test/controllers/web/account/resumes_controller_test.rb index ad6d13eb..a520c314 100644 --- a/test/controllers/web/account/resumes_controller_test.rb +++ b/test/controllers/web/account/resumes_controller_test.rb @@ -5,7 +5,9 @@ class Web::Account::ResumesControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:one) + @other_user = users(:two) sign_in(@user) + @draft_resume = resumes(:one_draft) end test '#index' do @@ -190,4 +192,19 @@ class Web::Account::ResumesControllerTest < ActionDispatch::IntegrationTest resume = Resume.find_by(name: attrs[:name]) assert { !resume } end + + test '#preview for draft resume' do + get preview_account_resume_path(@draft_resume) + assert_response :success + assert_select 'h1', @user.full_name + assert_select 'h3', @draft_resume.name + end + + test '#preview for resume not owned by user' do + sign_out(@user) + sign_in(@other_user) + assert_raises ActiveRecord::RecordNotFound do + get preview_account_resume_path(@draft_resume) + end + end end diff --git a/test/fixtures/resumes.yml b/test/fixtures/resumes.yml index fa63ece6..3f5e7e58 100644 --- a/test/fixtures/resumes.yml +++ b/test/fixtures/resumes.yml @@ -149,3 +149,9 @@ full_en: summary: | A self-taught programmer who has chosen the path of constant self-improvement. I value beautiful and concise code, I love functional programming (the great trinity of map, filter, reduce). I work with languages ​​such as JS, Ruby, PHP, Python, Elixir, Clojure (to varying degrees of skill, of course). I admire the LISP family of languages, so much so that I am writing my own LISP interpreter in Elixir as a pet project. At the moment, I am delving into Unix OS in order to further improve my DevOps skills. answers_count: 1 + +one_draft: + <<: *DEFAULTS + state: draft + user: one + contact_email: one@email.com \ No newline at end of file