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

Login workflow #44

Merged
merged 38 commits into from
Apr 28, 2020
Merged

Login workflow #44

merged 38 commits into from
Apr 28, 2020

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Mar 3, 2020

Summary

Added a first approach to the login workflow defined here. The current solution is far from optimal, but allows us to get a better understanding of the different moving parts of the solution.

I will keep working to improve the different parts, both in how to present the data, and the underlying architecture. Here is the current look of a full login process.

image

@larkox larkox requested a review from mickmister March 3, 2020 19:56
@mickmister mickmister added the Work In Progress Not yet ready for review label Mar 4, 2020
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.

@larkox Great job with the Welcomer patterns introduced.

My main blocker here is getting the mscalendar-specific Welcomer code out of the utils package. No issues found otherwise 👍

c.Config.PluginURL)
out := "The bot just sent you a message with the instructions to connect."
if err := c.MSCalendar.Welcome(c.Args.UserId); err != nil {
out = "There has been a problem while trying to connect."
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like two spaces got in there somehow

Suggested change
out = "There has been a problem while trying to connect."
out = "There has been a problem while trying to connect."

config.ApplicationName,
c.Config.PluginURL)
out := "The bot just sent you a message with the instructions to connect."
if err := c.MSCalendar.Welcome(c.Args.UserId); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're moving away from the if statements in this format, favoring:

err := c.MSCalendar.Welcome(c.Args.UserId)
if err != nil {
	out = "There has been a problem while trying to connect."
}

Welcome(userID string) error
AfterSuccessfullyConnect(userID, userLogin string) error
AfterUpdateStatus(userID string, status bool) error
AfterSetConfirmations(userID string, set bool) error
Copy link
Contributor

@mickmister mickmister Mar 4, 2020

Choose a reason for hiding this comment

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

The utils package is more-or-less supposed to be plugin-agnostic. Maybe this code should go into the mscalendar package since the sign-up flow is specific to this plugin. Then we can access the typed kvstore in the store package, to store the WelcomePostID.

Edit: Or it can go in a new package that has knowledge of the mscalendar package.

@larkox larkox requested a review from mickmister March 4, 2020 13:19
@larkox
Copy link
Contributor Author

larkox commented Mar 11, 2020

Here I leave some screenshots of the current behaviour:
Ephemeral:
image
Bot messages step 1:
image
Bot messages step 2:
image
Bot messages step 3:
image
Bot messages step 4:
image

@larkox larkox requested review from levb and aaronrothschild March 11, 2020 09:14
@codecov-io
Copy link

codecov-io commented Mar 11, 2020

Codecov Report

Merging #44 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #44   +/-   ##
=======================================
  Coverage   21.62%   21.62%           
=======================================
  Files          64       64           
  Lines        2418     2418           
=======================================
  Hits          523      523           
  Misses       1836     1836           
  Partials       59       59           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a5c110...5a5c110. Read the comment docs.

Copy link
Contributor

@levb levb left a comment

Choose a reason for hiding this comment

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

Left initial feedback; can use a clarification on the stored states/transitions.

Makefile Outdated Show resolved Hide resolved
server/mscalendar/calendar.go Outdated Show resolved Hide resolved
@@ -18,6 +18,7 @@ type MSCalendar interface {
EventResponder
Subscriptions
Users
Welcome(userID string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not Welcomer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(1/5) MSCalendar is not a welcomer, the bot in the dependencies is. But MSCalendar must know how to greet a new user, to be used on the commands, so that is why we expose that function on the interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dunno, I'd advocate composing the entire interface in. What's the harm? Polluting MSCalendar namespace?

AfterDisconnect(userID string) error
}

type MSCalendarBot struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest s/MSCalendarBot/welcomer/ or... what I think is really the idea here was to have a mscalendar.Bot (implemented as type bot struct) that implements all messaging, not just Welcome.

}

func (bot *MSCalendarBot) AfterSuccessfullyConnect(userID, userLogin string) error {
user, err := bot.Store.LoadUser(userID)
Copy link
Contributor

Choose a reason for hiding this comment

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

in solar lottery I chose to pass in *User, etc and then Expand - most of the time the caller should have the expanded entity values already, if not, create an ID-only entity, and it gets expanded to format the message. Ping me if you want an example.

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 understand the benefit and how to do it, but I think with the new shape of the program this is not necessary. Could you confirm?

server/store/welcome_store.go Show resolved Hide resolved
@larkox
Copy link
Contributor Author

larkox commented Mar 12, 2020

@levb After our conversation yesterday, I could not stop thinking about making the flow more detached from the welcome logic, so I made a refactoring in this line. Now we can add any steps we want as long as they are Yes/No questions.

With the current implementation, we declare our flow with its steps (an implementation of Flow interface) and our flowStore (an implementation of FlowStore). With that, Welcomer still handles the connection, but all the flow of Yes/No questions is handled by the Flow.

@larkox larkox requested a review from levb March 12, 2020 17:24
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 @larkox! Just some suggestions and questions.

},
expectedOutput: "[Click here to link your Microsoft Calendar account.](http://localhost/oauth2/connect)",
expectedError: "",
expectedOutput: `Welcome to the Microsoft Calendar Bot.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this should be worded as, but I'm thinking that we should be welcoming them to the plugin or the functionality, instead of the bot.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should review the consolidated messages with @aaronrothschild and @asaadmahmood - let's focus on making sure they're all "in one place"?

@@ -1,4 +1,4 @@
package mscalendar
package mscalendar_test
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a confused question, but if it's a separate package, wouldn't ./test be a better place?

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 a workaround that Go has for cycles in the tests. Conceptually, it is still a test of mscalendar, but due to the import cycles, it cannot be part of mscalendar package. With this naming, the compiler consider this a separate package, which solves the import cycles.

Copy link
Contributor

Choose a reason for hiding this comment

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

^^ seems fishy to me, we should be well-clear of cyclical dependencies. I'm ok with the PR as is, but would like to understand this better, offline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved by creating the mock of the welcomer in a different package.

server/mscalendar/welcomer.go Outdated Show resolved Hide resolved
server/mscalendar/welcomer.go Outdated Show resolved Hide resolved
server/utils/bot/bot.go Outdated Show resolved Hide resolved
server/utils/flow/handler.go Outdated Show resolved Hide resolved
}

func (bot *bot) setFlowStep(userID string, step int) error {
// TODO: Use KVStore for HA
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this will be covered in this PR? I'd be fine with deferring to a ticket if you want to get this merged sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My plan is to have this covered in this PR, but I wanted to confirm first that the new shape of the flow was interesting. I will take a look to have this done tomorrow.

},
expectedOutput: "[Click here to link your Microsoft Calendar account.](http://localhost/oauth2/connect)",
expectedError: "",
expectedOutput: `Welcome to the Microsoft Calendar Bot.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should review the consolidated messages with @aaronrothschild and @asaadmahmood - let's focus on making sure they're all "in one place"?

@@ -18,6 +18,7 @@ type MSCalendar interface {
EventResponder
Subscriptions
Users
Welcome(userID string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Dunno, I'd advocate composing the entire interface in. What's the harm? Polluting MSCalendar namespace?

@@ -1,4 +1,4 @@
package mscalendar
package mscalendar_test
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a confused question, but if it's a separate package, wouldn't ./test be a better place?

}
}

func (s *step) PostSA(flowHandler string, i int) *model.SlackAttachment {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it's verbose, but 2/5 SlackAttachment please... (grep-ability)

sh.panel.Set(mattermostUserID, idString, value)
err := sh.panel.Set(mattermostUserID, idString, value)
if err != nil {
utils.SlackAttachmentError(w, "Error: cannot set the property, "+err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these errors get shown in the UI? It seems a bit low-level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, these would get shown in the UI. My idea is the error to be meaningful to debug, but we could move the internals of the error to a log in the server. Nevertheless, that would imply passing a logger to the handler, which will make things a bit dirtier.

@mickmister mickmister removed the 2: Dev Review Requires review by a core committer label Apr 21, 2020
@DHaussermann
Copy link

@larkox I have done a test run through this now. Just a couple points.

  1. It seems like the login workflow may not properly store the response to confirm login status change? Maybe this is just because the related PR is not in this branch?
    LoginWorkflow

  2. Using mscalendar connect creates the new post that is part of the login workflow as well as the previous one. So the user ends up with 2. Can you get rid of the old one?
    WorkflowConnect

  3. UX point - Tell me HOW to change the settings here (using the slash command)
    LoginWorkflowSettings

@larkox
Copy link
Contributor Author

larkox commented Apr 22, 2020

  1. That must be a bug. I will look into it ASAP.
  2. It is a complicated decision. Slash commands must return something. And we want to have this connect message on the bot. At some point I thought about a "The MSCalendar bot just sent you the information to connect", but that adds another step. Also, the normal flow would be to call the command in a different channel than the bots direct message, so in general, you will not see the two messages together. @aaronrothschild Any thoughts on this?
  3. My bad. This was changed at some point (since we didn't have a settings panel at the moment), and have to be changed again as you said.

@aaronrothschild
Copy link
Contributor

2. It is a complicated decision. Slash commands must return something. And we want to have this connect message on the bot. At some point I thought about a "The MSCalendar bot just sent you the information to connect", but that adds another step. Also, the normal flow would be to call the command in a different channel than the bots direct message, so in general, you will not see the two messages together. @aaronrothschild Any thoughts on this?

@larkox sorry, I'm not following. Where does the double message show up?

@larkox
Copy link
Contributor Author

larkox commented Apr 22, 2020

@aaronrothschild
After /mscalendar connect you will receive an answer to the slash command (and ephemeral message) on whichever channel you are. You will also receive a Direct Message from the bot. Both messages have almost the same information, with the only difference being that the bot one will change when you successfully connect.
If you were already on the Direct Message of the bot (something that normal users will not do in general), you will see both messages together, as the image Dylan shared.
We could remove the message from the bot and just leave the command response (the ephemeral message) provide the connection link, and when the connection is finished, then send the welcome message to the user.
Or we could give as a command response a message like "The MSCalendar bot just sent you the information on how to connect your account."

@larkox
Copy link
Contributor Author

larkox commented Apr 22, 2020

@DHaussermann
Just heads up that the latest commit should fix 1 and 3.

@larkox
Copy link
Contributor Author

larkox commented Apr 23, 2020

@aaronrothschild I just discovered that slash commands can redirect the user to a different URL. What do you think about /mscalendar connect redirects to the bot direct message channel? Also, my assumption about the slash commands not being able to return nothing may be wrong. The final experience would be:

I type /mscalendar connect and hit enter. The window changes automatically to the MSCalendar bot direct message. There I find the instructions to sign in.

@larkox
Copy link
Contributor Author

larkox commented Apr 23, 2020

@DHaussermann Not sure what is happening with the CI, but this latest commit should fix also 2, so feel free to give it another round whenever you have the time.

@DHaussermann
Copy link

@larkox Thanks for the fixes! 1., 2. and 3. are resolved.

This may be ready to merge

  • Tested answering questions in every applicable combination of yes/no.
  • Data saved is accurate
  • Confirmed 3 issues above are resolved

Just a couple points:

  1. Intermittently I see the issue where answering the last question about subscription throws an error. This may be cause by data created by builds from other branches. Uninstalling the plugin and re-installing solves the issue even though it's the same build that was already running.
    ErrorOnSubscribe
    Please advise if this needs to be investigated in this PR or we're okay creating a separate issue if we see it in master.

  2. I think we should implement this suggestion to redirect the user to where the post will be Login workflow #44 (comment)

@larkox
Copy link
Contributor Author

larkox commented Apr 27, 2020

@DHaussermann

  1. It is weird. I think that this PR is becoming bit enough as it is, so I would say we merge this, and investigate the issue as a separate ticket.
  2. This should be already implemented. Can you not see this behaviour in the latest build?

@mickmister
Copy link
Contributor

mickmister commented Apr 27, 2020

I've tested this as well with no issues found. Though I agree with Dylan's comment in our conversation on MM to make it so the user can change their mind within thr settings panel about whether or not they should receive event invitations.

  1. It is weird. I think that this PR is becoming bit enough as it is, so I would say we merge this, and investigate the issue as a separate ticket.

Dylan and I have talked about stale data from different PRs affecting each other. I think it's important to document the behaviors so as to be on the lookout for them when testing master. This can be done with a follow up ticket. No reason to increase scope, thoughts @larkox?

Things like connecting to two different Microsoft accounts with one MM account (disconnecting in between them) may cause these sorts of things too. Things that we wouldn't directly design for. I'm not saying that caused this issue, just unexpected user actions like that may get the account in a weird state.

  1. This should be already implemented. Can you not see this behavior in the latest build?

I can confirm this is implemented and working correctly. In fact, when running on localhost, it redirects me to my ngrok instance's bot DM channel. This initially caught me off guard, but it ensures I am logged into the necessary domain before connecting.

LGTM 👍

@aaronrothschild We will need your blessing here

Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

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

Tested and passed.

  1. I will create an issue with as much detail as possible if I see this occur on master.
  2. Yes sorry for being unclear on this I also see the bot DM redirect happening as expected.

Thanks for all the effort on this @larkox and thanks to @mickmister for helping with some peer testing.
@aaronrothschild I will created a follow-up issue to add the subscription question to the settings panel. (#103)
LGTM!

@DHaussermann DHaussermann added the QA Review Done PR has been approved by QA label Apr 27, 2020
@aaronrothschild
Copy link
Contributor

Sweet!

@aaronrothschild aaronrothschild removed the 1: PM Review Requires review by a product manager label Apr 28, 2020
@mickmister mickmister added the 4: Reviews Complete All reviewers have approved the pull request label Apr 28, 2020
@mickmister
Copy link
Contributor

/update-branch

@mickmister mickmister merged commit 4fdc115 into mattermost:master Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request QA Review Done PR has been approved by QA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants