-
Notifications
You must be signed in to change notification settings - Fork 35
Add API to list calendars for a user #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
84ffac1
5de8728
7b13946
5f461c9
799f180
143b7e8
c07ae73
6e6a30c
519393b
2afad59
f51026d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| const ( | ||
| createEventDateTimeFormat = "2006-01-02 15:04" | ||
| createEventDateFormat = "2006-01-02" | ||
| HeaderMattermostUserID = "Mattermost-User-Id" | ||
| ) | ||
|
|
||
| type createEventPayload struct { | ||
|
|
@@ -35,6 +36,7 @@ type createEventPayload struct { | |
| Subject string `json:"subject"` | ||
| Location string `json:"location,omitempty"` | ||
| ChannelID string `json:"channel_id"` | ||
| CalendarID string `json:"calendar_id"` | ||
| } | ||
|
|
||
| func (cep createEventPayload) ToRemoteEvent(loc *time.Location) (*remote.Event, error) { | ||
|
|
@@ -226,7 +228,7 @@ func (api *api) createEvent(w http.ResponseWriter, r *http.Request) { | |
| }) | ||
| } | ||
|
|
||
| event, err := client.CreateEvent(user.Remote.ID, event) | ||
| event, err := client.CreateEvent("", user.Remote.ID, event) | ||
| if err != nil { | ||
| httputils.WriteInternalServerError(w, err) | ||
| return | ||
|
|
@@ -272,3 +274,31 @@ func (api *api) createEvent(w http.ResponseWriter, r *http.Request) { | |
|
|
||
| httputils.WriteJSONResponse(w, `{"ok": true}`, http.StatusCreated) | ||
| } | ||
|
|
||
| func (api *api) listCalendars(w http.ResponseWriter, r *http.Request) { | ||
| mattermostUserID := r.Header.Get(HeaderMattermostUserID) | ||
| if mattermostUserID == "" { | ||
| httputils.WriteUnauthorizedError(w, fmt.Errorf("unauthorized")) | ||
|
ayusht2810 marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using a shared error like var ErrUnauthorized = errors.New("unauthorized") |
||
| return | ||
| } | ||
|
|
||
| user, errStore := api.Store.LoadUser(mattermostUserID) | ||
| if errStore != nil && !errors.Is(errStore, store.ErrNotFound) { | ||
| httputils.WriteInternalServerError(w, errStore) | ||
| return | ||
| } | ||
| if errors.Is(errStore, store.ErrNotFound) { | ||
| httputils.WriteUnauthorizedError(w, fmt.Errorf("unauthorized")) | ||
| return | ||
| } | ||
|
|
||
| client := api.Remote.MakeClient(context.Background(), user.OAuth2Token) | ||
|
|
||
| calendars, errMailbox := client.GetCalendars(user.Remote.ID) | ||
| if errMailbox != nil { | ||
| httputils.WriteInternalServerError(w, errMailbox) | ||
| return | ||
| } | ||
|
|
||
| httputils.WriteJSONResponse(w, calendars, http.StatusOK) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ func (m *mscalendar) CreateEvent(user *User, event *remote.Event, mattermostUser | |
| } | ||
| } | ||
|
|
||
| return m.client.CreateEvent(user.Remote.ID, event) | ||
| return m.client.CreateEvent("", user.Remote.ID, event) | ||
|
||
| } | ||
|
|
||
| func (m *mscalendar) DeleteCalendar(user *User, calendarID string) error { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
calendarIDparameter is hardcoded as an empty string, but the payload includes aCalendarIDfield (line 41). Consider usingpayload.CalendarIDinstead of an empty string to utilize the calendar selection functionality.