-
Notifications
You must be signed in to change notification settings - Fork 481
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
Conversation
Codecov Report
@@ 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 |
…lhelm-test into private-unfurls-settings
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.
Nice work! This is looking really good.
}); | ||
|
||
next(); | ||
}; |
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.
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.
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.
Two ways in which this is different from the authenticate
middleware:
- (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 onres.locals
- 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 isreq.body.user_id
, whereas on actions it'sreq.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.
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.
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 👍
lib/middleware/route-action.js
Outdated
if (res.locals.action === 'cancel') { | ||
return res.send({ | ||
delete_original: true, | ||
}); |
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.
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. 🤷♂️
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.
Agreed. Moving this all the way to the end is better, although it does add some additional code to each action handler 🤔
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.
As part of the action based routing, this actually ended up being quite nice
unfurlAction, | ||
showRichPreview, | ||
unfurlAutoSetting, | ||
mutePrompts, |
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.
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.
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.
Moved a lot of things out of this file as part of the action-based routing refactor.
lib/models/slack-user.js
Outdated
return true; | ||
} | ||
return false; | ||
}, |
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.
This can be simplified quite a bit:
return this.settings.muteUnfurlPromptsIndefinitely || (
this.settings.muteUnfurlPromptsUntil &&
moment.unix(this.settings.muteUnfurlPromptsUntil) > moment()
)
lib/slack/index.js
Outdated
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`); |
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.
…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?
lib/unfurls/index.js
Outdated
@@ -71,16 +78,17 @@ async function linkShared(req, res) { | |||
user: event.user, | |||
attachments: [new PrivateUnfurlPrompt(newUnfurl).getAttachment()], | |||
}); | |||
} else { | |||
return Promise.resolve(); |
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.
Unless I'm missing something, I think this can just return;
without the Promise.resolve()
lib/unfurls/index.js
Outdated
settings: { | ||
muteUnfurlPromptsUntil: moment().add(24, 'hours').unix(), | ||
}, | ||
}); |
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.
Can this be added to a method on the model?
lib/unfurls/index.js
Outdated
attachments: [new MutePromptsSettingConfirm('for 24h').getAttachment()], | ||
}); | ||
} | ||
if (res.locals.action === 'mute-indefinitely') { |
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.
There's quite a few conditionals here. Would it make sense to also try to route based on action?
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.
👍 looks great.
@@ -34,7 +34,7 @@ module.exports = class AutoUnfurlPrompt extends Message { | |||
}, | |||
{ | |||
name: 'cancel', | |||
text: 'Cancel', | |||
text: 'Always prompt me', |
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.
"Always ask me"?
@@ -29,7 +29,7 @@ module.exports = class MutePromptsPrompt extends Message { | |||
}, | |||
{ | |||
name: 'cancel', | |||
text: 'Cancel', | |||
text: 'Always prompt me', |
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.
"Always ask me"?
…ack into private-unfurls-settings
Implements user settings to move us closer to shipping private unfurls
Things to do:
Deploy notes: