Skip to content

Commit a0dc2d8

Browse files
author
Uros Marolt
authored
Member exists optimization and prettier fix (#1026)
1 parent b04f30d commit a0dc2d8

File tree

9 files changed

+270
-250
lines changed

9 files changed

+270
-250
lines changed
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import passport from 'passport'
2-
import { PlatformType } from '@crowd/types'
3-
import Permissions from '../../../security/permissions'
4-
import PermissionChecker from '../../../services/user/permissionChecker'
1+
// import passport from 'passport'
2+
// import { PlatformType } from '@crowd/types'
3+
// import Permissions from '../../../security/permissions'
4+
// import PermissionChecker from '../../../services/user/permissionChecker'
55

6-
export default async (req, res, next) => {
7-
// Checking we have permision to edit the project
8-
new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
6+
// export default async (req, res, next) => {
7+
// // Checking we have permision to edit the project
8+
// new PermissionChecker(req).validateHas(Permissions.values.integrationEdit)
99

10-
const state = {
11-
tenantId: req.params.tenantId,
12-
redirectUrl: req.query.redirectUrl,
13-
hashtags: req.query.hashtags ? req.query.hashtags : '',
14-
crowdToken: req.query.crowdToken,
15-
platform: PlatformType.TWITTER,
16-
userId: req.currentUser.id,
17-
}
10+
// const state = {
11+
// tenantId: req.params.tenantId,
12+
// redirectUrl: req.query.redirectUrl,
13+
// hashtags: req.query.hashtags ? req.query.hashtags : '',
14+
// crowdToken: req.query.crowdToken,
15+
// platform: PlatformType.TWITTER,
16+
// userId: req.currentUser.id,
17+
// }
1818

19-
const authenticator = passport.authenticate('twitter', {
20-
scope: ['tweet.read', 'tweet.write', 'users.read', 'follows.read', 'offline.access'],
21-
state,
22-
})
19+
// const authenticator = passport.authenticate('twitter', {
20+
// scope: ['tweet.read', 'tweet.write', 'users.read', 'follows.read', 'offline.access'],
21+
// state,
22+
// })
2323

24-
authenticator(req, res, next)
25-
}
24+
// authenticator(req, res, next)
25+
// }

backend/src/api/integration/index.ts

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import passport from 'passport'
2-
import { API_CONFIG, SLACK_CONFIG, TWITTER_CONFIG } from '../../conf'
2+
import { API_CONFIG, SLACK_CONFIG } from '../../conf'
3+
import SegmentRepository from '../../database/repositories/segmentRepository'
34
import { authMiddleware } from '../../middlewares/authMiddleware'
4-
import TenantService from '../../services/tenantService'
55
import { safeWrap } from '../../middlewares/errorMiddleware'
6-
import SegmentRepository from '../../database/repositories/segmentRepository'
6+
import TenantService from '../../services/tenantService'
77

88
export default (app) => {
99
app.post(`/tenant/:tenantId/integration/query`, safeWrap(require('./integrationQuery').default))
@@ -76,60 +76,60 @@ export default (app) => {
7676
safeWrap(require('./helpers/discourseTestWebhook').default),
7777
)
7878

79-
if (TWITTER_CONFIG.clientId) {
80-
/**
81-
* Using the passport.authenticate this endpoint forces a
82-
* redirect to happen to the twitter oauth2 page.
83-
* We keep a state of the important variables such as tenantId, redirectUrl, ..
84-
* so that after user logs in through the twitter page, these
85-
* variables are forwarded back to the callback as well
86-
* This state is sent using the authenticator options and
87-
* manipulated through twitterStrategy.staticPKCEStore
88-
*/
89-
app.get(
90-
'/twitter/:tenantId/connect',
91-
safeWrap(require('./helpers/twitterAuthenticate').default),
92-
() => {
93-
// The request will be redirected for authentication, so this
94-
// function will not be called.
95-
},
96-
)
79+
// if (TWITTER_CONFIG.clientId) {
80+
// /**
81+
// * Using the passport.authenticate this endpoint forces a
82+
// * redirect to happen to the twitter oauth2 page.
83+
// * We keep a state of the important variables such as tenantId, redirectUrl, ..
84+
// * so that after user logs in through the twitter page, these
85+
// * variables are forwarded back to the callback as well
86+
// * This state is sent using the authenticator options and
87+
// * manipulated through twitterStrategy.staticPKCEStore
88+
// */
89+
// app.get(
90+
// '/twitter/:tenantId/connect',
91+
// safeWrap(require('./helpers/twitterAuthenticate').default),
92+
// () => {
93+
// // The request will be redirected for authentication, so this
94+
// // function will not be called.
95+
// },
96+
// )
9797

98-
/**
99-
* OAuth2 callback endpoint. After user successfully
100-
* logs in through twitter page s/he is redirected to
101-
* this endpoint. Few middlewares first mimic a proper
102-
* api request in this order:
103-
*
104-
* Set headers-> Auth middleware (currentUser)-> Set currentTenant
105-
* -> finally we call the project service to update the
106-
* corresponding project.
107-
*
108-
* We have to call these standart middlewares explicitly because
109-
* the request method is get and tenant id does not exist in the
110-
* uri as request parameters.
111-
*
112-
*/
113-
app.get(
114-
'/twitter/callback',
115-
passport.authenticate('twitter', {
116-
session: false,
117-
failureRedirect: `${API_CONFIG.frontendUrl}/integrations?error=true`,
118-
}),
119-
(req, _res, next) => {
120-
const crowdToken = new URLSearchParams(req.query.state).get('crowdToken')
121-
req.headers.authorization = `Bearer ${crowdToken}`
122-
next()
123-
},
124-
authMiddleware,
125-
async (req, _res, next) => {
126-
const tenantId = new URLSearchParams(req.query.state).get('tenantId')
127-
req.currentTenant = await new TenantService(req).findById(tenantId)
128-
next()
129-
},
130-
safeWrap(require('./helpers/twitterAuthenticateCallback').default),
131-
)
132-
}
98+
// /**
99+
// * OAuth2 callback endpoint. After user successfully
100+
// * logs in through twitter page s/he is redirected to
101+
// * this endpoint. Few middlewares first mimic a proper
102+
// * api request in this order:
103+
// *
104+
// * Set headers-> Auth middleware (currentUser)-> Set currentTenant
105+
// * -> finally we call the project service to update the
106+
// * corresponding project.
107+
// *
108+
// * We have to call these standart middlewares explicitly because
109+
// * the request method is get and tenant id does not exist in the
110+
// * uri as request parameters.
111+
// *
112+
// */
113+
// app.get(
114+
// '/twitter/callback',
115+
// passport.authenticate('twitter', {
116+
// session: false,
117+
// failureRedirect: `${API_CONFIG.frontendUrl}/integrations?error=true`,
118+
// }),
119+
// (req, _res, next) => {
120+
// const crowdToken = new URLSearchParams(req.query.state).get('crowdToken')
121+
// req.headers.authorization = `Bearer ${crowdToken}`
122+
// next()
123+
// },
124+
// authMiddleware,
125+
// async (req, _res, next) => {
126+
// const tenantId = new URLSearchParams(req.query.state).get('tenantId')
127+
// req.currentTenant = await new TenantService(req).findById(tenantId)
128+
// next()
129+
// },
130+
// safeWrap(require('./helpers/twitterAuthenticateCallback').default),
131+
// )
132+
// }
133133

134134
/**
135135
* Slack integration endpoints

0 commit comments

Comments
 (0)