Skip to content
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

[GCAL] Enable notifications and reminders when a superuser token is not supported #272

Merged
merged 41 commits into from
Aug 1, 2023

Conversation

fmartingr
Copy link
Contributor

@fmartingr fmartingr commented Jul 25, 2023

Summary

Review the notifications and subscription logic to make it work with Google Calendar.

I've modified around things to allow the Sync/SyncAll/ProcessAllDailySummary to work without super user tokens, which I think is the same problem right now with the Google Calendar integration.

The changes work in a way that, if the MakeSuperUserClient returns a specific error ("not supported"), we use the individual credentials to make the API calls.

This has a big downside, and that is we can't batch the requests to Google, since each request uses a different credential.

Also, a fun thing I found during this is that even if you remove your application from Google, you still receive the webhook notifications 🥲

Ticket Link

https://mattermost.atlassian.net/browse/MM-53796

@fmartingr fmartingr self-assigned this Jul 25, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2023

Codecov Report

Patch coverage: 24.52% and project coverage change: +2.08% 🎉

Comparison is base (585e821) 15.29% compared to head (b240b85) 17.37%.
Report is 1 commits behind head on migrate-to-gcal.

Additional details and impacted files
@@                 Coverage Diff                 @@
##           migrate-to-gcal     #272      +/-   ##
===================================================
+ Coverage            15.29%   17.37%   +2.08%     
===================================================
  Files                   78       79       +1     
  Lines                 3780     3896     +116     
===================================================
+ Hits                   578      677      +99     
- Misses                3138     3141       +3     
- Partials                64       78      +14     
Files Changed Coverage Δ
server/command/command.go 37.39% <0.00%> (ø)
server/command/view_calendar.go 0.00% <0.00%> (ø)
server/mscalendar/notification.go 5.73% <ø> (+3.47%) ⬆️
server/mscalendar/notification_format.go 0.00% <0.00%> (ø)
server/mscalendar/subscription.go 0.00% <0.00%> (ø)
server/remote/gcal/event.go 0.00% <0.00%> (ø)
server/remote/gcal/remote.go 6.25% <0.00%> (+2.08%) ⬆️
server/remote/gcal/subscription.go 0.00% <ø> (ø)
server/remote/msgraph/event.go 0.00% <0.00%> (ø)
server/remote/msgraph/get_default_calendar_view.go 0.00% <0.00%> (ø)
... and 5 more

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -31,6 +31,13 @@ func withRemoteUser(user *User) func(m *mscalendar) error {
}
}

func withActingUser(mattermostUserID string) func(m *mscalendar) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is not cheating 🙃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not cheating per se, but maybe error-prone. This is being called in a service account context, so we are changing the state of m temporarily while handling a given user's events. This makes it difficult to do concurrent operations across users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only way I imagined of leaving the architecture as it is, without moving other parts of the logic outside of the main "calendar" logic, but I do not know how this could affect elsewhere, if anything. Only running under GCal at the moment. Open to suggestions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this seems fine, though just concerned about potential pitfalls of mutating the state. Really that's just an artifact of the .Filter() method in general. It's mainly meant to be used in a per-user context, but we introduced the superuser token later. And now we're doing sort of a hybrid, where we're using user-level OAuth tokens in a scheduled job context.

I think it's fine how this PR implements it, though we will need to rethink this if we want to perform these requests concurrently across different users. Speaking of which, what are your thoughts on the performance of the current approach, versus fanning out the requests in some fashion? The timing of reminders etc. depends on the speed of this operation, so I'm thinking we'll need some performance optimization here in the case of sending individual requests for each user.

Copy link
Contributor Author

@fmartingr fmartingr Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to parallelize work we can do a Filter function that returns a copy of the mscalendar with the context switched so we can send out all the jobs to goroutines and wait for all of them to finish using a waitgroup. Is not the best approach, but it surely helps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work on this 🎉

Just a few comments for now. Just wondering, are the notifications features now working properly from this PR?

server/mscalendar/availability.go Outdated Show resolved Hide resolved
@@ -31,6 +31,13 @@ func withRemoteUser(user *User) func(m *mscalendar) error {
}
}

func withActingUser(mattermostUserID string) func(m *mscalendar) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not cheating per se, but maybe error-prone. This is being called in a service account context, so we are changing the state of m temporarily while handling a given user's events. This makes it difficult to do concurrent operations across users.

server/mscalendar/notification.go Outdated Show resolved Hide resolved
server/mscalendar/notification_format.go Show resolved Hide resolved
server/mscalendar/subscription.go Show resolved Hide resolved
server/remote/msgraph/event.go Outdated Show resolved Hide resolved
server/mscalendar/daily_summary.go Outdated Show resolved Hide resolved
@fmartingr fmartingr force-pushed the fmartingr/gcal/notifications branch from b6b3a84 to 429698a Compare July 25, 2023 17:58
Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very good 👍 Some comments for discussion, and request to de-duplicate some code, and add some unit tests for the new functionality

server/mscalendar/daily_summary.go Outdated Show resolved Hide resolved
server/mscalendar/daily_summary.go Outdated Show resolved Hide resolved
server/mscalendar/availability.go Outdated Show resolved Hide resolved
@@ -63,9 +71,84 @@ func (m *mscalendar) SyncAll() (string, *StatusSyncJobSummary, error) {
return "", &StatusSyncJobSummary{}, errors.Wrap(err, "not able to load the users from user index")
}

err = m.Filter(withSuperuserClient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible this could have side effects since this mutates state, and thus affects functions like syncUsers. From a quick look, it seems that it won't have issues though.

What's weird is that the only client used in that path is in GetCalendarViews, which is setting its own user-level client for batch requests. Not sure how that is working this way:

func (m *mscalendar) GetCalendarViews(users []*store.User) ([]*remote.ViewCalendarResponse, error) {
err := m.Filter(withClient)

server/mscalendar/notification_format.go Show resolved Hide resolved
@fmartingr fmartingr force-pushed the fmartingr/gcal/notifications branch from 4a9ce37 to a92d545 Compare July 27, 2023 11:41
@fmartingr fmartingr changed the title [GCAL] Notifications review [GCAL] Enable notifications and reminders when a superuser token is not supported Jul 27, 2023
Copy link
Contributor

@mickmister mickmister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 just a few comments

As an aside, if possible I would avoid force-pushing since this makes it so GitHub's UI shows the PR commit history out of line with comments made before the most recent push.

server/mscalendar/availability.go Outdated Show resolved Hide resolved
server/mscalendar/availability.go Outdated Show resolved Hide resolved
@@ -31,6 +31,13 @@ func withRemoteUser(user *User) func(m *mscalendar) error {
}
}

func withActingUser(mattermostUserID string) func(m *mscalendar) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

server/mscalendar/availability_test.go Show resolved Hide resolved
@mickmister
Copy link
Contributor

Great work on this btw!! Awesome to see this implemented 🎉

server/mscalendar/availability_test.go Outdated Show resolved Hide resolved
}

err = m.Filter(withClient)
err := m.Filter(withClient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see an opportunity to make this code less error-prone? It concerns me that it's easy to make an error based on where this call is placed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intention when I removed the withActingUser from this method. Now we can call this one without problems from other places since the new withActingUser only gets called from the fenced code in the "main" calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but what can we do to avoid needing to have withActingUser in the fenced code? Just want to make sure we don't run into something similar later, especially if it's something not caught by a unit test

@fmartingr fmartingr merged commit 336a906 into migrate-to-gcal Aug 1, 2023
4 checks passed
@fmartingr fmartingr deleted the fmartingr/gcal/notifications branch August 1, 2023 07:03
mickmister added a commit that referenced this pull request Mar 1, 2024
* oauth works

* autocomplete

* viewcal works

* add unimplemented if blocks

* fix tests and lint

* implement CreateMySubscription, RenewSubscription, and DeleteSubscription gcal methods

* WIP gcal subs

* setup-attach make target

* fix lint and tests

* chore: more compatible tar command

* add review comments

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* bug: get timezone from datetime instead of event data (#271)

* [GCAL] Allow building two different plugins under the same codebase (#268)

* plugin profile images

* receive provider flag

* manifests

* retrieve manifest id from file

* Build time configuration

* revert manifest

* using go static configuration for providers

* removed unused build flags

* revert manifest

* Added basic Google Calendar instructions

* Update providers/GoogleCalendar.md

Co-authored-by: Michael Kochell <[email protected]>

* Update providers/GoogleCalendar.md

Co-authored-by: Michael Kochell <[email protected]>

* Update server/plugin/plugin.go

Co-authored-by: Michael Kochell <[email protected]>

* remoove log

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Endpoint to autocomplete connected calendar users (#275)

* user_store: more information fields on the index

* feat: endpoint to autocomplete calendar connected users

* revert test event store hashed

* Update server/api/autocomplete.go

Co-authored-by: Michael Kochell <[email protected]>

* Update server/api/autocomplete.go

Co-authored-by: Michael Kochell <[email protected]>

* dont expose private data in endpoint

* lint

* Update server/store/user_store.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Refactor Microsoft Calendar references to provider references (#276)

* chore: replace provider display name

* chore: replace command trigger references

* revert previous changes

* [GCAL] Enable notifications and reminders when a superuser token is not supported (#272)

* nil control

* use subscriptions default ttl

* return specific error when no superuser token can be used

* notification formatting logic to other file

* Client.GetEventsBetweenDates

* typo: import

* shorter command name :)

* availability without super user token

* delete store subs only if we successfuly do on remote

* comment

* ignore missing subs

* update sync method

* allow switching acting user on the fly

* daily summary without super user token

* formatted imports

* calendar -> calendarEvents

* processAllDailySummaryByUser
 -> processAllDailySummaryWithIndividualCredentials

* revert silenced error under notifications

* msgraph GetEventsBetweenDates

* Update server/mscalendar/daily_summary.go

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* Client.GetEventsBetweenDates

* fix: store last post time

* refactored availability logic

* availability test

* refactored daily summary logic

* test: availability

* daily summary tests (wip)

* daily summary test

* fix: merge duplications

* slack attachment for notifications

* lint and test

* goimports

* Update server/mscalendar/availability.go

Co-authored-by: Michael Kochell <[email protected]>

* remove logges

* nullify client when changing acting user

* move withActiveUser filter to fenced code outside of general method

* tests: handling more scenarios

* Fixed test after bugfix

* fixed test assertions

* allow engine copy to perform safe state mutations

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Added encrypted key value storage (#270)

* Added encrypted kvstore

* encrypt only oauth2 kv store

* retrieve encryption setting from provider config

* explicitly disable encrypted store for mscalendar

* remove old comment

* [GCAL] today/tomorrow commands with styling (#273)

* feat: added today and tomorrow commands with attachments

* remove unused function

* linted

* now -> day

* remove unused code

* today/tomorrow autocomplete

* return tables on today/tomorrow commands

* check for nil location

* revert tomorrow day times four

* fix markdown table render and test

* [GCAL] Fix test in main branch from PR merges (#277)

* fix: test from merges

* add meeting url

* [GCAL] Move configuration readyness logic to remotes (#279)

* Move configuration logic to remotes

* check encryption key as well

* Update server/plugin/plugin.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Remove unused code (#278)

* remove batch requests from gcal code

* More info in readme

* [GCAL] Fix event notifications not working due to missing scope permissions plus internal state (#282)

* fix: notifications scope and acting user logic

* remove log

* avoid calling notifications if the engine fails to load

* [GCAL] Unsubscriptions (#283)

* fix: notifications scope and acting user logic

* fix: gcal unsubscribe requiring more parameters

* update gcal manifest (#285)

* [GCAL] Better logging information (#287)

* fix: better log information

* log missing error

* use correct manifest file on manifest calls (#290)

* [GCAL] Embed tzdata and correctly parse location from event datetime (#288)

* fix: embed tzdata to prevent errors on systems without it installed

* move to main

* avoid overwritting location if empty

* use tags instead of import

* [GCAL] Event notifications behind a feature flag (#292)

* put event notifications behind a feature flag

* admin only un/subscribe commands

* properly fence notification processor

* ignore notifications if there's no processor (#293)

* [GCAL] Remove join event column (broken from merges) (#294)

* remove join column from merges

* revert manifest

* [GCAL] Channels reminder underlying logic (#274)

* nil control

* use subscriptions default ttl

* return specific error when no superuser token can be used

* notification formatting logic to other file

* Client.GetEventsBetweenDates

* typo: import

* shorter command name :)

* availability without super user token

* delete store subs only if we successfuly do on remote

* comment

* ignore missing subs

* update sync method

* allow switching acting user on the fly

* daily summary without super user token

* formatted imports

* calendar -> calendarEvents

* processAllDailySummaryByUser
 -> processAllDailySummaryWithIndividualCredentials

* revert silenced error under notifications

* msgraph GetEventsBetweenDates

* Update server/mscalendar/daily_summary.go

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* Client.GetEventsBetweenDates

* fix: store last post time

* refactored availability logic

* availability test

* refactored daily summary logic

* test: availability

* daily summary tests (wip)

* daily summary test

* fix: merge duplications

* slack attachment for notifications

* lint and test

* goimports

* Allow poster to create posts

* Allow store event metadata

* styling

* store recurring event id

* deliver channel notifications

* test: fixed for base case

* test: channel reminders

* test: recurring events

* move from slice to map

* Added store methods to interact with event metadata

* lint

* lint imports

* restore logic lost in merge

* duplicated test

* Update server/mscalendar/availability_test.go

Co-authored-by: Michael Kochell <[email protected]>

* remove recurrent event id field

---------

Co-authored-by: Michael Kochell <[email protected]>

* Updated google calendar readme

* [GCAL] Summary command fixes (#286)

* command trigger shown

* added autocomplete to summary command

* remove join meeting column

* fix event subjects with table separator

* fixed merge import

* replace more characters in subject

* [GCAL] Add a modal to create events (#281)

* add webapp folder

* WIP

* opening create event modal from slash command works

* add time selectors and initial impl of attendee selector

* delete .npminstall

* ignore .npminstall

* [GCAL/MSCAL] Add endpoint to create events from the frontend (#291)

* add remoteid to event attendee

* api endpoint

* conversion fixes

* api logic

* frontend logic to test

* check if user belongs to channel

* updated interface

* use api/v1 prefix

* implement getchannelmember

* all day events

* pluginAPI.CanLinkEventToChannel

* autocomplete users

* create event fetch call

* channel autocomplete

* improved error messages displayed to users

* better error handling

* channel selector store channel id

* properly set email addresses for attendees

* event location as string

* response messages

* little refactor

* attendee selector can invite arbitrary emails

* uppercase error dynamically

* lowercase error

* remove punctuation

* linted ts files

* goimports

* fixed import

* link events on creation

* Add channel action to create events

* add channel_id to payload

* time selector every 15 minutes

* time selector start/end with limits

* capitalized error messages

* don't allow 0 minute events

* display timezone in channel reminders

* utc time parsing

* remove nullfunc

* properly initialize variables

* address some comments

* npm run fix

* Update webapp/src/components/time_selector.tsx

Co-authored-by: Michael Kochell <[email protected]>

* Update webapp/src/components/time_selector.tsx

Co-authored-by: Michael Kochell <[email protected]>

* refactor options with useMemo

* capitalization in function for clarity

* npm run fix

* get plugin id from manifest

* remove no-ops

* refactor createEvent

* fix channel autocomplete url

* fix lint

* fix user string typo

* make it so `make apply` assumes gcal for now

* more careful error handling

* reorganize frontend error handling

* default to CALENDAR_PROVIDER=gcal

* use Client4.autocompleteChannels instead of custom plugin endpoint

* fix manifest test

---------

Co-authored-by: Michael Kochell <[email protected]>

* gofmt

---------

Co-authored-by: Felipe Martin <[email protected]>
Co-authored-by: Felipe Martin <[email protected]>

* [GCAL/MSCAL] Store linked events per user to remove links on disconnection (#296)

* add webapp folder

* WIP

* opening create event modal from slash command works

* add time selectors and initial impl of attendee selector

* delete .npminstall

* ignore .npminstall

* add remoteid to event attendee

* api endpoint

* conversion fixes

* api logic

* frontend logic to test

* check if user belongs to channel

* updated interface

* use api/v1 prefix

* implement getchannelmember

* all day events

* pluginAPI.CanLinkEventToChannel

* autocomplete users

* create event fetch call

* channel autocomplete

* improved error messages displayed to users

* better error handling

* channel selector store channel id

* properly set email addresses for attendees

* event location as string

* response messages

* little refactor

* attendee selector can invite arbitrary emails

* uppercase error dynamically

* lowercase error

* remove punctuation

* linted ts files

* goimports

* fixed import

* link events on creation

* Add channel action to create events

* add channel_id to payload

* time selector every 15 minutes

* time selector start/end with limits

* capitalized error messages

* don't allow 0 minute events

* display timezone in channel reminders

* utc time parsing

* remove nullfunc

* properly initialize variables

* address some comments

* npm run fix

* store linked events for user to remove links on disconnection

* typo

* remove unused items after merge

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL/MSCAL] Remind only accepted events (#295)

* remind only accepted events

* fixed tests

* excludeDeclinedEvents

* normalize msgraph event response

* Remove GoogleDomainVerifyKey setting (#299)

* fix: encrypt user store (#297)

* feat: send notifications when an event is created (#300)

* typo: user already connected message (#301)

* typo: user already connected message

* test: fix change

* typo: user already connected message (#301)

* typo: user already connected message

* test: fix change

* [GCAL/MSCAL] Exclude rejected events from agenda commands (#302)

* exclude rejected events from agenda commands

* test: check that declied event are excluded

* fix possible nil pointer

* [GCAL/MSCAL] Create event modal only for connected accounts (#303)

* only connected users chan use slash command

* prevent channel menu action from allowing too

* npm run fix

* lint errors

* retrieve provider configuration to use in messages

* websocket events

* add message to mobile users

* npm run fix

* Update webapp/src/plugin_hooks.ts

Co-authored-by: Michael Kochell <[email protected]>

* register modal in setup

* events create

* trigger from provide config

* using dispatch

* missing semicolon

* Update webapp/src/plugin_hooks.ts

Co-authored-by: Michael Kochell <[email protected]>

* singular

---------

Co-authored-by: Michael Kochell <[email protected]>

* updated settings to use style and removed current value line (#305)

* show link to connect if not connected (#306)

* [GCAL/MSCAL] Reduce welcome steps  (#308)

* reduce welcome steps and edit defaults

* Update server/mscalendar/welcome_flow.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL/MSCAL] Control start/date times if the selected date is today (#307)

* improvements to create event datetimes

* reset starttime endtime on date change

* repopulate times if date changed

* npm run fix

* database replication workaround (#312)

* [GCAL/MSCAL] Catch errors when using `findmeetings` commands without enough parameters (#313)

* fix: handle error in find meetings parameters command

* changed loop variable usage

* Replace Equals with ElementsMatch

* makefile dist build for production (#314)

* [GCAL/MSCAL] Create event UX improvements (#309)

* Optional fields

* time picker defaults

* Add custom icon to Create Event menu item

* add custom icon to date selector

* npm run fix

* header menu icon multiline

* use scss

* using proper typeRoots

* scoped css style

* [GCAL] Store conference data (#298)

* extract conference data into new attribute

* removed log

* removed unused fuunction

* tests

* Update server/remote/gcal/get_default_calendar_view_test.go

Co-authored-by: Michael Kochell <[email protected]>

* more realistic datetime values

---------

Co-authored-by: Michael Kochell <[email protected]>

* Common code refactor, back to mscalendar plugin (#334)

* refactor: mscalendar -> engine

* remove gcal assets

* refactored common code outside server package

* check-style

* go mod tidy

* REPO_URL -> REPOSITORY_URL

* delete unknown file

* updated mocks

* apped user to handle after all actions (#335)

* refactor msgraph to mscalendar

* goimports

* removed apply command from merge

* remove "REVIEW:" comments

---------

Co-authored-by: Felipe Martin <[email protected]>
Co-authored-by: Felipe Martin <[email protected]>
raghavaggarwal2308 added a commit that referenced this pull request Aug 9, 2024
* oauth works

* autocomplete

* viewcal works

* add unimplemented if blocks

* fix tests and lint

* implement CreateMySubscription, RenewSubscription, and DeleteSubscription gcal methods

* WIP gcal subs

* setup-attach make target

* fix lint and tests

* chore: more compatible tar command

* add review comments

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* bug: get timezone from datetime instead of event data (#271)

* [GCAL] Allow building two different plugins under the same codebase (#268)

* plugin profile images

* receive provider flag

* manifests

* retrieve manifest id from file

* Build time configuration

* revert manifest

* using go static configuration for providers

* removed unused build flags

* revert manifest

* Added basic Google Calendar instructions

* Update providers/GoogleCalendar.md

Co-authored-by: Michael Kochell <[email protected]>

* Update providers/GoogleCalendar.md

Co-authored-by: Michael Kochell <[email protected]>

* Update server/plugin/plugin.go

Co-authored-by: Michael Kochell <[email protected]>

* remoove log

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Endpoint to autocomplete connected calendar users (#275)

* user_store: more information fields on the index

* feat: endpoint to autocomplete calendar connected users

* revert test event store hashed

* Update server/api/autocomplete.go

Co-authored-by: Michael Kochell <[email protected]>

* Update server/api/autocomplete.go

Co-authored-by: Michael Kochell <[email protected]>

* dont expose private data in endpoint

* lint

* Update server/store/user_store.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Refactor Microsoft Calendar references to provider references (#276)

* chore: replace provider display name

* chore: replace command trigger references

* revert previous changes

* [GCAL] Enable notifications and reminders when a superuser token is not supported (#272)

* nil control

* use subscriptions default ttl

* return specific error when no superuser token can be used

* notification formatting logic to other file

* Client.GetEventsBetweenDates

* typo: import

* shorter command name :)

* availability without super user token

* delete store subs only if we successfuly do on remote

* comment

* ignore missing subs

* update sync method

* allow switching acting user on the fly

* daily summary without super user token

* formatted imports

* calendar -> calendarEvents

* processAllDailySummaryByUser
 -> processAllDailySummaryWithIndividualCredentials

* revert silenced error under notifications

* msgraph GetEventsBetweenDates

* Update server/mscalendar/daily_summary.go

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* Client.GetEventsBetweenDates

* fix: store last post time

* refactored availability logic

* availability test

* refactored daily summary logic

* test: availability

* daily summary tests (wip)

* daily summary test

* fix: merge duplications

* slack attachment for notifications

* lint and test

* goimports

* Update server/mscalendar/availability.go

Co-authored-by: Michael Kochell <[email protected]>

* remove logges

* nullify client when changing acting user

* move withActiveUser filter to fenced code outside of general method

* tests: handling more scenarios

* Fixed test after bugfix

* fixed test assertions

* allow engine copy to perform safe state mutations

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Added encrypted key value storage (#270)

* Added encrypted kvstore

* encrypt only oauth2 kv store

* retrieve encryption setting from provider config

* explicitly disable encrypted store for mscalendar

* remove old comment

* [GCAL] today/tomorrow commands with styling (#273)

* feat: added today and tomorrow commands with attachments

* remove unused function

* linted

* now -> day

* remove unused code

* today/tomorrow autocomplete

* return tables on today/tomorrow commands

* check for nil location

* revert tomorrow day times four

* fix markdown table render and test

* [GCAL] Fix test in main branch from PR merges (#277)

* fix: test from merges

* add meeting url

* [GCAL] Move configuration readyness logic to remotes (#279)

* Move configuration logic to remotes

* check encryption key as well

* Update server/plugin/plugin.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Remove unused code (#278)

* remove batch requests from gcal code

* More info in readme

* [GCAL] Fix event notifications not working due to missing scope permissions plus internal state (#282)

* fix: notifications scope and acting user logic

* remove log

* avoid calling notifications if the engine fails to load

* [GCAL] Unsubscriptions (#283)

* fix: notifications scope and acting user logic

* fix: gcal unsubscribe requiring more parameters

* update gcal manifest (#285)

* [GCAL] Better logging information (#287)

* fix: better log information

* log missing error

* use correct manifest file on manifest calls (#290)

* [GCAL] Embed tzdata and correctly parse location from event datetime (#288)

* fix: embed tzdata to prevent errors on systems without it installed

* move to main

* avoid overwritting location if empty

* use tags instead of import

* [GCAL] Event notifications behind a feature flag (#292)

* put event notifications behind a feature flag

* admin only un/subscribe commands

* properly fence notification processor

* ignore notifications if there's no processor (#293)

* [GCAL] Remove join event column (broken from merges) (#294)

* remove join column from merges

* revert manifest

* [GCAL] Channels reminder underlying logic (#274)

* nil control

* use subscriptions default ttl

* return specific error when no superuser token can be used

* notification formatting logic to other file

* Client.GetEventsBetweenDates

* typo: import

* shorter command name :)

* availability without super user token

* delete store subs only if we successfuly do on remote

* comment

* ignore missing subs

* update sync method

* allow switching acting user on the fly

* daily summary without super user token

* formatted imports

* calendar -> calendarEvents

* processAllDailySummaryByUser
 -> processAllDailySummaryWithIndividualCredentials

* revert silenced error under notifications

* msgraph GetEventsBetweenDates

* Update server/mscalendar/daily_summary.go

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL] Create event logic (#269)

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time

* Client.GetEventsBetweenDates

* fix: store last post time

* refactored availability logic

* availability test

* refactored daily summary logic

* test: availability

* daily summary tests (wip)

* daily summary test

* fix: merge duplications

* slack attachment for notifications

* lint and test

* goimports

* Allow poster to create posts

* Allow store event metadata

* styling

* store recurring event id

* deliver channel notifications

* test: fixed for base case

* test: channel reminders

* test: recurring events

* move from slice to map

* Added store methods to interact with event metadata

* lint

* lint imports

* restore logic lost in merge

* duplicated test

* Update server/mscalendar/availability_test.go

Co-authored-by: Michael Kochell <[email protected]>

* remove recurrent event id field

---------

Co-authored-by: Michael Kochell <[email protected]>

* Updated google calendar readme

* [GCAL] Summary command fixes (#286)

* command trigger shown

* added autocomplete to summary command

* remove join meeting column

* fix event subjects with table separator

* fixed merge import

* replace more characters in subject

* [GCAL] Add a modal to create events (#281)

* add webapp folder

* WIP

* opening create event modal from slash command works

* add time selectors and initial impl of attendee selector

* delete .npminstall

* ignore .npminstall

* [GCAL/MSCAL] Add endpoint to create events from the frontend (#291)

* add remoteid to event attendee

* api endpoint

* conversion fixes

* api logic

* frontend logic to test

* check if user belongs to channel

* updated interface

* use api/v1 prefix

* implement getchannelmember

* all day events

* pluginAPI.CanLinkEventToChannel

* autocomplete users

* create event fetch call

* channel autocomplete

* improved error messages displayed to users

* better error handling

* channel selector store channel id

* properly set email addresses for attendees

* event location as string

* response messages

* little refactor

* attendee selector can invite arbitrary emails

* uppercase error dynamically

* lowercase error

* remove punctuation

* linted ts files

* goimports

* fixed import

* link events on creation

* Add channel action to create events

* add channel_id to payload

* time selector every 15 minutes

* time selector start/end with limits

* capitalized error messages

* don't allow 0 minute events

* display timezone in channel reminders

* utc time parsing

* remove nullfunc

* properly initialize variables

* address some comments

* npm run fix

* Update webapp/src/components/time_selector.tsx

Co-authored-by: Michael Kochell <[email protected]>

* Update webapp/src/components/time_selector.tsx

Co-authored-by: Michael Kochell <[email protected]>

* refactor options with useMemo

* capitalization in function for clarity

* npm run fix

* get plugin id from manifest

* remove no-ops

* refactor createEvent

* fix channel autocomplete url

* fix lint

* fix user string typo

* make it so `make apply` assumes gcal for now

* more careful error handling

* reorganize frontend error handling

* default to CALENDAR_PROVIDER=gcal

* use Client4.autocompleteChannels instead of custom plugin endpoint

* fix manifest test

---------

Co-authored-by: Michael Kochell <[email protected]>

* gofmt

---------

Co-authored-by: Felipe Martin <[email protected]>
Co-authored-by: Felipe Martin <[email protected]>

* [GCAL/MSCAL] Store linked events per user to remove links on disconnection (#296)

* add webapp folder

* WIP

* opening create event modal from slash command works

* add time selectors and initial impl of attendee selector

* delete .npminstall

* ignore .npminstall

* add remoteid to event attendee

* api endpoint

* conversion fixes

* api logic

* frontend logic to test

* check if user belongs to channel

* updated interface

* use api/v1 prefix

* implement getchannelmember

* all day events

* pluginAPI.CanLinkEventToChannel

* autocomplete users

* create event fetch call

* channel autocomplete

* improved error messages displayed to users

* better error handling

* channel selector store channel id

* properly set email addresses for attendees

* event location as string

* response messages

* little refactor

* attendee selector can invite arbitrary emails

* uppercase error dynamically

* lowercase error

* remove punctuation

* linted ts files

* goimports

* fixed import

* link events on creation

* Add channel action to create events

* add channel_id to payload

* time selector every 15 minutes

* time selector start/end with limits

* capitalized error messages

* don't allow 0 minute events

* display timezone in channel reminders

* utc time parsing

* remove nullfunc

* properly initialize variables

* address some comments

* npm run fix

* store linked events for user to remove links on disconnection

* typo

* remove unused items after merge

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL/MSCAL] Remind only accepted events (#295)

* remind only accepted events

* fixed tests

* excludeDeclinedEvents

* normalize msgraph event response

* Remove GoogleDomainVerifyKey setting (#299)

* fix: encrypt user store (#297)

* feat: send notifications when an event is created (#300)

* typo: user already connected message (#301)

* typo: user already connected message

* test: fix change

* typo: user already connected message (#301)

* typo: user already connected message

* test: fix change

* [GCAL/MSCAL] Exclude rejected events from agenda commands (#302)

* exclude rejected events from agenda commands

* test: check that declied event are excluded

* fix possible nil pointer

* [GCAL/MSCAL] Create event modal only for connected accounts (#303)

* only connected users chan use slash command

* prevent channel menu action from allowing too

* npm run fix

* lint errors

* retrieve provider configuration to use in messages

* websocket events

* add message to mobile users

* npm run fix

* Update webapp/src/plugin_hooks.ts

Co-authored-by: Michael Kochell <[email protected]>

* register modal in setup

* events create

* trigger from provide config

* using dispatch

* missing semicolon

* Update webapp/src/plugin_hooks.ts

Co-authored-by: Michael Kochell <[email protected]>

* singular

---------

Co-authored-by: Michael Kochell <[email protected]>

* updated settings to use style and removed current value line (#305)

* show link to connect if not connected (#306)

* [GCAL/MSCAL] Reduce welcome steps  (#308)

* reduce welcome steps and edit defaults

* Update server/mscalendar/welcome_flow.go

Co-authored-by: Michael Kochell <[email protected]>

---------

Co-authored-by: Michael Kochell <[email protected]>

* [GCAL/MSCAL] Control start/date times if the selected date is today (#307)

* improvements to create event datetimes

* reset starttime endtime on date change

* repopulate times if date changed

* npm run fix

* database replication workaround (#312)

* [GCAL/MSCAL] Catch errors when using `findmeetings` commands without enough parameters (#313)

* fix: handle error in find meetings parameters command

* changed loop variable usage

* Replace Equals with ElementsMatch

* makefile dist build for production (#314)

* [GCAL/MSCAL] Create event UX improvements (#309)

* Optional fields

* time picker defaults

* Add custom icon to Create Event menu item

* add custom icon to date selector

* npm run fix

* header menu icon multiline

* use scss

* using proper typeRoots

* scoped css style

* [GCAL] Store conference data (#298)

* extract conference data into new attribute

* removed log

* removed unused fuunction

* tests

* Update server/remote/gcal/get_default_calendar_view_test.go

Co-authored-by: Michael Kochell <[email protected]>

* more realistic datetime values

---------

Co-authored-by: Michael Kochell <[email protected]>

* Common code refactor, back to mscalendar plugin (#334)

* refactor: mscalendar -> engine

* remove gcal assets

* refactored common code outside server package

* check-style

* go mod tidy

* REPO_URL -> REPOSITORY_URL

* delete unknown file

* updated mocks

* apped user to handle after all actions (#335)

* refactor msgraph to mscalendar

* refactor: removed unused commands

* Update calendar/command/command.go

Co-authored-by: Michael Kochell <[email protected]>

* go mod tidy

* removed added code from merge

---------

Co-authored-by: Michael Kochell <[email protected]>
Co-authored-by: Raghav Aggarwal <[email protected]>
Co-authored-by: Doug Lauder <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants