Skip to content

Commit

Permalink
Merge pull request #7518 from fjordllc/feature/mentor-profile-display…
Browse files Browse the repository at this point in the history
…-toggle

メンター公開プロフィールの公開・非公開切り替え機能
  • Loading branch information
komagata authored Apr 24, 2024
2 parents 0d433f1 + 98f2973 commit c893f00
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/controllers/current_user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def user_params
:nda, :avatar, :trainee,
:mail_notification, :job_seeker, :tag_list,
:after_graduation_hope, :training_ends_on, :profile_image,
:hide_mentor_profile,
:profile_name, :profile_job, :profile_text, { authored_books_attributes: %i[id title url cover _destroy] },
:feed_url, :country_code, :subdivision_code, { discord_profile_attributes: %i[id account_name times_url] }
]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index
set_required_fields
render aciton: :index
else
@mentors = User.with_attached_profile_image.mentor.includes(authored_books: { cover_attachment: :blob })
@mentors = User.visible_sorted_mentors
render template: 'welcome/index', layout: 'welcome'
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class WelcomeController < ApplicationController
DEFAULT_COURSE = 'Railsプログラマー'

def index
@mentors = User.mentors_sorted_by_created_at
@mentors = current_user ? User.mentors_sorted_by_created_at : User.visible_sorted_mentors
end

def pricing; end
Expand Down
21 changes: 21 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class User < ApplicationRecord
validates :nda, presence: true
validates :password, length: { minimum: 4 }, confirmation: true, if: :password_required?
validates :mail_notification, inclusion: { in: [true, false] }
validates :hide_mentor_profile, inclusion: { in: [true, false] }
validates :github_id, uniqueness: true, allow_nil: true
validates :other_editor, presence: true, if: -> { editor == 'other_editor' }

Expand Down Expand Up @@ -226,6 +227,7 @@ class User < ApplicationRecord
message: 'は英文字と_(アンダースコア)のみが使用できます'
}
end

flag :retire_reasons, %i[
done
necessity
Expand Down Expand Up @@ -325,6 +327,13 @@ class User < ApplicationRecord
.includes(authored_books: { cover_attachment: :blob })
.order(:created_at)
}
scope :visible_sorted_mentors, lambda {
with_attached_profile_image
.mentor
.includes(authored_books: { cover_attachment: :blob })
.order(:created_at)
.where(hide_mentor_profile: false)
}
scope :working, lambda {
active.where(
adviser: false,
Expand Down Expand Up @@ -610,6 +619,18 @@ def avatar_url
image_url default_image_path
end

def profile_image_url
default_image_path = '/images/users/avatars/default.png'

if profile_image.attached?
profile_image
else
image_url default_image_path
end
rescue ActiveStorage::FileNotFoundError, ActiveStorage::InvariableError
image_url default_image_path
end

def generation
(created_at.year - 2013) * 4 + (created_at.month + 2) / 3
end
Expand Down
1 change: 1 addition & 0 deletions app/views/users/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- if user.mentor?
.form__items
h3.form__items-title メンター紹介用公開プロフィール
= render 'users/form/hide_mentor_profile', f: f
= render 'users/form/profile_image', f: f
= render 'users/form/profile_name', f: f
= render 'users/form/profile_job', f: f
Expand Down
10 changes: 10 additions & 0 deletions app/views/users/form/_hide_mentor_profile.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.form-item
= f.label :hide_mentor_profile, class: 'a-form-label'
label.a-on-off-checkbox.is-md
= f.check_box :hide_mentor_profile
span
.a-form-help
p
| あなたのメンター紹介用公開プロフィールをトップページに表示させるか否かの設定です。メンター紹介用公開プロフィールは誰でも閲覧できる場所に表示されます。
br
| メンバー以外に表示したくない場合はオンにしてください。
2 changes: 1 addition & 1 deletion app/views/users/form/_profile_image.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.form-item
= f.label :profile_image, class: 'a-form-label'
.form-item-file-input.js-file-input.a-file-input.is-square
.form-item-file-input.js-file-input.a-file-input
label.js-file-input__preview
- if f.object.profile_image.attached?
= image_tag f.object.profile_image
Expand Down
5 changes: 2 additions & 3 deletions app/views/welcome/_mentor.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ section.welcome-member.a-card(class="is-#{page}")
hr.a-border
.welcome-member__inner
.welcome-member__header
- if mentor.profile_image.attached?
.welcome-member__start
= image_tag(mentor.profile_image, class: 'welcome-member__image', alt: "#{mentor.profile_name}のアイコン画像")
.welcome-member__start
= image_tag(mentor.profile_image_url, class: 'welcome-member__image', alt: "#{mentor.profile_name}のアイコン画像")
.welcome-member__end
- if mentor.profile_name.present?
h3.welcome-member__name
Expand Down
6 changes: 1 addition & 5 deletions app/views/welcome/_mentors.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ section.welcome-child-section
.welcome-members
.row.is-gutter-width-32
- mentors.each do |mentor|
- if mentor.profile_image.present? && \
mentor.profile_name.present? && \
mentor.profile_job.present? && \
mentor.profile_text.present? && \
mentor.login_name != 'achamixx'
- if mentor.profile_name.present?
.col-xs-12.col-md-6.col-lg-4
= render 'welcome/mentor', mentor:, page: 'welcome-index'
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ja:
not_auto_retire: 休会六ヶ月後に自動退会しない
invoice_payment_user: 請求書払いのユーザーである
other_editor: その他のエディタ
hide_mentor_profile: プロフィール非公開
discord_profile:
account_name: Discord アカウント
times_url: 分報URL
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240308052935_add_hide_mentor_profile_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHideMentorProfileToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :hide_mentor_profile, :boolean, default: false, null: false
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@
t.boolean "invoice_payment", default: false, null: false
t.integer "editor"
t.string "other_editor"
t.boolean "hide_mentor_profile", default: false, null: false
t.index ["course_id"], name: "index_users_on_course_id"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["github_id"], name: "index_users_on_github_id", unique: true
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ komagata:
updated_at: "2014-01-01 00:00:01"
created_at: "2014-01-01 00:00:01"
last_activity_at: "2014-01-01 00:00:01"
hide_mentor_profile: false
profile_name: "駒形 真幸"
profile_job: "プログラマー"
profile_text: "株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。"
Expand Down
14 changes: 14 additions & 0 deletions test/system/home_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,18 @@ def assert_events_count(event_label, count)
visit_with_auth '/', 'hajime'
assert_text '最新のみんなの日報'
end

test 'toggles_mentor_profile_visibility' do
visit '/'
assert_text '駒形 真幸'
assert_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
visit_with_auth edit_current_user_path, 'komagata'
check 'プロフィール非公開', allow_label_click: true
click_on '更新する'
assert_text 'ユーザー情報を更新しました。'
logout
visit '/'
assert_no_text '駒形 真幸'
assert_no_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
end
end
17 changes: 17 additions & 0 deletions test/system/welcome_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,21 @@ class WelcomeTest < ApplicationSystemTestCase
assert_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
assert_selector 'img[src*="cherry-book.jpg"]'
end

test 'toggles_mentor_profile_visibility' do
visit '/welcome'
assert_text '駒形 真幸'
assert_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
visit_with_auth edit_current_user_path, 'komagata'
check 'プロフィール非公開', allow_label_click: true
click_on '更新する'
assert_text 'ユーザー情報を更新しました。'
logout
visit '/welcome'
assert_no_text '駒形 真幸'
assert_no_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
visit_with_auth '/welcome', 'kimura'
assert_text '駒形 真幸'
assert_text '株式会社ロッカの代表兼プログラマー。Rubyが大好きで怖話、フィヨルドブートキャンプなどを開発している。'
end
end

0 comments on commit c893f00

Please sign in to comment.