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

Private unfurl user settings #528

Merged
merged 51 commits into from
May 1, 2018
Merged

Private unfurl user settings #528

merged 51 commits into from
May 1, 2018

Conversation

wilhelmklopp
Copy link
Contributor

@wilhelmklopp wilhelmklopp commented Apr 13, 2018

Implements user settings to move us closer to shipping private unfurls

Things to do:

Deploy notes:

  • Need to deploy to migrations app first when promoting

@codecov
Copy link

codecov bot commented Apr 13, 2018

Codecov Report

Merging #528 into master will increase coverage by 0.09%.
The diff coverage is 99.13%.

@@            Coverage Diff             @@
##           master     #528      +/-   ##
==========================================
+ Coverage   98.44%   98.53%   +0.09%     
==========================================
  Files         105      113       +8     
  Lines        1608     1707      +99     
  Branches      201      207       +6     
==========================================
+ Hits         1583     1682      +99     
  Misses         22       22              
  Partials        3        3

@bkeepers bkeepers mentioned this pull request Apr 18, 2018
6 tasks
@wilhelmklopp wilhelmklopp mentioned this pull request Apr 24, 2018
2 tasks
Copy link
Contributor

@bkeepers bkeepers left a comment

Choose a reason for hiding this comment

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

Nice work! This is looking really good.

});

next();
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks really similar to the authenticate middleware. Is there any way we could share them? Maybe one to look up the current workspace/user, and the other just verifies that the current user has a GitHub user associated?

Also I'm not sure what action-attach-metadata means in the context of authentication/authorization.

Copy link
Contributor Author

@wilhelmklopp wilhelmklopp Apr 30, 2018

Choose a reason for hiding this comment

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

Two ways in which this is different from the authenticate middleware:

  1. (the big one): The authenticate middleware ensures that a GitHub account is connected (to an existing slackUser). action-attach-metadata goes as far as creating a new slackUser if one doesn't exist, just to make the slackUser available on res.locals
  2. The data format is slightly different between slash commands (where authenticate is in use thus far) and actions. For example on slash commands a user id is req.body.user_id, whereas on actions it's req.body.user.id

Also I'm not sure what action-attach-metadata means in the context of authentication/authorization.

I'm not sure if what the middleware does is really authentication/authorization. It's kind of just a helper that makes the model available so that each "action route" doesn't have to worry about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe one to look up the current workspace/user, and the other just verifies that the current user has a GitHub user associated?

I agree this would be good to do 👍

if (res.locals.action === 'cancel') {
return res.send({
delete_original: true,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this always be the case? Curious if it'd make sense to include this as a middleware/route handler at the end of all the actions that only does this if nothing else has handled the response. 🤷‍♂️

Copy link
Contributor Author

@wilhelmklopp wilhelmklopp Apr 30, 2018

Choose a reason for hiding this comment

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

Agreed. Moving this all the way to the end is better, although it does add some additional code to each action handler 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of the action based routing, this actually ended up being quite nice

unfurlAction,
showRichPreview,
unfurlAutoSetting,
mutePrompts,
Copy link
Contributor

Choose a reason for hiding this comment

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

this file is getting a little gnarly. We don't have to anything now, but it'd be good to start thinking about refactoring this to be a little easier to grok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved a lot of things out of this file as part of the action-based routing refactor.

return true;
}
return false;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified quite a bit:

return this.settings.muteUnfurlPromptsIndefinitely || (
  this.settings.muteUnfurlPromptsUntil &&
  moment.unix(this.settings.muteUnfurlPromptsUntil) > moment()
)

router.post('/actions:unfurl-mute-prompts', unfurls.mutePrompts);

router.post(/actions:.*/, (req) => {
throw new Error(`Callback id "${req.body.callback_id}" does not match any patterns`);
Copy link
Contributor

Choose a reason for hiding this comment

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

…does not match any patterns

nit: I get what that is trying to say, but maybe "not found" would be a better way of describing it?

@@ -71,16 +78,17 @@ async function linkShared(req, res) {
user: event.user,
attachments: [new PrivateUnfurlPrompt(newUnfurl).getAttachment()],
});
} else {
return Promise.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something, I think this can just return; without the Promise.resolve()

settings: {
muteUnfurlPromptsUntil: moment().add(24, 'hours').unix(),
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be added to a method on the model?

attachments: [new MutePromptsSettingConfirm('for 24h').getAttachment()],
});
}
if (res.locals.action === 'mute-indefinitely') {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's quite a few conditionals here. Would it make sense to also try to route based on action?

Copy link
Contributor

@bkeepers bkeepers left a comment

Choose a reason for hiding this comment

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

👍 looks great.

@@ -34,7 +34,7 @@ module.exports = class AutoUnfurlPrompt extends Message {
},
{
name: 'cancel',
text: 'Cancel',
text: 'Always prompt me',
Copy link
Contributor

Choose a reason for hiding this comment

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

"Always ask me"?

@@ -29,7 +29,7 @@ module.exports = class MutePromptsPrompt extends Message {
},
{
name: 'cancel',
text: 'Cancel',
text: 'Always prompt me',
Copy link
Contributor

Choose a reason for hiding this comment

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

"Always ask me"?

@wilhelmklopp wilhelmklopp merged commit 6024b6a into master May 1, 2018
@wilhelmklopp wilhelmklopp deleted the private-unfurls-settings branch May 17, 2018 09:39
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.

2 participants