-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Vendor verification #1208
Changes from 21 commits
130f64e
21a1cbc
3ad89f6
4c90249
6fa7096
442130a
df70d43
15f5ca8
815f6f2
7675404
749ff98
52f8835
263f631
df8031a
2eea45a
7e5b4ed
0b2e110
c650638
48c4f2f
f1c1ab7
3273e14
051e41b
265e6d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,12 @@ const ME_FIELDS = gql` | |
id | ||
username | ||
roles | ||
company { | ||
id | ||
ats { | ||
id | ||
} | ||
} | ||
} | ||
`; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -827,7 +827,12 @@ export default ( | |
me: { | ||
id: '1', | ||
username: 'foo-bar', | ||
roles: ['ADMIN', 'TESTER'] | ||
roles: ['ADMIN', 'TESTER'], | ||
company: { | ||
id: '1', | ||
name: 'Company', | ||
ats: [] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the mock, would these need a company since the roles assigned here doesn't include 'VENDOR'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great point! Addressed. |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
const { User } = require('../models'); | ||
const { getOrCreateUser } = require('../models/services/UserService'); | ||
const { | ||
getOrCreateUser, | ||
addUserVendor, | ||
getUserById | ||
} = require('../models/services/UserService'); | ||
const { GithubService } = require('../services'); | ||
const getUsersFromFile = require('../util/getUsersFromFile'); | ||
const { | ||
findVendorByName, | ||
getOrCreateVendor | ||
} = require('../models/services/VendorService'); | ||
|
||
const APP_SERVER = process.env.APP_SERVER; | ||
|
||
|
@@ -70,6 +78,40 @@ const oauthRedirectFromGithubController = async (req, res) => { | |
transaction: req.transaction | ||
}); | ||
|
||
if (roles.some(role => role.name === User.VENDOR)) { | ||
const vendorEntry = vendors.find( | ||
vendor => vendor.split('|')[0] === githubUsername | ||
); | ||
if (vendorEntry) { | ||
const [, companyName] = vendorEntry.split('|'); | ||
const vendor = await findVendorByName({ | ||
name: companyName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to trim this just in case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I added a |
||
transaction: req.transaction | ||
}); | ||
if (vendor) { | ||
await addUserVendor(user.id, vendor.id, { | ||
transaction: req.transaction | ||
}); | ||
} else { | ||
const vendor = await getOrCreateVendor({ | ||
where: { name: companyName }, | ||
transaction: req.transaction | ||
}); | ||
await addUserVendor(user.id, vendor.id, { | ||
transaction: req.transaction | ||
}); | ||
} | ||
// Fetch the user again with vendor and AT information | ||
user = await getUserById({ | ||
id: user.id, | ||
vendorAttributes: ['id', 'name'], | ||
atAttributes: ['id', 'name'], | ||
includeVendorAts: true, | ||
transaction: req.transaction | ||
}); | ||
} | ||
} | ||
|
||
req.session.user = user; | ||
|
||
return loginSucceeded(); | ||
|
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.
👍🏽 👍🏽