Skip to content

Commit 110e7fb

Browse files
tybalexthedadams
andauthored
feat: support deletion of event series. (#621)
* feat: support deletion of event series. * Update microsoft365/outlook/calendar/pkg/commands/deleteEvent.go Co-authored-by: Donnie Adams <[email protected]> * Update microsoft365/outlook/calendar/pkg/graph/events.go Co-authored-by: Donnie Adams <[email protected]> * Update microsoft365/outlook/calendar/main.go Co-authored-by: Donnie Adams <[email protected]> * fix: fix typo --------- Co-authored-by: Donnie Adams <[email protected]>
1 parent 7fcca31 commit 110e7fb

File tree

9 files changed

+39
-15
lines changed

9 files changed

+39
-15
lines changed

microsoft365/outlook/calendar/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func main() {
118118
os.Exit(1)
119119
}
120120
case "deleteEvent":
121-
if err := commands.DeleteEvent(context.Background(), os.Getenv("EVENT_ID"), os.Getenv("CALENDAR_ID"), graph.OwnerType(os.Getenv("OWNER_TYPE"))); err != nil {
121+
if err := commands.DeleteEvent(context.Background(), os.Getenv("EVENT_ID"), os.Getenv("CALENDAR_ID"), graph.OwnerType(os.Getenv("OWNER_TYPE")), os.Getenv("DELETE_SERIES") == "true"); err != nil {
122122
fmt.Println(err)
123123
os.Exit(1)
124124
}

microsoft365/outlook/calendar/pkg/commands/deleteEvent.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/obot-platform/tools/microsoft365/outlook/common/id"
1111
)
1212

13-
func DeleteEvent(ctx context.Context, eventID, calendarID string, owner graph.OwnerType) error {
13+
func DeleteEvent(ctx context.Context, eventID, calendarID string, owner graph.OwnerType, deleteSeries bool) error {
1414
trueEventID, err := id.GetOutlookID(ctx, eventID)
1515
if err != nil {
1616
return fmt.Errorf("failed to get outlook ID: %w", err)
@@ -29,9 +29,17 @@ func DeleteEvent(ctx context.Context, eventID, calendarID string, owner graph.Ow
2929
return fmt.Errorf("failed to create client: %w", err)
3030
}
3131

32-
if err := graph.DeleteEvent(ctx, c, trueEventID, trueCalendarID, owner); err != nil {
33-
return fmt.Errorf("failed to delete event: %w", err)
32+
if deleteSeries {
33+
if err := graph.DeleteEventSeries(ctx, c, trueEventID, trueCalendarID, owner); err != nil {
34+
return fmt.Errorf("failed to delete event series: %w", err)
35+
}
36+
fmt.Println("Event series deleted successfully")
37+
} else {
38+
if err := graph.DeleteEvent(ctx, c, trueEventID, trueCalendarID, owner); err != nil {
39+
return fmt.Errorf("failed to delete event: %w", err)
40+
} else {
41+
fmt.Println("Event deleted successfully")
42+
}
3443
}
35-
fmt.Println("Event deleted successfully")
3644
return nil
3745
}

microsoft365/outlook/calendar/pkg/commands/getEventAttachments.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"log"
77

88
"github.com/gptscript-ai/go-gptscript"
9+
"github.com/microsoftgraph/msgraph-sdk-go/models"
910
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/client"
1011
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/global"
1112
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/graph"
1213
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
1314
"github.com/obot-platform/tools/microsoft365/outlook/common/id"
14-
"github.com/microsoftgraph/msgraph-sdk-go/models"
1515
)
1616

1717
func GetEventAttachments(ctx context.Context, eventID, calendarID string, owner graph.OwnerType) error {

microsoft365/outlook/calendar/pkg/commands/listEvents.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"time"
77

88
"github.com/gptscript-ai/go-gptscript"
9+
"github.com/microsoftgraph/msgraph-sdk-go/models"
910
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/client"
1011
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/global"
1112
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/graph"
1213
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/printers"
1314
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
1415
"github.com/obot-platform/tools/microsoft365/outlook/common/id"
15-
"github.com/microsoftgraph/msgraph-sdk-go/models"
1616
)
1717

1818
func ListEvents(ctx context.Context, start, end time.Time) error {

microsoft365/outlook/calendar/pkg/commands/searchEvents.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"time"
88

99
"github.com/gptscript-ai/go-gptscript"
10+
"github.com/microsoftgraph/msgraph-sdk-go/models"
1011
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/client"
1112
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/global"
1213
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/graph"
1314
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/printers"
1415
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
1516
"github.com/obot-platform/tools/microsoft365/outlook/common/id"
16-
"github.com/microsoftgraph/msgraph-sdk-go/models"
1717
)
1818

1919
func SearchEvents(ctx context.Context, query string, start, end time.Time) error {

microsoft365/outlook/calendar/pkg/graph/calendar.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"fmt"
66
"time"
77

8-
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
98
msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go"
109
"github.com/microsoftgraph/msgraph-sdk-go/groups"
1110
"github.com/microsoftgraph/msgraph-sdk-go/models"
1211
"github.com/microsoftgraph/msgraph-sdk-go/users"
12+
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
1313
)
1414

1515
type CalendarInfo struct {

microsoft365/outlook/calendar/pkg/graph/events.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66
"time"
77

8-
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/recurrence"
9-
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
108
msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go"
119
"github.com/microsoftgraph/msgraph-sdk-go/groups"
1210
"github.com/microsoftgraph/msgraph-sdk-go/models"
1311
"github.com/microsoftgraph/msgraph-sdk-go/users"
12+
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/recurrence"
13+
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
1414
)
1515

1616
type CreateEventInfo struct {
@@ -197,6 +197,21 @@ func DeleteEvent(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, e
197197
return nil
198198
}
199199

200+
func DeleteEventSeries(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, eventID, calendarID string, owner OwnerType) error {
201+
event, err := GetEvent(ctx, client, eventID, calendarID, owner)
202+
if err != nil {
203+
return fmt.Errorf("failed to get the event to delete: %w", err)
204+
}
205+
206+
seriesMasterID := event.GetSeriesMasterId()
207+
if seriesMasterID == nil {
208+
fmt.Println("It appears that this is not a recurring event, so we will delete the single event")
209+
return DeleteEvent(ctx, client, eventID, calendarID, owner)
210+
}
211+
// delete the series master event
212+
return DeleteEvent(ctx, client, util.Deref(seriesMasterID), calendarID, owner)
213+
}
214+
200215
func AcceptEvent(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, eventID, calendarID string, owner OwnerType) error {
201216
requestBody := users.NewItemEventsItemAcceptPostRequestBody()
202217
requestBody.SetSendResponse(util.Ptr(true))

microsoft365/outlook/calendar/pkg/graph/groups.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package graph
33
import (
44
"context"
55

6-
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
76
msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go"
7+
"github.com/obot-platform/tools/microsoft365/outlook/calendar/pkg/util"
88
)
99

1010
func GetGroupNameFromID(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, id string) (string, error) {

microsoft365/outlook/calendar/tool.gpt

+4-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ Description: Deletes an event.
9595
Share Context: Outlook Calendar Context
9696
Credential: ../../credential
9797
Share Tools: List Calendars, List Events, Search Events, Get Event Details
98-
Param: event_id: The unique ID of the event.
99-
Param: calendar_id: The unique ID of the calendar or group the event belongs to. If unset, uses the default calendar.
100-
Param: owner_type: The type of the owner of the calendar or group. Possible values are "user" or "group". Required if calendar_id is set.
98+
Param: event_id: (Required) The unique ID of the event.
99+
Param: delete_series: (Optional) Whether to delete the entire series of recurring events. If true, all events in the series will be deleted. If false, only the specific event will be deleted. Default is false.
100+
Param: calendar_id: (Optional) The unique ID of the calendar or group the event belongs to. If unset, uses the default calendar.
101+
Param: owner_type: (Optional) The type of the owner of the calendar or group. Possible values are "user" or "group". Required if calendar_id is set.
101102

102103
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool deleteEvent
103104

0 commit comments

Comments
 (0)