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

Refactor calendar engine into its own package #267

Merged
merged 63 commits into from
Mar 1, 2024
Merged

Conversation

mickmister
Copy link
Contributor

@mickmister mickmister commented Jul 24, 2023

Summary

This pull requests refactors the main calendar engine used by the mscalendar plugin and leverages the remotes implementation to allow other plugins to easily import this plugin providing its own remote to easily create other calendar plugins.

This work was done to create the mattermost-plugin-google-calendar that could be used as a template, with the caveheat that the google calendar plugin contains it's own frontend code to create events and that is currently not shared and it's a task to tackle in the future.

@mickmister
Copy link
Contributor Author

@fmartingr I've reopened this on a Mattermost-owned branch. Also notice that the base branch is gcal-master, which is currently equal to the master branch. 1/5 Let's use gcal-master as the protected branch for this project.

@@ -91,6 +92,8 @@ func newTestNotification(clientState string, recommendRenew bool) *remote.Notifi
}

func TestProcessNotification(t *testing.T) {
t.Skip("TODO gcal implement TestProcessNotification")
Copy link
Contributor Author

@mickmister mickmister Jul 24, 2023

Choose a reason for hiding this comment

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

Test needs to be updated

@codecov-commenter
Copy link

codecov-commenter commented Jul 25, 2023

Codecov Report

Attention: Patch coverage is 23.51454% with 605 lines in your changes are missing coverage. Please review.

Project coverage is 20.94%. Comparing base (b1bcb7b) to head (1de44d0).

Files Patch % Lines
calendar/engine/notification.go 5.78% 114 Missing ⚠️
calendar/engine/welcome_flow.go 0.00% 82 Missing ⚠️
calendar/command/daily_summary.go 0.00% 65 Missing ⚠️
calendar/utils/kvstore/crypt.go 35.00% 45 Missing and 7 partials ⚠️
calendar/engine/availability.go 53.77% 38 Missing and 11 partials ⚠️
msgraph/event.go 0.00% 44 Missing ⚠️
calendar/command/command.go 30.30% 22 Missing and 1 partial ⚠️
calendar/engine/daily_summary.go 62.06% 16 Missing and 6 partials ⚠️
calendar/engine/user.go 19.23% 21 Missing ⚠️
msgraph/msgraph.go 0.00% 18 Missing ⚠️
... and 27 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #267      +/-   ##
==========================================
- Coverage   23.71%   20.94%   -2.77%     
==========================================
  Files          62       67       +5     
  Lines        3087     3442     +355     
==========================================
- Hits          732      721      -11     
- Misses       2274     2628     +354     
- Partials       81       93      +12     

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

Copy link
Contributor Author

@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.

@fmartingr I gave the plugin a review, and noted some things within this commit d78381a. Note that the commit itself is the review. Please take a look and share any thoughts you might have.

I added some PR review comments on top of the commit, to gather info that is provider-specific. The goal is to put them all in one struct. I plan to search for these strings in the code to find more:

  • microsoft
  • msgraph
  • mscalender
  • mscal
  • gcal
  • google

I think the notification subscription lifecycle is the one thing that seems murky with regards to remaining work to handle both providers. I need to better understand gcal's subscription lifecycle to connect the dots on the code related to subscriptions.

Comment on lines 12 to 15
// REVIEW: hardcoded "microsoft"
func (c *Command) info(parameters ...string) (string, bool, error) {
resp := fmt.Sprintf("Mattermost Microsoft Calendar plugin version: %s, "+
"[%s](https://github.com/mattermost/%s/commit/%s), built %s\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

config: plugin name

Comment on lines 6 to 10
// REVIEW: need an interface for returning bot info
// probably good to have a struct to capture the data clump
const (
BotUserName = "gcal"
BotDisplayName = "Google Calendar"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all fields being used here, that should be put into a struct

BotUserName    = "gcal"
BotDisplayName = "Google Calendar"
BotDescription = "Created by the Google Calendar Plugin."
ApplicationName    = "Google Calendar"
Repository         = "mattermost-plugin-gcal"
CommandTrigger     = "gcal"
TelemetryShortName = "gcal"

Comment on lines 38 to 40
// REVIEW: notification subscription logic in notification settings. this seems a bit weird. what does this function/block have to do specifically with notifications?
_, err := cal.LoadMyEventSubscription()
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really sure what's going on here. It seems like:

"If a setting is a boolean, create an event subscription if not exists"

This is notificationSetting.Set, so I suppose this is "I want to change notification settings". what do we do when the value hasn't changed? I suppose this function takes care of no-ops

@@ -21,6 +21,7 @@ type Subscriptions interface {
LoadMyEventSubscription() (*store.Subscription, error)
}

// REVIEW: depends on the overlap of subscription logic between providers, but lots of logic about supscription lifecycle in this file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to figure out if google's subscription lifecycle lines up with this

Comment on lines 34 to 36
// REVIEW: "microsoft" referenced here
WelcomeMessage = `Welcome to the Microsoft Calendar plugin.
[Click here to link your account.](%s/oauth2/connect)`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Microsoft Calendar plugin" mentioned here

Comment on lines 126 to 128
// REVIEW: "microsoft" referenced here
text := ":tada: Congratulations! Your microsoft account (*" + userLogin + "*) has been connected to Mattermost."
return &model.SlackAttachment{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Microsoft" mentioned here

Comment on lines 178 to 179
// REVIEW: need to make this provider agnostic terminology
mscalendarBot := mscalendar.NewMSCalendarBot(e.bot, e.Env, pluginURL)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mscalendar terminology leaked into plugin package. not much else than what's visible here though

@@ -28,6 +28,7 @@ func (oa *oa) oauth2Complete(w http.ResponseWriter, r *http.Request) {
return
}

// REVIEW "microsoft" is hardcoded
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Microsoft Calendar" is hardcoded

@mickmister
Copy link
Contributor Author

Follow ups:

  • make tickets for all known remaining tasks
  • review original migration PR to make note of any significant changes for gcal case
  • remove features/endpoints:
    • accept/decline/tentative
    • create/delete calendar

Copy link
Contributor

Choose a reason for hiding this comment

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

This we should take care as well.

@fmartingr
Copy link
Contributor

I need to better understand gcal's subscription lifecycle to connect the dots on the code related to subscriptions

Using the Events.watch endpoint to create a channel, with a default TTL of 7 days, channel can be stopped using Channels.stop.

* remote logic

* allow datetimes without timezone

* add calendar settings readonly scope to get tz

* event conversion

* scopes

* revert datetime.time
@fmartingr fmartingr changed the title Initial gcal implementation [GCAL] Initial Google Calendar implementation Jul 27, 2023
fmartingr and others added 5 commits July 31, 2023 13:15
…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]>
* 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]>
…276)

* chore: replace provider display name

* chore: replace command trigger references

* revert previous changes
…ot 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]>
* Added encrypted kvstore

* encrypt only oauth2 kv store

* retrieve encryption setting from provider config

* explicitly disable encrypted store for mscalendar

* remove old comment
@AayushChaudhary0001
Copy link

Tested this PR.

2 commands, namely createevent and findmeetings do not have any functionality mentioned anywhere and is not clear after executing those commands as well.
Also, on adding any calendar through createcal, I am not able to find from where to add it in the Outlook window. Can you please have a look at those two and this issue?

Rest all are tested and approved from my side.

@mickmister
Copy link
Contributor Author

Thanks so much @AayushChaudhary0001. All 3 of those commands are generally unimplemented and should be removed from the codebase

@fmartingr
Copy link
Contributor

Thanks so much @AayushChaudhary0001. All 3 of those commands are generally unimplemented and should be removed from the codebase

Should I do that in a separate PR?

@mickmister
Copy link
Contributor Author

@fmartingr Yeah that sounds good to me

@mickmister
Copy link
Contributor Author

Rest all are tested and approved from my side.

@fmartingr It seems this PR has been approved by QA. Should we merge this and move forward with a release of this plugin, and also update the gcal plugin's commit to the next tag once created?

@fmartingr
Copy link
Contributor

Rest all are tested and approved from my side.

@fmartingr It seems this PR has been approved by QA. Should we merge this and move forward with a release of this plugin, and also update the gcal plugin's commit to the next tag once created?

Absolutely! You take care of mscalendar and I take care of gcal?

@fmartingr
Copy link
Contributor

Solved conflicts from latest changes.

@mickmister
Copy link
Contributor Author

@fmartingr Do you think this is good to merge based on QA's approval?

@fmartingr
Copy link
Contributor

@fmartingr Do you think this is good to merge based on QA's approval?

Yeah, apart from QA we did some testing ourselves back in the day, so I think this is good to go.

@mickmister
Copy link
Contributor Author

@fmartingr I need at least one dev's explicit approval on this to merge it. Can you please take a look and approve if it looks good? (which it does based on your comment)

Copy link
Contributor

@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

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

Considering this passed through QA and the Google Calendar plugin works from this, I'm giving my approval, but if we need a proper 2nd dev review I would add someone else, since we are the authors of this PR so my approval seems like cheating.

@mickmister
Copy link
Contributor Author

@larkox Do you mind giving this a review?

Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

Apart of the many "REVIEW" comments, everything seems fine. And I find this a great idea!

Are we planning on dealing with the review comments now or later?

@mickmister
Copy link
Contributor Author

mickmister commented Mar 1, 2024

@larkox I created two followup issues from those "REVIEW" comments. 3/5 none of them should be blocking for this

#357
#358

@mickmister mickmister merged commit 7f1bbcd into master Mar 1, 2024
6 checks passed
@mickmister mickmister deleted the migrate-to-gcal branch March 1, 2024 04:02
@mickmister mickmister mentioned this pull request Mar 14, 2024
@raghavaggarwal2308 raghavaggarwal2308 added this to the v1.3.0 milestone Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: QA Review Requires review by a QA tester
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants