Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Labels
Plan
Issues
25
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cokoapps
server
Commits
f04f5892
Commit
f04f5892
authored
1 year ago
by
Duncan Bennett
Committed by
Yannis Barlas
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(models): add constraint that makes provider-email combinations unique
parent
a17dcc62
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!64
fix: unique provider email
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/models/__tests__/identity.model.test.js
+37
-0
37 additions, 0 deletions
src/models/__tests__/identity.model.test.js
src/models/identity/migrations/1700129852-unique-email-per-provider.js
+33
-0
33 additions, 0 deletions
...entity/migrations/1700129852-unique-email-per-provider.js
with
70 additions
and
0 deletions
src/models/__tests__/identity.model.test.js
+
37
−
0
View file @
f04f5892
...
...
@@ -99,4 +99,41 @@ describe('Identity model', () => {
identityWithProfileData
.
profileData
.
displayName
,
)
})
it
(
'
creates two identities with the same email but different provider
'
,
async
()
=>
{
const
user
=
await
createUser
()
const
createIdentity
=
async
provider
=>
{
return
Identity
.
insert
({
userId
:
user
.
id
,
email
:
'
john@example.com
'
,
provider
,
})
}
// first time should be fine
const
id1
=
await
createIdentity
(
'
test1
'
)
const
id2
=
await
createIdentity
(
'
test2
'
)
expect
(
id1
.
email
).
toEqual
(
id2
.
email
)
expect
(
id1
.
provider
).
not
.
toEqual
(
id2
.
provider
)
})
it
(
'
fails when creating two identities with the same email and provider
'
,
async
()
=>
{
const
user
=
await
createUser
()
const
createIdentity
=
async
()
=>
{
await
Identity
.
insert
({
userId
:
user
.
id
,
email
:
'
john@example.com
'
,
provider
:
'
test
'
,
})
}
// first time should be fine
await
createIdentity
()
// second time should throw an error
await
expect
(
createIdentity
).
rejects
.
toThrow
(
/unique_provider_email/
)
})
})
This diff is collapsed.
Click to expand it.
src/models/identity/migrations/1700129852-unique-email-per-provider.js
0 → 100644
+
33
−
0
View file @
f04f5892
const
logger
=
require
(
'
@pubsweet/logger
'
)
exports
.
up
=
async
knex
=>
{
try
{
await
knex
.
schema
.
alterTable
(
'
identities
'
,
table
=>
{
table
.
dropUnique
([
'
email
'
],
'
unique_email
'
)
})
await
knex
.
raw
(
'
ALTER TABLE identities ADD CONSTRAINT unique_provider_email UNIQUE (provider, email);
'
,
)
return
true
}
catch
(
e
)
{
logger
.
error
(
e
)
throw
new
Error
(
'
Migration: Identity: require unique email per provider failed
'
,
)
}
}
exports
.
down
=
async
knex
=>
{
try
{
await
knex
.
schema
.
alterTable
(
'
identities
'
,
table
=>
{
table
.
dropUnique
([
'
provider
'
,
'
email
'
],
'
unique_provider_email
'
)
})
await
knex
.
raw
(
'
ALTER TABLE identities ADD CONSTRAINT unique_email UNIQUE (email);
'
,
)
return
true
}
catch
(
e
)
{
logger
.
error
(
e
)
throw
new
Error
(
'
Migration: Identity: require unique email failed
'
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment