Skip to content

Commit 3d953d3

Browse files
authored
Slack notifications automation (#833)
1 parent a33a0a4 commit 3d953d3

67 files changed

Lines changed: 2261 additions & 1199 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/.env.dist.local

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ CROWD_SLACK_CLIENT_SECRET=
102102
CROWD_SLACK_REPORTER_TOKEN=
103103
CROWD_SLACK_REPORTER_CHANNEL=
104104

105+
# Slack notifier settings
106+
CROWD_SLACK_NOTIFIER_CLIENT_ID=
107+
CROWD_SLACK_NOTIFIER_CLIENT_SECRET=
108+
105109
# Google settings
106110
CROWD_GOOGLE_CLIENT_ID=
107111
CROWD_GOOGLE_CLIENT_SECRET=

backend/config/custom-environment-variables.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
"appId": "CROWD_SLACK_APP_ID",
115115
"appToken": "CROWD_SLACK_APP_TOKEN"
116116
},
117+
"slackNotifier": {
118+
"clientId": "CROWD_SLACK_NOTIFIER_CLIENT_ID",
119+
"clientSecret": "CROWD_SLACK_NOTIFIER_CLIENT_SECRET"
120+
},
117121
"google": {
118122
"clientId": "CROWD_GOOGLE_CLIENT_ID",
119123
"clientSecret": "CROWD_GOOGLE_CLIENT_SECRET",

backend/config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"slack": {
3232
"maxRetrospectInSeconds": 3600
3333
},
34+
"slackNotifier": {},
3435
"google": {},
3536
"discord": {
3637
"maxRetrospectInSeconds": 3600

backend/package-lock.json

Lines changed: 215 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"formidable-serverless": "1.1.1",
8585
"he": "^1.2.0",
8686
"helmet": "4.1.1",
87+
"html-to-mrkdwn-ts": "^1.1.0",
8788
"html-to-text": "^8.2.1",
8889
"json2csv": "^5.0.7",
8990
"jsonwebtoken": "8.5.1",

backend/src/api/apiResponseHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class ApiResponseHandler extends LoggingBase {
3232
method: req.method,
3333
query: error.sql,
3434
body: req.body,
35-
errorMessage: error.original.message,
35+
errorMessage: error.original?.message,
3636
},
3737
'Database error while processing REST API request!',
3838
)

backend/src/api/auth/authMe.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default async (req, res) => {
3434
activityTypes: await SettingsRepository.buildActivityTypes(
3535
tenantUser.tenant.settings[0].dataValues,
3636
),
37+
slackWebHook: !!tenantUser.tenant.settings[0].dataValues.slackWebHook,
3738
}
3839

3940
return tenantUser
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Axios from 'axios'
2+
import Permissions from '../../security/permissions'
3+
import PermissionChecker from '../../services/user/permissionChecker'
4+
import SettingsService from '../../services/settingsService'
5+
6+
export default async (req, res) => {
7+
new PermissionChecker(req).validateHas(Permissions.values.automationCreate)
8+
const { redirectUrl } = JSON.parse(Buffer.from(req.query.state, 'base64').toString())
9+
10+
const { url } = req.account
11+
12+
await SettingsService.save({ slackWebHook: url }, req)
13+
await Axios.post(url, {
14+
text: 'Crowd.dev Notifier has been successfully connected.',
15+
})
16+
17+
res.redirect(redirectUrl)
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import passport from 'passport'
2+
import Permissions from '../../security/permissions'
3+
import PermissionChecker from '../../services/user/permissionChecker'
4+
import { getSlackNotifierStrategy } from '../../services/auth/passportStrategies/slackStrategy'
5+
6+
export default async (req, res, next) => {
7+
new PermissionChecker(req).validateHas(Permissions.values.automationCreate)
8+
const state = {
9+
tenantId: req.params.tenantId,
10+
redirectUrl: req.query.redirectUrl,
11+
crowdToken: req.query.crowdToken,
12+
}
13+
14+
const authenticator = passport.authenticate(getSlackNotifierStrategy(), {
15+
scope: ['incoming-webhook'],
16+
state: Buffer.from(JSON.stringify(state)).toString('base64'),
17+
})
18+
19+
authenticator(req, res, next)
20+
}

0 commit comments

Comments
 (0)