Skip to content

Commit dc8b536

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/getkin/kin-openapi-0.135.0
2 parents 8297fc9 + 187e68c commit dc8b536

7 files changed

Lines changed: 128 additions & 6 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
1616
go build -o /anke-to -ldflags "-s -w"
1717

1818
# run
19-
FROM alpine:3.23.3
19+
FROM alpine:3.23.4
2020
WORKDIR /app
2121

2222
RUN apk --update --no-cache add tzdata \

controller/adapter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func questionnaireInfo2questionnaireSummary(questionnaireInfo model.Questionnair
2828
IsTargetingMe: questionnaireInfo.IsTargeted,
2929
ModifiedAt: questionnaireInfo.ModifiedAt,
3030
QuestionnaireId: questionnaireInfo.ID,
31+
ResponseViewableBy: convertResSharedTo(questionnaireInfo.ResSharedTo),
3132
Title: questionnaireInfo.Title,
3233
}
3334
if respondedDateTimeByMe.Valid {

controller/questionnaire.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func (q *Questionnaire) PostQuestionnaire(c echo.Context, params openapi.PostQue
470470
append(allTargetUsers, targetGroupNames...),
471471
)
472472

473-
if params.ResponseDueDateTime != nil {
473+
if params.ResponseDueDateTime != nil && params.IsPublished {
474474
dueDateTime := responseDueDateTime.Time
475475
err = q.PushReminder(questionnaireID, &dueDateTime)
476476
if err != nil {
@@ -922,7 +922,7 @@ func (q *Questionnaire) EditQuestionnaire(c echo.Context, questionnaireID int, p
922922
c.Logger().Errorf("failed to delete reminder: %+v", err)
923923
return err
924924
}
925-
if params.ResponseDueDateTime != nil {
925+
if params.ResponseDueDateTime != nil && params.IsPublished {
926926
dueDateTime := responseDueDateTime.Time
927927
err = q.PushReminder(questionnaireID, &dueDateTime)
928928
if err != nil {

controller/questionnaire_test.go

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,17 @@ func TestPostQuestionnaire(t *testing.T) {
655655
isErr bool
656656
err error
657657
normalizedDueDate bool
658+
hasReminder *bool
658659
}
659660
type test struct {
660661
description string
661662
args
662663
expect
663664
}
664665

666+
hasReminderTrue := true
667+
hasReminderFalse := false
668+
665669
responseDueDateTimeMinus := time.Now().Add(-24 * time.Hour)
666670
responseDueDateTimeNearlyNowPast := time.Now().Add(-3 * time.Second)
667671
responseDueDateTimePlus := time.Now().Add(24 * time.Hour)
@@ -723,6 +727,9 @@ func TestPostQuestionnaire(t *testing.T) {
723727
Title: "第1回集会らん☆ぷろ募集アンケート",
724728
},
725729
},
730+
expect: expect{
731+
hasReminder: &hasReminderTrue,
732+
},
726733
},
727734
{
728735
description: "invalid response due date time",
@@ -1003,6 +1010,33 @@ func TestPostQuestionnaire(t *testing.T) {
10031010
},
10041011
},
10051012
},
1013+
{
1014+
description: "not published with response due date time",
1015+
args: args{
1016+
params: openapi.PostQuestionnaireJSONRequestBody{
1017+
Admin: sampleAdmin,
1018+
Description: "第1回集会らん☆ぷろ参加者募集",
1019+
IsDuplicateAnswerAllowed: true,
1020+
IsAnonymous: false,
1021+
IsPublished: false,
1022+
Questions: []openapi.NewQuestion{
1023+
sampleQuestionSettingsText,
1024+
sampleQuestionSettingsTextLong,
1025+
sampleQuestionSettingsNumber,
1026+
sampleQuestionSettingsSingleChoice,
1027+
sampleQuestionSettingsMultipleChoice,
1028+
sampleQeustionsettingsScale,
1029+
},
1030+
ResponseDueDateTime: &responseDueDateTimePlus,
1031+
ResponseViewableBy: "anyone",
1032+
Target: sampleTarget,
1033+
Title: "第1回集会らん☆ぷろ募集アンケート",
1034+
},
1035+
},
1036+
expect: expect{
1037+
hasReminder: &hasReminderFalse,
1038+
},
1039+
},
10061040
{
10071041
description: "invalid question settings number",
10081042
args: args{
@@ -1153,6 +1187,12 @@ func TestPostQuestionnaire(t *testing.T) {
11531187
assertion.Equal(testCase.args.params.Target.Groups, questionnaireDetail.Target.Groups, "target groups not equal")
11541188

11551189
assertion.Equal(testCase.args.params.Title, questionnaireDetail.Title, "title not equal")
1190+
1191+
if testCase.expect.hasReminder != nil {
1192+
remindStatus, err := re.CheckRemindStatus(questionnaireDetail.QuestionnaireId)
1193+
assertion.NoError(err, testCase.description, "no error checking remind status")
1194+
assertion.Equal(*testCase.expect.hasReminder, remindStatus, testCase.description, "reminder status")
1195+
}
11561196
}
11571197
}
11581198

@@ -1260,15 +1300,19 @@ func TestEditQuestionnaire(t *testing.T) {
12601300
isNewQuestion []bool
12611301
}
12621302
type expect struct {
1263-
isErr bool
1264-
err error
1303+
isErr bool
1304+
err error
1305+
hasReminder *bool
12651306
}
12661307
type test struct {
12671308
description string
12681309
args
12691310
expect
12701311
}
12711312

1313+
hasReminderTrue := true
1314+
hasReminderFalse := false
1315+
12721316
responseDueDateTimeMinus := time.Now().Add(-24 * time.Hour)
12731317
responseDueDateTimePlus := time.Now().Add(24 * time.Hour)
12741318

@@ -1362,6 +1406,9 @@ func TestEditQuestionnaire(t *testing.T) {
13621406
},
13631407
isNewQuestion: []bool{false, false, false, false, false, false},
13641408
},
1409+
expect: expect{
1410+
hasReminder: &hasReminderTrue,
1411+
},
13651412
},
13661413
{
13671414
description: "invalid question id",
@@ -1647,6 +1694,34 @@ func TestEditQuestionnaire(t *testing.T) {
16471694
isNewQuestion: []bool{false, false, false, false, false, false},
16481695
},
16491696
},
1697+
{
1698+
description: "not published with response due date time",
1699+
args: args{
1700+
params: openapi.PostQuestionnaireJSONRequestBody{
1701+
Admin: sampleAdmin,
1702+
Description: "第1回集会らん☆ぷろ参加者募集",
1703+
IsDuplicateAnswerAllowed: true,
1704+
IsAnonymous: false,
1705+
IsPublished: false,
1706+
Questions: []openapi.NewQuestion{
1707+
sampleQuestionSettingsText,
1708+
sampleQuestionSettingsTextLong,
1709+
sampleQuestionSettingsNumber,
1710+
sampleQuestionSettingsSingleChoice,
1711+
sampleQuestionSettingsMultipleChoice,
1712+
sampleQeustionsettingsScale,
1713+
},
1714+
ResponseDueDateTime: &responseDueDateTimePlus,
1715+
ResponseViewableBy: "anyone",
1716+
Target: sampleTarget,
1717+
Title: "第1回集会らん☆ぷろ募集アンケート",
1718+
},
1719+
isNewQuestion: []bool{false, false, false, false, false, false},
1720+
},
1721+
expect: expect{
1722+
hasReminder: &hasReminderFalse,
1723+
},
1724+
},
16501725
{
16511726
description: "invalid question settings number",
16521727
args: args{
@@ -1855,6 +1930,12 @@ func TestEditQuestionnaire(t *testing.T) {
18551930
questionnaireDetailExpected.Questions[i].CreatedAt = questionnaireDetailEdited.Questions[i].CreatedAt
18561931
}
18571932
assertion.Equal(questionnaireDetailExpected, questionnaireDetailEdited, testCase.description, "questionnaireDetail")
1933+
1934+
if testCase.expect.hasReminder != nil {
1935+
remindStatus, err := re.CheckRemindStatus(questionnaireDetail.QuestionnaireId)
1936+
assertion.NoError(err, testCase.description, "no error checking remind status")
1937+
assertion.Equal(*testCase.expect.hasReminder, remindStatus, testCase.description, "reminder status")
1938+
}
18581939
}
18591940
}
18601941

controller/reminder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func reminderAction(questionnaireID int, leftTimeText string) error {
206206
return err
207207
}
208208

209+
if !questionnaire.IsPublished {
210+
return nil
211+
}
212+
209213
reminderTargetOverrides, err := model.NewReminderTarget().GetReminderTargets(ctx, questionnaireID)
210214
if err != nil {
211215
return err

controller/reminder_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package controller
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"errors"
7+
"net/http"
8+
"net/http/httptest"
59
"testing"
610
"time"
711

12+
"github.com/labstack/echo/v4"
813
"github.com/stretchr/testify/assert"
914
"github.com/stretchr/testify/require"
15+
"github.com/traPtitech/anke-to/openapi"
1016
)
1117

1218
// nthJob returns the nth job (0-indexed) from the btree in ascending order.
@@ -462,3 +468,33 @@ func TestPop(t *testing.T) {
462468
}
463469
}
464470
}
471+
472+
func TestReminderActionUnpublished(t *testing.T) {
473+
responseDueDateTimePlus := time.Now().Add(24 * time.Hour)
474+
params := openapi.PostQuestionnaireJSONRequestBody{
475+
Admin: sampleAdmin,
476+
Description: "リマインダーテスト用アンケート",
477+
IsDuplicateAnswerAllowed: false,
478+
IsAnonymous: false,
479+
IsPublished: false,
480+
Questions: []openapi.NewQuestion{},
481+
ResponseDueDateTime: &responseDueDateTimePlus,
482+
ResponseViewableBy: "anyone",
483+
Target: sampleTarget,
484+
Title: "未公開リマインダーテスト",
485+
}
486+
487+
e := echo.New()
488+
body, err := json.Marshal(params)
489+
require.NoError(t, err)
490+
req := httptest.NewRequest(http.MethodPost, "/questionnaires", bytes.NewReader(body))
491+
rec := httptest.NewRecorder()
492+
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
493+
ctx := e.NewContext(req, rec)
494+
495+
detail, err := q.PostQuestionnaire(ctx, params)
496+
require.NoError(t, err)
497+
498+
err = reminderAction(detail.QuestionnaireId, "5分")
499+
assert.NoError(t, err, "reminderAction should return nil for unpublished questionnaire")
500+
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func main() {
4343

4444
api.Reminder.Wg.Add(1)
4545
go func() {
46-
e.Use(middleware.Logger())
46+
e.Use(middleware.RequestLogger())
4747
e.Use(middleware.Recover())
4848

4949
swagger, err := openapi.GetSwagger()

0 commit comments

Comments
 (0)