From 81d4cde278e6246d3fa8ca06f549e5029478e005 Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Thu, 6 Aug 2020 16:22:57 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BB=96=E4=BA=BA=E3=81=B8=E3=81=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=81=8C=E8=A8=B1=E5=8F=AF=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AF=E3=82=BB?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E3=82=A2=E3=83=BC?= =?UTF-8?q?=E3=82=AB=E3=82=A4=E3=83=96=E3=81=97=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/session.go | 2 +- database/session_test.go | 46 ++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/database/session.go b/database/session.go index 761c0da5..3d33ca80 100644 --- a/database/session.go +++ b/database/session.go @@ -162,7 +162,7 @@ func (r *SessionRepository) StoreQueueTrack(ctx context.Context, queueTrack *ent //// - 作成から3日以上が経過している。もしくはArchiveが解除されてから3日以上が経過している func (r *SessionRepository) ArchiveSessionsForBatch() error { currentDateTime := time.Now().UTC() - if _, err := r.dbMap.Exec("UPDATE sessions SET state_type = 'ARCHIVED' WHERE state_type != 'ARCHIVED' AND expired_at < ?;", currentDateTime); err != nil { + if _, err := r.dbMap.Exec("UPDATE sessions SET state_type = 'ARCHIVED' WHERE allow_to_control_by_others = true AND state_type != 'ARCHIVED' AND expired_at < ?;", currentDateTime); err != nil { return fmt.Errorf("update session state_type to ARCHIVED: %w", err) } return nil diff --git a/database/session_test.go b/database/session_test.go index bba5cfda..4c61d89d 100644 --- a/database/session_test.go +++ b/database/session_test.go @@ -685,23 +685,36 @@ func TestSessionRepository_ArchiveSessionsForBatch(t *testing.T) { DisplayName: "existing_user_display_name", } oldSession := &sessionDTO{ - ID: "existing_session_id1", - Name: "existing_session_name", - CreatorID: "existing_user", - QueueHead: 0, - StateType: "PLAY", - DeviceID: "device_id", - ExpiredAt: time.Now().Add(-1 * 24 * time.Hour), + ID: "existing_session_id1", + Name: "existing_session_name", + CreatorID: "existing_user", + QueueHead: 0, + StateType: "PLAY", + DeviceID: "device_id", + ExpiredAt: time.Now().Add(-1 * 24 * time.Hour), + AllowToControlByOthers: true, } newSession := &sessionDTO{ - ID: "existing_session_id2", - Name: "existing_session_name", - CreatorID: "existing_user", - QueueHead: 0, - StateType: "PLAY", - DeviceID: "device_id", - ExpiredAt: time.Now().Add(1 * 24 * time.Hour), + ID: "existing_session_id2", + Name: "existing_session_name", + CreatorID: "existing_user", + QueueHead: 0, + StateType: "PLAY", + DeviceID: "device_id", + ExpiredAt: time.Now().Add(1 * 24 * time.Hour), + AllowToControlByOthers: true, + } + + notAllowedSessions := &sessionDTO{ + ID: "existing_session_id3", + Name: "existing_session_name", + CreatorID: "existing_user", + QueueHead: 0, + StateType: "PLAY", + DeviceID: "device_id", + ExpiredAt: time.Now().Add(-1 * 24 * time.Hour), + AllowToControlByOthers: false, } tests := []struct { @@ -719,6 +732,11 @@ func TestSessionRepository_ArchiveSessionsForBatch(t *testing.T) { session: oldSession, wantState: "ARCHIVED", }, + { + name: "古くても他人の操作を許可していないsessionはARCHIVEされない", + session: notAllowedSessions, + wantState: "PLAY", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {