Skip to content
Snippets Groups Projects
Commit 19daad75 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

feat(models): add to/remove from global team methods

parent 8e2ec494
No related branches found
No related tags found
2 merge requests!52Docx,!17Graphql api
......@@ -46,6 +46,7 @@
"node-cron": "^2.0.3",
"objection": "^2.2.15",
"passport": "^0.4.1",
"pg": "^8.7.3",
"pubsweet": "^5.1.25",
"pubsweet-server": "^13.12.5",
"uuid": "^8.3.2",
......@@ -57,6 +58,9 @@
"jest": "^26.6.3",
"standard-version": "^7.1.0"
},
"resolutions": {
"pg": "^8.7.3"
},
"config": {
"commitizen": {
"path": "cz-customizable"
......
......@@ -324,4 +324,56 @@ describe('Team Model', () => {
expect(foundUser.teams).toHaveLength(0)
})
it('adds member to global team by role', async () => {
const editorTeam = await Team.insert({
role: 'editor',
displayName: 'Editor',
global: true,
})
const user = await User.insert({})
let members = await TeamMember.find({
teamId: editorTeam.id,
})
expect(members.result).toEqual([])
await Team.addMemberToGlobalTeam(user.id, 'editor')
members = await TeamMember.find({
teamId: editorTeam.id,
})
expect(members.result.length).toEqual(1)
expect(members.result[0].userId).toEqual(user.id)
})
it('removes member from global team by role', async () => {
const editorTeam = await Team.insert({
role: 'editor',
displayName: 'Editor',
global: true,
})
const user = await User.insert({})
await Team.addMemberToGlobalTeam(user.id, 'editor')
let members = await TeamMember.find({
teamId: editorTeam.id,
})
expect(members.result.length).toEqual(1)
expect(members.result[0].userId).toEqual(user.id)
await Team.removeMemberFromGlobalTeam(user.id, 'editor')
members = await TeamMember.find({
teamId: editorTeam.id,
})
expect(members.result).toEqual([])
})
})
......@@ -119,14 +119,22 @@ describe('User Controller', () => {
it('can allow user to login with email and password', async () => {
const { id } = await createUserWithPasswordAndIdentities('password1')
const res = await login('password1', id.email)
const res = await login({
email: id.email,
password: 'password1',
})
expect(res.token).toBeDefined()
})
it('can allow user to login with username and password', async () => {
const { user } = await createUserWithPasswordAndIdentities('password1')
const res = await login('password1', undefined, user.username)
const res = await login({
username: user.username,
password: 'password1',
})
expect(res.token).toBeDefined()
})
......
......@@ -249,6 +249,44 @@ class Team extends BaseModel {
throw new Error(e)
}
}
static async addMemberToGlobalTeam(userId, role, options = {}) {
try {
const { trx } = options
const team = await Team.findOne(
{
role,
global: true,
},
{ trx },
)
return Team.addMember(team.id, userId, options)
} catch (e) {
logger.error(`Team model: Add member to global team: ${e.message}`)
throw new Error(e)
}
}
static async removeMemberFromGlobalTeam(userId, role, options = {}) {
try {
const { trx } = options
const team = await Team.findOne(
{
role,
global: true,
},
{ trx },
)
return Team.removeMember(team.id, userId, options)
} catch (e) {
logger.error(`Team model: Remove member from global team: ${e.message}`)
throw new Error(e)
}
}
}
module.exports = Team
......@@ -9194,20 +9194,15 @@ pg-boss@^5.2.0:
pg "^8.5.1"
uuid "^8.3.2"
 
pg-connection-string@0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-0.1.3.tgz#da1847b20940e42ee1492beaf65d49d91b245df7"
integrity sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=
pg-connection-string@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.3.0.tgz#c13fcb84c298d0bfa9ba12b40dd6c23d946f55d6"
integrity sha512-ukMTJXLI7/hZIwTW7hGMZJ0Lj0S2XQBCJ4Shv4y1zgQ/vqVea+FLhzywvPj0ujSuofu+yA4MYHGZPTsgjBgJ+w==
 
pg-connection-string@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.4.0.tgz#c979922eb47832999a204da5dbe1ebf2341b6a10"
integrity sha512-3iBXuv7XKvxeMrIgym7njT+HlZkwZqqGX4Bu9cci8xHZNT+Um1gWKqCsAzcC0d95rcKMU5WBg6YRUcHyV0HZKQ==
pg-connection-string@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34"
integrity sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==
 
pg-int8@1.0.1:
version "1.0.1"
......@@ -9219,25 +9214,15 @@ pg-ipc@^1.0.4:
resolved "https://registry.yarnpkg.com/pg-ipc/-/pg-ipc-1.0.4.tgz#e018f5aae417ded8a917878e33c1fe911bcce45f"
integrity sha1-4Bj1quQX3tipF4eOM8H+kRvM5F8=
 
pg-packet-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914"
integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg==
pg-pool@^2.0.10:
version "2.0.10"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a"
integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg==
pg-pool@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.2.2.tgz#a560e433443ed4ad946b84d774b3f22452694dff"
integrity sha512-ORJoFxAlmmros8igi608iVEbQNNZlp89diFVx6yV5v+ehmpMY9sK6QgpmgoXbmkNaBAx8cOOZh9g80kJv1ooyA==
pg-pool@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.5.1.tgz#f499ce76f9bf5097488b3b83b19861f28e4ed905"
integrity sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==
 
pg-protocol@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.4.0.tgz#43a71a92f6fe3ac559952555aa3335c8cb4908be"
integrity sha512-El+aXWcwG/8wuFICMQjM5ZSAm6OWiJicFdNYo+VY3QP+8vI4SvLIWVe51PppTzMhikUJR+PsyIFKqfdXPz/yxA==
pg-protocol@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.5.0.tgz#b5dd452257314565e2d54ab3c132adc46565a6a0"
integrity sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ==
 
pg-types@^2.1.0:
version "2.2.0"
......@@ -9250,30 +9235,16 @@ pg-types@^2.1.0:
postgres-date "~1.0.4"
postgres-interval "^1.1.0"
 
pg@^7.4.1, pg@^7.8.0:
version "7.18.2"
resolved "https://registry.yarnpkg.com/pg/-/pg-7.18.2.tgz#4e219f05a00aff4db6aab1ba02f28ffa4513b0bb"
integrity sha512-Mvt0dGYMwvEADNKy5PMQGlzPudKcKKzJds/VbOeZJpb6f/pI3mmoXX0JksPgI3l3JPP/2Apq7F36O63J7mgveA==
pg@^7.4.1, pg@^7.8.0, pg@^8.5.1, pg@^8.7.3:
version "8.7.3"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.7.3.tgz#8a5bdd664ca4fda4db7997ec634c6e5455b27c44"
integrity sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==
dependencies:
buffer-writer "2.0.0"
packet-reader "1.0.0"
pg-connection-string "0.1.3"
pg-packet-stream "^1.1.0"
pg-pool "^2.0.10"
pg-types "^2.1.0"
pgpass "1.x"
semver "4.3.2"
pg@^8.5.1:
version "8.5.1"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.5.1.tgz#34dcb15f6db4a29c702bf5031ef2e1e25a06a120"
integrity sha512-9wm3yX9lCfjvA98ybCyw2pADUivyNWT/yIP4ZcDVpMN0og70BUWYEGXPCTAQdGTAqnytfRADb7NERrY1qxhIqw==
dependencies:
buffer-writer "2.0.0"
packet-reader "1.0.0"
pg-connection-string "^2.4.0"
pg-pool "^3.2.2"
pg-protocol "^1.4.0"
pg-connection-string "^2.5.0"
pg-pool "^3.5.1"
pg-protocol "^1.5.0"
pg-types "^2.1.0"
pgpass "1.x"
 
......@@ -10376,11 +10347,6 @@ semver-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
 
semver@4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.2.tgz#c7a07158a80bedd052355b770d82d6640f803be7"
integrity sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=
semver@6.3.0, semver@^6.0.0, semver@^6.1.0, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment