From e6b480c8a350c3350eea8b6ea5e42a4545401c23 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 4 Nov 2023 10:39:53 +0900 Subject: [PATCH 01/21] =?UTF-8?q?=E4=BC=91=E4=BC=9A=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=82=89=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AE=E4=B8=BB=E5=82=AC=E8=80=85=E3=81=8Ckomagata=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 1 + app/controllers/regular_events_controller.rb | 9 +++++++++ app/models/regular_event.rb | 8 ++++++++ app/models/user.rb | 9 +++++++++ 4 files changed, 27 insertions(+) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index ca32de380cd..c2e43900cb2 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,6 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins + current_user.delete_organizer logout redirect_to hibernation_path else diff --git a/app/controllers/regular_events_controller.rb b/app/controllers/regular_events_controller.rb index d1fd907d0a5..edad6a51618 100644 --- a/app/controllers/regular_events_controller.rb +++ b/app/controllers/regular_events_controller.rb @@ -120,4 +120,13 @@ def set_all_user_participants_and_watchers RegularEvent::ParticipantsCreator.call(regular_event: @regular_event, target: students_trainees_mentors_and_admins) RegularEvent::ParticipantsWatcher.call(regular_event: @regular_event, target: students_trainees_mentors_and_admins) end + + def assign_admin_as_organizer_if_none + return if @regular_event.organizers.exists? + + # 管理者(komagata)をデータベースから検索 + admin_user = User.active.find_by(login_name: 'komagata') + # 管理者を主催者として割り当てる + @regular_event.organizers.create(user: admin_user) if admin_user + end end diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 046132d17aa..02196813c7a 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -185,6 +185,14 @@ def remove_event(events_arr, id) end end + def assign_admin_as_organizer_if_none + return if organizers.exists? + # DBから管理者(komagata)を取得 + admin_user = User.find_by(login_name: 'komagata') + # 管理者が存在する場合にのみ主催者として追加 + Organizer.new(user: admin_user, regular_event: self).save if admin_user + end + private def end_at_be_greater_than_start_at diff --git a/app/models/user.rb b/app/models/user.rb index 87b327f8cd7..fb2a7a97b8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -755,6 +755,15 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end + def delete_organizer + organizers = self.organizers + organizers.each do |organizer| + event = organizer.regular_event + organizer.delete + event.assign_admin_as_organizer_if_none + end + end + private def password_required? From 53f813fa8628029f8c36af763e42c5906a85add7 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:02:58 +0900 Subject: [PATCH 02/21] =?UTF-8?q?=E9=80=80=E4=BC=9A=E3=81=97=E3=81=9F?= =?UTF-8?q?=E6=99=82=E3=81=AE=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99=E3=83=B3?= =?UTF-8?q?=E3=83=88=E4=B8=BB=E5=82=AC=E8=80=85=E3=81=AE=E5=89=B2=E3=82=8A?= =?UTF-8?q?=E5=BD=93=E3=81=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/regular_events_controller.rb | 9 ------ app/controllers/retirement_controller.rb | 1 + app/models/regular_event.rb | 3 +- test/fixtures/regular_events.yml | 11 +++++++ test/models/regular_event_test.rb | 9 ++++++ test/models/user_test.rb | 8 +++++ test/system/hibernation_test.rb | 34 ++++++++++++++++++++ 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/app/controllers/regular_events_controller.rb b/app/controllers/regular_events_controller.rb index edad6a51618..d1fd907d0a5 100644 --- a/app/controllers/regular_events_controller.rb +++ b/app/controllers/regular_events_controller.rb @@ -120,13 +120,4 @@ def set_all_user_participants_and_watchers RegularEvent::ParticipantsCreator.call(regular_event: @regular_event, target: students_trainees_mentors_and_admins) RegularEvent::ParticipantsWatcher.call(regular_event: @regular_event, target: students_trainees_mentors_and_admins) end - - def assign_admin_as_organizer_if_none - return if @regular_event.organizers.exists? - - # 管理者(komagata)をデータベースから検索 - admin_user = User.active.find_by(login_name: 'komagata') - # 管理者を主催者として割り当てる - @regular_event.organizers.create(user: admin_user) if admin_user - end end diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index b633f862de0..5f115c58de7 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,6 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user + current_user.delete_organizer Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 02196813c7a..48e62aebd52 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -187,9 +187,8 @@ def remove_event(events_arr, id) def assign_admin_as_organizer_if_none return if organizers.exists? - # DBから管理者(komagata)を取得 + admin_user = User.find_by(login_name: 'komagata') - # 管理者が存在する場合にのみ主催者として追加 Organizer.new(user: admin_user, regular_event: self).save if admin_user end diff --git a/test/fixtures/regular_events.yml b/test/fixtures/regular_events.yml index 3c15d904384..3673ecd50da 100644 --- a/test/fixtures/regular_events.yml +++ b/test/fixtures/regular_events.yml @@ -155,3 +155,14 @@ regular_event32: user: komagata category: 0 published_at: "2023-08-01 00:00:00" + +regular_event33: + title: 主催者のいないイベント + description: 主催者のいないイベント + finished: false + hold_national_holiday: false + start_at: <%= Time.zone.local(2020, 1, 1, 21, 0, 0) %> + end_at: <%= Time.zone.local(2020, 1, 1, 22, 0, 0) %> + user: kimura + category: 0 + published_at: "2023-08-01 00:00:00" diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index b80627c5768..90709c92746 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -155,4 +155,13 @@ class RegularEventTest < ActiveSupport::TestCase assert regular_events1.include?(regular_event2) assert regular_events2.include?(regular_event3) end + + test '#assign_admin_as_organizer_if_none' do + + regular_event = regular_events(:regular_event33) + regular_event.assign_admin_as_organizer_if_none + assert User.find_by(login_name: 'komagata'), regular_event.organizers[0] + end + + end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 10fd634aa2a..e1102226eb8 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -678,4 +678,12 @@ class UserTest < ActiveSupport::TestCase assert_equal User.students_and_trainees, User.users_role(not_scope_name, allowed_targets: allowed_targets, default_target: 'student_and_trainee') assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets) end + + test '#delete_organizer' do + user = users(:hajime) + user.delete_organizer + + event = regular_events(:regular_event4) + assert !event.organizers.include?(user) + end end diff --git a/test/system/hibernation_test.rb b/test/system/hibernation_test.rb index c19a7300e89..8bcef514834 100644 --- a/test/system/hibernation_test.rb +++ b/test/system/hibernation_test.rb @@ -37,4 +37,38 @@ class HibernationTest < ApplicationSystemTestCase page.driver.browser.switch_to.alert.accept assert_text '復帰予定日を入力してください' end + + test 'hibernate with event organizer' do + visit_with_auth new_hibernation_path, 'hajime' + within('form[name=hibernation]') do + fill_in( + 'hibernation[scheduled_return_on]', + with: (Date.current + 30) + ) + fill_in('hibernation[reason]', with: 'test') + end + click_on '休会する' + page.driver.browser.switch_to.alert.accept + assert_text '休会処理が完了しました' + + regular_event = regular_event(regular_event4) + visit_with_auth "regular_events/#{regular_event.id}", 'kimura' + assert_no_selector 'is-hajime' + + visit_with_auth new_hibernation_path, 'kimura' + within('form[name=hibernation]') do + fill_in( + 'hibernation[scheduled_return_on]', + with: (Date.current + 30) + ) + fill_in('hibernation[reason]', with: 'test') + end + click_on '休会する' + page.driver.browser.switch_to.alert.accept + assert_text '休会処理が完了しました' + + visit_with_auth "regular_events/#{regular_event.id}", 'komagata' + assert_no_selector 'is-kimura' + assert_selector 'is-komagata' + end end From ef80d89f7ef960c9d452024555152bbc4189f907 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 5 Nov 2023 12:32:06 +0900 Subject: [PATCH 03/21] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=81=A8=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 3 --- test/models/user_test.rb | 2 +- test/system/hibernation_test.rb | 10 ++++++---- test/system/retirement_test.rb | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 90709c92746..491b4a54cab 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -157,11 +157,8 @@ class RegularEventTest < ActiveSupport::TestCase end test '#assign_admin_as_organizer_if_none' do - regular_event = regular_events(:regular_event33) regular_event.assign_admin_as_organizer_if_none assert User.find_by(login_name: 'komagata'), regular_event.organizers[0] end - - end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index e1102226eb8..6c11ce92350 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -684,6 +684,6 @@ class UserTest < ActiveSupport::TestCase user.delete_organizer event = regular_events(:regular_event4) - assert !event.organizers.include?(user) + assert_not event.organizers.include?(user) end end diff --git a/test/system/hibernation_test.rb b/test/system/hibernation_test.rb index 8bcef514834..0aa033b42bd 100644 --- a/test/system/hibernation_test.rb +++ b/test/system/hibernation_test.rb @@ -47,13 +47,14 @@ class HibernationTest < ApplicationSystemTestCase ) fill_in('hibernation[reason]', with: 'test') end + find('.check-box-to-read').click click_on '休会する' page.driver.browser.switch_to.alert.accept assert_text '休会処理が完了しました' - regular_event = regular_event(regular_event4) + regular_event = regular_events(:regular_event4) visit_with_auth "regular_events/#{regular_event.id}", 'kimura' - assert_no_selector 'is-hajime' + assert_no_selector '.is-hajime' visit_with_auth new_hibernation_path, 'kimura' within('form[name=hibernation]') do @@ -63,12 +64,13 @@ class HibernationTest < ApplicationSystemTestCase ) fill_in('hibernation[reason]', with: 'test') end + find('.check-box-to-read').click click_on '休会する' page.driver.browser.switch_to.alert.accept assert_text '休会処理が完了しました' visit_with_auth "regular_events/#{regular_event.id}", 'komagata' - assert_no_selector 'is-kimura' - assert_selector 'is-komagata' + assert_no_selector '.is-kimura' + assert_selector '.is-komagata' end end diff --git a/test/system/retirement_test.rb b/test/system/retirement_test.rb index e8b2376cd3b..a35521a25e8 100644 --- a/test/system/retirement_test.rb +++ b/test/system/retirement_test.rb @@ -185,4 +185,26 @@ class RetirementTest < ApplicationSystemTestCase visit '/retirement' assert_equal 'FJORD BOOT CAMP(フィヨルドブートキャンプ)', title end + + test 'retirement with event organizer' do + visit_with_auth new_retirement_path, 'hajime' + find('label', text: 'とても良い').click + click_on '退会する' + page.driver.browser.switch_to.alert.accept + assert_text '退会処理が完了しました' + + regular_event = regular_events(:regular_event4) + visit_with_auth "regular_events/#{regular_event.id}", 'kimura' + assert_no_selector '.is-hajime' + + visit_with_auth new_retirement_path, 'kimura' + find('label', text: 'とても良い').click + click_on '退会する' + page.driver.browser.switch_to.alert.accept + assert_text '退会処理が完了しました' + + visit_with_auth "regular_events/#{regular_event.id}", 'komagata' + assert_no_selector '.is-kimura' + assert_selector '.is-komagata' + end end From 4e9b976abd02a9303238a63301af551356930971 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 7 Nov 2023 09:55:25 +0900 Subject: [PATCH 04/21] =?UTF-8?q?=E4=BC=91=E4=BC=9A=E3=80=81=E9=80=80?= =?UTF-8?q?=E4=BC=9A=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=AB=E8=87=AA?= =?UTF-8?q?=E5=88=86=E3=81=8C=E4=B8=BB=E5=82=AC=E3=81=AE=E5=AE=9A=E6=9C=9F?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E3=80=81=E4=BB=BB=E6=84=8F=E3=81=A7=E5=88=A5?= =?UTF-8?q?=E3=81=AE=E5=8F=82=E5=8A=A0=E8=80=85=E3=81=AB=E4=B8=BB=E5=82=AC?= =?UTF-8?q?=E8=80=85=E5=BC=95=E3=81=8D=E7=B6=99=E3=81=8E=E3=82=92=E6=8E=A8?= =?UTF-8?q?=E5=A5=A8=E3=81=99=E3=82=8B=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/hibernation/new.html.slim | 14 ++++++++++++++ app/views/retirement/new.html.slim | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/views/hibernation/new.html.slim b/app/views/hibernation/new.html.slim index fb04de60331..9b6ee13b2ad 100644 --- a/app/views/hibernation/new.html.slim +++ b/app/views/hibernation/new.html.slim @@ -69,6 +69,20 @@ hr.a-border | こちら | のページの「分報 URL」欄に分報チャンネルの URL を登録してください。 + - if current_user.regular_events.any? + .form-item + label.a-form-label + | 定期イベント + .important-message + .important-message__body + .a-short-text.is-sm + p + |ご自身が主催者である定期イベントがあります。 + | 休会をお考えの場合、イベントの進行に影響がないよう、任意で他の参加者に主催を引き継ぐことを推奨します。 + | 休会手続きを完了する前に、 + = link_to 'こちら', regular_events_path + | からイベント管理を行なってください。 + .form-item label.a-form-label.is-required | 休会についての注意を読みましたか? diff --git a/app/views/retirement/new.html.slim b/app/views/retirement/new.html.slim index 15df2ab1f23..436712c742e 100644 --- a/app/views/retirement/new.html.slim +++ b/app/views/retirement/new.html.slim @@ -15,6 +15,17 @@ hr.a-border = render 'errors', object: current_user = form_with model: current_user, local: true, url: retirement_path, method: :post, class: 'form' do |f| .form__items + - if current_user.regular_events.any? + .form-item + .important-message + .important-message__body + .a-short-text.is-sm + p + |ご自身が主催者である定期イベントがあります。 + | 退会をお考えの場合、イベントの進行に影響がないよう、任意で他の参加者に主催を引き継ぐことを推奨します。 + | 退会手続きを完了する前に、 + = link_to 'こちら', regular_events_path + | からイベント管理を行ってください。 .form-item = f.label :retire_reasons, '退会の理由を教えてください(複数選択可)', class: 'a-form-label' .checkboxes From 94c2bc0465f0f5e2297f9408fb79d947e75bda46 Mon Sep 17 00:00:00 2001 From: machida Date: Tue, 21 Nov 2023 02:27:01 +0900 Subject: [PATCH 05/21] =?UTF-8?q?=E9=80=80=E4=BC=9A=E3=80=81=E4=BC=91?= =?UTF-8?q?=E4=BC=9A=E6=99=82=E3=81=AE=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E7=AE=A1=E7=90=86=E8=80=85=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AE=E5=BE=AE?= =?UTF-8?q?=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/hibernation/new.html.slim | 10 +++++++--- app/views/retirement/new.html.slim | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/views/hibernation/new.html.slim b/app/views/hibernation/new.html.slim index 9b6ee13b2ad..2fa508b6b4f 100644 --- a/app/views/hibernation/new.html.slim +++ b/app/views/hibernation/new.html.slim @@ -78,10 +78,14 @@ hr.a-border .a-short-text.is-sm p |ご自身が主催者である定期イベントがあります。 + br | 休会をお考えの場合、イベントの進行に影響がないよう、任意で他の参加者に主催を引き継ぐことを推奨します。 - | 休会手続きを完了する前に、 - = link_to 'こちら', regular_events_path - | からイベント管理を行なってください。 + | 休会手続きを完了する前に、以下のリンク先でイベント設定変更を行なってください。 + ul + - current_user.regular_events.each do |event| + li + = link_to edit_regular_event_path(event), target: '_blank', rel: 'noopener' do + | 定期イベント「#{event.title}」の設定変更 .form-item label.a-form-label.is-required diff --git a/app/views/retirement/new.html.slim b/app/views/retirement/new.html.slim index 436712c742e..93124aab0c0 100644 --- a/app/views/retirement/new.html.slim +++ b/app/views/retirement/new.html.slim @@ -22,10 +22,16 @@ hr.a-border .a-short-text.is-sm p |ご自身が主催者である定期イベントがあります。 + br | 退会をお考えの場合、イベントの進行に影響がないよう、任意で他の参加者に主催を引き継ぐことを推奨します。 | 退会手続きを完了する前に、 - = link_to 'こちら', regular_events_path - | からイベント管理を行ってください。 + | 以下のリンク先でイベント設定変更を行なってください。 + ul + - current_user.regular_events.each do |event| + li + = link_to edit_regular_event_path(event), target: '_blank', rel: 'noopener' do + | 定期イベント「#{event.title}」の設定変更 + .form-item = f.label :retire_reasons, '退会の理由を教えてください(複数選択可)', class: 'a-form-label' .checkboxes From 746373904d3208345001d3975be020968c6996ee Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:51:50 +0900 Subject: [PATCH 06/21] =?UTF-8?q?.card-list-item=E3=81=AE=E8=A6=81?= =?UTF-8?q?=E7=B4=A0=E6=95=B0=E3=82=928=E5=80=8B=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/regular_events_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/regular_events_test.rb b/test/system/regular_events_test.rb index 8acb4239798..b79fdd9c8ec 100644 --- a/test/system/regular_events_test.rb +++ b/test/system/regular_events_test.rb @@ -180,7 +180,7 @@ class RegularEventsTest < ApplicationSystemTestCase visit_with_auth regular_events_path, 'kimura' assert_selector '.card-list-item', count: 25 visit regular_events_path(page: 2) - assert_selector '.card-list-item', count: 7 + assert_selector '.card-list-item', count: 8 end test 'create a regular event for all students and trainees' do From ae2efb4a87f6af916f2ec565f04de03f7cfd4a1c Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 21 Nov 2023 19:13:10 +0900 Subject: [PATCH 07/21] =?UTF-8?q?.card-list-item=E3=81=AE=E8=A6=81?= =?UTF-8?q?=E7=B4=A0=E6=95=B0=E3=82=9215=E5=80=8B=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/regular_events_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/regular_events_test.rb b/test/system/regular_events_test.rb index b79fdd9c8ec..670e79910e1 100644 --- a/test/system/regular_events_test.rb +++ b/test/system/regular_events_test.rb @@ -173,7 +173,7 @@ class RegularEventsTest < ApplicationSystemTestCase test 'show listing not finished regular events' do visit_with_auth regular_events_path(target: 'not_finished'), 'kimura' - assert_selector '.card-list-item', count: 14 + assert_selector '.card-list-item', count: 15 end test 'show listing all regular events' do From 47beb79da4ee1f57a0f1720864a484f5e599d1a0 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:03:32 +0900 Subject: [PATCH 08/21] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 2 +- test/models/user_test.rb | 7 ++++--- test/system/retirement_test.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 491b4a54cab..50ca8db2deb 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -159,6 +159,6 @@ class RegularEventTest < ActiveSupport::TestCase test '#assign_admin_as_organizer_if_none' do regular_event = regular_events(:regular_event33) regular_event.assign_admin_as_organizer_if_none - assert User.find_by(login_name: 'komagata'), regular_event.organizers[0] + assert_equal User.find_by(login_name: 'komagata'), regular_event.organizers[0] end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6c11ce92350..0bca8cca749 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -681,9 +681,10 @@ class UserTest < ActiveSupport::TestCase test '#delete_organizer' do user = users(:hajime) - user.delete_organizer - event = regular_events(:regular_event4) - assert_not event.organizers.include?(user) + + assert_changes -> { event.organizers.include?(user) }, from: true, to: false do + user.delete_organizer + end end end diff --git a/test/system/retirement_test.rb b/test/system/retirement_test.rb index a35521a25e8..de8b20262cc 100644 --- a/test/system/retirement_test.rb +++ b/test/system/retirement_test.rb @@ -186,7 +186,7 @@ class RetirementTest < ApplicationSystemTestCase assert_equal 'FJORD BOOT CAMP(フィヨルドブートキャンプ)', title end - test 'retirement with event organizer' do + test 'retire with event organizer' do visit_with_auth new_retirement_path, 'hajime' find('label', text: 'とても良い').click click_on '退会する' From 537bdf6e4dd28d2bc9f7db82f1b62a6035bd1925 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:41:22 +0900 Subject: [PATCH 09/21] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E9=80=80=E4=BC=9A=E6=99=82=E3=81=AE=E3=82=A4=E3=83=99=E3=83=B3?= =?UTF-8?q?=E3=83=88=E4=B8=BB=E5=82=AC=E8=80=85=E5=89=B2=E3=82=8A=E5=BD=93?= =?UTF-8?q?=E3=81=A6=E5=87=A6=E7=90=86=E3=82=92Organizer=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 2 +- app/controllers/retirement_controller.rb | 2 +- app/models/organizer.rb | 6 ++++++ app/models/user.rb | 9 ++------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index c2e43900cb2..50bee6e37b1 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,7 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins - current_user.delete_organizer + current_user.delete_all_organizer logout redirect_to hibernation_path else diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index 5f115c58de7..c51aa7b1aef 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,7 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user - current_user.delete_organizer + current_user.delete_all_organizer Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now diff --git a/app/models/organizer.rb b/app/models/organizer.rb index 8392e284141..bf6c0ae6149 100644 --- a/app/models/organizer.rb +++ b/app/models/organizer.rb @@ -5,4 +5,10 @@ class Organizer < ApplicationRecord belongs_to :regular_event validates :user_id, uniqueness: { scope: :regular_event_id } + + def delete_and_assign_new + event = regular_event + delete + event.assign_admin_as_organizer_if_none + end end diff --git a/app/models/user.rb b/app/models/user.rb index fb2a7a97b8d..02eb9a23a73 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -755,13 +755,8 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end - def delete_organizer - organizers = self.organizers - organizers.each do |organizer| - event = organizer.regular_event - organizer.delete - event.assign_admin_as_organizer_if_none - end + def delete_all_organizer + organizers.each(&:delete_and_assign_new) end private From 92ec8f12fb58a3ab6d32a19b315e4347bcc62120 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:59:09 +0900 Subject: [PATCH 10/21] =?UTF-8?q?=E8=A4=87=E6=95=B0=E5=BD=A2=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 2 +- app/controllers/retirement_controller.rb | 2 +- app/models/user.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index 50bee6e37b1..374c0881ed1 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,7 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins - current_user.delete_all_organizer + current_user.delete_all_organizers logout redirect_to hibernation_path else diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index c51aa7b1aef..c9267a279e9 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,7 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user - current_user.delete_all_organizer + current_user.delete_all_organizers Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now diff --git a/app/models/user.rb b/app/models/user.rb index 02eb9a23a73..1c2175923d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -755,7 +755,7 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end - def delete_all_organizer + def delete_all_organizers organizers.each(&:delete_and_assign_new) end From c5e4817a8fa43282a48b1a44f4a8dcbe49af2ace Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:00:16 +0900 Subject: [PATCH 11/21] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/organizer_test.rb | 16 ++++++++++++++++ test/models/user_test.rb | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/models/organizer_test.rb diff --git a/test/models/organizer_test.rb b/test/models/organizer_test.rb new file mode 100644 index 00000000000..6dde4da1b3a --- /dev/null +++ b/test/models/organizer_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'test_helper' + +class OrganizerTest < ActiveSupport::TestCase + test '#delete_and_assign_new' do + organizer = organizers(:organizer12) + event = organizer.regular_event + + assert_changes -> { Organizer.where(regular_event: event, user: organizer.user).exists? }, from: true, to: false do + organizer.delete_and_assign_new + end + + assert Organizer.where(regular_event: event).exists? + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 0bca8cca749..65f7ae9ae94 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -679,12 +679,11 @@ class UserTest < ActiveSupport::TestCase assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets) end - test '#delete_organizer' do + test '#delete_all_organizers' do user = users(:hajime) - event = regular_events(:regular_event4) - assert_changes -> { event.organizers.include?(user) }, from: true, to: false do - user.delete_organizer + assert_changes -> { Organizer.where(user: user).exists? }, from: true, to: false do + user.delete_all_organizers end end end From bae6ee6f0b3616ba6b9c71bd8f6094429dab3448 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Thu, 14 Dec 2023 21:16:50 +0900 Subject: [PATCH 12/21] =?UTF-8?q?komagata=E3=82=92=E5=AE=9A=E6=95=B0?= =?UTF-8?q?=E3=81=AB=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 2 +- app/models/user.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 48e62aebd52..449a2449b19 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -188,7 +188,7 @@ def remove_event(events_arr, id) def assign_admin_as_organizer_if_none return if organizers.exists? - admin_user = User.find_by(login_name: 'komagata') + admin_user = User.find_by(login_name: User::DEFAULT_ADMIN_LOGIN_NAME) Organizer.new(user: admin_user, regular_event: self).save if admin_user end diff --git a/app/models/user.rb b/app/models/user.rb index 1c2175923d1..5404c1a4ac4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,6 +19,7 @@ class User < ApplicationRecord 'adviser' => :advisers, 'trainee' => :trainees }.freeze + DEFAULT_ADMIN_LOGIN_NAME = 'komagata' enum job: { student: 0, From a53b5a7a7e7575f9794776df39b094cbe651e557 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:15:03 +0900 Subject: [PATCH 13/21] =?UTF-8?q?RegularEvent=E3=83=A2=E3=83=87=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/regular_events.yml | 11 ----------- test/models/regular_event_test.rb | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/fixtures/regular_events.yml b/test/fixtures/regular_events.yml index 3673ecd50da..3c15d904384 100644 --- a/test/fixtures/regular_events.yml +++ b/test/fixtures/regular_events.yml @@ -155,14 +155,3 @@ regular_event32: user: komagata category: 0 published_at: "2023-08-01 00:00:00" - -regular_event33: - title: 主催者のいないイベント - description: 主催者のいないイベント - finished: false - hold_national_holiday: false - start_at: <%= Time.zone.local(2020, 1, 1, 21, 0, 0) %> - end_at: <%= Time.zone.local(2020, 1, 1, 22, 0, 0) %> - user: kimura - category: 0 - published_at: "2023-08-01 00:00:00" diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index 50ca8db2deb..b5fcc531812 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -157,8 +157,19 @@ class RegularEventTest < ActiveSupport::TestCase end test '#assign_admin_as_organizer_if_none' do - regular_event = regular_events(:regular_event33) + regular_event = RegularEvent.new( + title: '主催者のいないイベント', + description: '主催者のいないイベント', + finished: false, + hold_national_holiday: false, + start_at: Time.zone.local(2020, 1, 1, 21, 0, 0), + end_at: Time.zone.local(2020, 1, 1, 22, 0, 0), + user: users(:kimura), + category: 0, + published_at: '2023-08-01 00:00:00' + ) + regular_event.save(validate: false) regular_event.assign_admin_as_organizer_if_none - assert_equal User.find_by(login_name: 'komagata'), regular_event.organizers[0] + assert_equal User.find_by(login_name: User::DEFAULT_ADMIN_LOGIN_NAME), regular_event.organizers.first end end From 7c9f7b4c72c48242faca6b57cb1fc6e8e145f23e Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:00:40 +0900 Subject: [PATCH 14/21] =?UTF-8?q?count=E3=81=AE=E6=95=B0=E3=82=92=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/regular_events_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/regular_events_test.rb b/test/system/regular_events_test.rb index 670e79910e1..b79fdd9c8ec 100644 --- a/test/system/regular_events_test.rb +++ b/test/system/regular_events_test.rb @@ -173,7 +173,7 @@ class RegularEventsTest < ApplicationSystemTestCase test 'show listing not finished regular events' do visit_with_auth regular_events_path(target: 'not_finished'), 'kimura' - assert_selector '.card-list-item', count: 15 + assert_selector '.card-list-item', count: 14 end test 'show listing all regular events' do From 54c6f5c06c6a8fff5b00d8b3e62d6c518c2bd73c Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:09:49 +0900 Subject: [PATCH 15/21] =?UTF-8?q?=E5=AE=9A=E6=95=B0=E5=90=8D=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 2 +- app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 449a2449b19..7b89d5b9fbf 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -188,7 +188,7 @@ def remove_event(events_arr, id) def assign_admin_as_organizer_if_none return if organizers.exists? - admin_user = User.find_by(login_name: User::DEFAULT_ADMIN_LOGIN_NAME) + admin_user = User.find_by(login_name: User::DEFAULT_REGULAR_EVENT_ORGANIZER) Organizer.new(user: admin_user, regular_event: self).save if admin_user end diff --git a/app/models/user.rb b/app/models/user.rb index 5404c1a4ac4..b768145a024 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ class User < ApplicationRecord 'adviser' => :advisers, 'trainee' => :trainees }.freeze - DEFAULT_ADMIN_LOGIN_NAME = 'komagata' + DEFAULT_REGULAR_EVENT_ORGANIZER = 'komagata' enum job: { student: 0, From 1d64dd5df81b8a42eeedbd5bcf660e8ba389ffa0 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:27:33 +0900 Subject: [PATCH 16/21] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AB?= =?UTF-8?q?=E5=90=AB=E3=81=BE=E3=82=8C=E3=82=8B=E5=AE=9A=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/regular_event_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index b5fcc531812..f99016d7162 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -170,6 +170,6 @@ class RegularEventTest < ActiveSupport::TestCase ) regular_event.save(validate: false) regular_event.assign_admin_as_organizer_if_none - assert_equal User.find_by(login_name: User::DEFAULT_ADMIN_LOGIN_NAME), regular_event.organizers.first + assert_equal User.find_by(login_name: User::DEFAULT_REGULAR_EVENT_ORGANIZER), regular_event.organizers.first end end From 72dd86d59a7e7504128f0aa0024c66bd520d6819 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 17 Dec 2023 00:14:00 +0900 Subject: [PATCH 17/21] =?UTF-8?q?=E4=BC=91=E4=BC=9A=E3=81=BE=E3=81=9F?= =?UTF-8?q?=E3=81=AF=E9=80=80=E4=BC=9A=E3=81=97=E3=81=9F=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=AE=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=AE=E4=B8=BB=E5=82=AC=E8=80=85=E3=82=92?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E3=81=AB=E8=87=AA=E5=8B=95=E3=81=A7?= =?UTF-8?q?=E5=89=B2=E3=82=8A=E5=BD=93=E3=81=A6=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 7 ++++++- app/controllers/retirement_controller.rb | 7 ++++++- app/models/organizer.rb | 6 ------ app/models/user.rb | 4 ---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index 374c0881ed1..87486d7dfd3 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,7 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins - current_user.delete_all_organizers + assign_admin_as_organizer logout redirect_to hibernation_path else @@ -52,4 +52,9 @@ def notify_to_mentors_and_admins def notify_to_chat DiscordNotifier.with(sender: current_user).hibernated.notify_now end + + def assign_admin_as_organizer + current_user.organizers.destroy_all + current_user.regular_events.each(&:assign_admin_as_organizer_if_none) + end end diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index c9267a279e9..77c19ab3726 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,7 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user - current_user.delete_all_organizers + assign_admin_as_organizer Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now @@ -52,4 +52,9 @@ def notify_to_mentors ActivityDelivery.with(sender: current_user, receiver: mentor_user).notify(:retired) end end + + def assign_admin_as_organizer + current_user.organizers.destroy_all + current_user.regular_events.each(&:assign_admin_as_organizer_if_none) + end end diff --git a/app/models/organizer.rb b/app/models/organizer.rb index bf6c0ae6149..8392e284141 100644 --- a/app/models/organizer.rb +++ b/app/models/organizer.rb @@ -5,10 +5,4 @@ class Organizer < ApplicationRecord belongs_to :regular_event validates :user_id, uniqueness: { scope: :regular_event_id } - - def delete_and_assign_new - event = regular_event - delete - event.assign_admin_as_organizer_if_none - end end diff --git a/app/models/user.rb b/app/models/user.rb index b768145a024..45edcef0a6e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -756,10 +756,6 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end - def delete_all_organizers - organizers.each(&:delete_and_assign_new) - end - private def password_required? From 0fc35c1281494cf8b30e2420e58d270349debfd9 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 17 Dec 2023 11:13:56 +0900 Subject: [PATCH 18/21] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/organizer_test.rb | 16 ---------------- test/models/user_test.rb | 8 -------- 2 files changed, 24 deletions(-) delete mode 100644 test/models/organizer_test.rb diff --git a/test/models/organizer_test.rb b/test/models/organizer_test.rb deleted file mode 100644 index 6dde4da1b3a..00000000000 --- a/test/models/organizer_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class OrganizerTest < ActiveSupport::TestCase - test '#delete_and_assign_new' do - organizer = organizers(:organizer12) - event = organizer.regular_event - - assert_changes -> { Organizer.where(regular_event: event, user: organizer.user).exists? }, from: true, to: false do - organizer.delete_and_assign_new - end - - assert Organizer.where(regular_event: event).exists? - end -end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 65f7ae9ae94..10fd634aa2a 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -678,12 +678,4 @@ class UserTest < ActiveSupport::TestCase assert_equal User.students_and_trainees, User.users_role(not_scope_name, allowed_targets: allowed_targets, default_target: 'student_and_trainee') assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets) end - - test '#delete_all_organizers' do - user = users(:hajime) - - assert_changes -> { Organizer.where(user: user).exists? }, from: true, to: false do - user.delete_all_organizers - end - end end From 11f9b95d91f057f6d0eff66e25128c1fe26cc23e Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 17 Dec 2023 19:07:10 +0900 Subject: [PATCH 19/21] =?UTF-8?q?=E4=BC=91=E4=BC=9A=E3=81=BE=E3=81=9F?= =?UTF-8?q?=E3=81=AF=E9=80=80=E4=BC=9A=E3=81=97=E3=81=9F=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=AE=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=AE=E4=B8=BB=E5=82=AC=E8=80=85=E3=82=92?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E3=81=AB=E8=87=AA=E5=8B=95=E3=81=A7?= =?UTF-8?q?=E5=89=B2=E3=82=8A=E5=BD=93=E3=81=A6=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E6=88=BB=E3=81=97=E3=80=81=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E5=90=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 7 +------ app/controllers/retirement_controller.rb | 7 +------ app/models/organizer.rb | 6 ++++++ app/models/user.rb | 4 ++++ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index 87486d7dfd3..42b4533efcb 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,7 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins - assign_admin_as_organizer + current_user.organizers_delete_and_assign_new logout redirect_to hibernation_path else @@ -52,9 +52,4 @@ def notify_to_mentors_and_admins def notify_to_chat DiscordNotifier.with(sender: current_user).hibernated.notify_now end - - def assign_admin_as_organizer - current_user.organizers.destroy_all - current_user.regular_events.each(&:assign_admin_as_organizer_if_none) - end end diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index 77c19ab3726..7638ea2d747 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,7 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user - assign_admin_as_organizer + current_user.organizers_delete_and_assign_new Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now @@ -52,9 +52,4 @@ def notify_to_mentors ActivityDelivery.with(sender: current_user, receiver: mentor_user).notify(:retired) end end - - def assign_admin_as_organizer - current_user.organizers.destroy_all - current_user.regular_events.each(&:assign_admin_as_organizer_if_none) - end end diff --git a/app/models/organizer.rb b/app/models/organizer.rb index 8392e284141..bf6c0ae6149 100644 --- a/app/models/organizer.rb +++ b/app/models/organizer.rb @@ -5,4 +5,10 @@ class Organizer < ApplicationRecord belongs_to :regular_event validates :user_id, uniqueness: { scope: :regular_event_id } + + def delete_and_assign_new + event = regular_event + delete + event.assign_admin_as_organizer_if_none + end end diff --git a/app/models/user.rb b/app/models/user.rb index 45edcef0a6e..d18982235b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -756,6 +756,10 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end + def organizers_delete_and_assign_new + organizers.each(&:delete_and_assign_new) + end + private def password_required? From e10c4a716b7d1e62431cb62540f6d93aae455ae7 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sun, 17 Dec 2023 19:20:05 +0900 Subject: [PATCH 20/21] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E6=88=BB?= =?UTF-8?q?=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/organizer_test.rb | 16 ++++++++++++++++ test/models/user_test.rb | 8 ++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/models/organizer_test.rb diff --git a/test/models/organizer_test.rb b/test/models/organizer_test.rb new file mode 100644 index 00000000000..6dde4da1b3a --- /dev/null +++ b/test/models/organizer_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'test_helper' + +class OrganizerTest < ActiveSupport::TestCase + test '#delete_and_assign_new' do + organizer = organizers(:organizer12) + event = organizer.regular_event + + assert_changes -> { Organizer.where(regular_event: event, user: organizer.user).exists? }, from: true, to: false do + organizer.delete_and_assign_new + end + + assert Organizer.where(regular_event: event).exists? + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 10fd634aa2a..a1484f43081 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -678,4 +678,12 @@ class UserTest < ActiveSupport::TestCase assert_equal User.students_and_trainees, User.users_role(not_scope_name, allowed_targets: allowed_targets, default_target: 'student_and_trainee') assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets) end + + test '#organizers_delete_and_assign_new' do + user = users(:hajime) + + assert_changes -> { Organizer.where(user: user).exists? }, from: true, to: false do + user.organizers_delete_and_assign_new + end + end end From a62971b873825c2ae9ce8efe243542aa2eb14b10 Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:02:04 +0900 Subject: [PATCH 21/21] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 2 +- app/controllers/retirement_controller.rb | 2 +- app/models/user.rb | 2 +- test/models/user_test.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index 42b4533efcb..cdea0cabdcf 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -18,7 +18,7 @@ def create destroy_subscription! notify_to_chat notify_to_mentors_and_admins - current_user.organizers_delete_and_assign_new + current_user.delete_and_assign_new_organizer logout redirect_to hibernation_path else diff --git a/app/controllers/retirement_controller.rb b/app/controllers/retirement_controller.rb index 7638ea2d747..9c45bc1e968 100644 --- a/app/controllers/retirement_controller.rb +++ b/app/controllers/retirement_controller.rb @@ -12,7 +12,7 @@ def create current_user.retired_on = Date.current if current_user.save(context: :retirement) user = current_user - current_user.organizers_delete_and_assign_new + current_user.delete_and_assign_new_organizer Newspaper.publish(:retirement_create, user) begin UserMailer.retire(user).deliver_now diff --git a/app/models/user.rb b/app/models/user.rb index d18982235b4..def7dd8db00 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -756,7 +756,7 @@ def become_watcher!(watchable) watches.find_or_create_by!(watchable:) end - def organizers_delete_and_assign_new + def delete_and_assign_new_organizer organizers.each(&:delete_and_assign_new) end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index a1484f43081..5dc836a211d 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -679,11 +679,11 @@ class UserTest < ActiveSupport::TestCase assert_empty User.users_role(not_scope_name, allowed_targets: allowed_targets) end - test '#organizers_delete_and_assign_new' do + test '#delete_and_assign_new_organizer' do user = users(:hajime) assert_changes -> { Organizer.where(user: user).exists? }, from: true, to: false do - user.organizers_delete_and_assign_new + user.delete_and_assign_new_organizer end end end