Skip to content

Commit

Permalink
Merge pull request #187 from camphor-/change-not-to-archive-non-allow…
Browse files Browse the repository at this point in the history
…ed-session

他人への操作が許可されていないときはセッションをアーカイブしない
  • Loading branch information
p1ass authored Aug 8, 2020
2 parents fbafd5c + 81d4cde commit f630963
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion database/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 32 additions & 14 deletions database/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit f630963

Please sign in to comment.