Commit aa75f1cd authored by Yannis Barlas's avatar Yannis Barlas

fix(dashboard): fix duplicate editor section

parent 71e5a92c
......@@ -241,7 +241,7 @@ const Dashboard = props => {
/>
)}
{isSectionEditor && (
{isSectionEditor && !isEditor && (
<Section
actions={editorActions}
allEditors={allEditors}
......
......@@ -8,9 +8,9 @@ module.exports = {
'pubsweet-server': {
db: {
database: 'test',
user: 'test',
password: 'pass',
port: 5481,
user: 'test',
},
host: 'http://localhost',
pool: {
......
......@@ -342,4 +342,74 @@ describe('Team Model', () => {
expect(membersOfManuscriptTwo.length).toEqual(1)
expect(membersOfManuscriptTwo[0].userId).toEqual(users[1].id)
})
/**
* A user is both an editor and a section editor
* If they are removed from the editor team, they should remain assigned
* to their manuscripts, since they are still a member of the section editor
* team.
*/
test('does not remove assignments if a user is both editor and section editor', async () => {
// setup
const user = await User.query().insert({})
const manuscript = await Manuscript.query().insert({})
const globalSectionEditorTeam = await Team.query().insert({
role: 'globalSectionEditor',
global: true,
})
const globalEditorTeam = await Team.query().insert({
role: 'editors',
global: true,
})
const manuscriptEditorTeam = await Team.query().insert({
role: 'editor',
objectId: manuscript.id,
objectType: 'article',
})
await Team.addMember(globalEditorTeam.id, user.id)
await Team.addMember(globalSectionEditorTeam.id, user.id)
await Team.addMember(manuscriptEditorTeam.id, user.id)
const assignedEditor = () =>
TeamMember.query()
.leftJoin('teams', 'team_members.team_id', 'teams.id')
.findOne({
role: 'editor',
objectId: manuscript.id,
userId: user.id,
})
let manuscriptEditor = await assignedEditor()
expect(manuscriptEditor).toBeDefined()
expect(manuscriptEditor.userId).toEqual(user.id)
// removing from editors should not affect assignment, as they are stil
// a section editor
await Team.removeMember(globalEditorTeam.id, user.id)
manuscriptEditor = await assignedEditor()
expect(manuscriptEditor).toBeDefined()
expect(manuscriptEditor.userId).toEqual(user.id)
// removing from section editors should not affect assignment, as they are
// still an editor
await Team.addMember(globalEditorTeam.id, user.id)
await Team.removeMember(globalSectionEditorTeam.id, user.id)
manuscriptEditor = await assignedEditor()
expect(manuscriptEditor).toBeDefined()
expect(manuscriptEditor.userId).toEqual(user.id)
// removing from both global teams, should remove them from the manuscript
// as well
await Team.removeMember(globalSectionEditorTeam.id, user.id)
await Team.removeMember(globalEditorTeam.id, user.id)
manuscriptEditor = await assignedEditor()
expect(manuscriptEditor).not.toBeDefined()
})
})
......@@ -148,16 +148,53 @@ class Team extends PubsweetTeam {
userId,
})
// If a user is removed from a global team, they should also be unassigned
// from all objects that they have that role on.
// eg. you cannot be an editor of X if you are not an editor anymore
/**
* If a user is removed from a global team, they should also be unassigned
* from all objects that they have that role on.
* eg. you cannot be an editor of X if you are not an editor anymore
*
* There might be an exception with editors. See comments below.
*/
if (team.global) {
// TO DO -- standardize
const mapper = {
editors: 'editor',
scienceOfficers: 'scienceOfficer',
globalCurator: 'curator',
globalSectionEditor: 'sectionEditor',
globalSectionEditor: 'editor',
}
/**
* If a user is removed from the global editor team, but they're still
* a section editor, they still have the right to be assigned.
*
* Same goes if the user is removed from the section editors team, but
* they are still in the editor team.
*
* Do not touch their assignments in these scenarios.
*/
if (team.role === 'editors') {
const isSectionEditor = await TeamMember.query(trx)
.leftJoin('teams', 'team_members.team_id', 'teams.id')
.findOne({
global: true,
role: 'globalSectionEditor',
userId,
})
if (isSectionEditor) return
}
if (team.role === 'globalSectionEditor') {
const isEditor = await TeamMember.query(trx)
.leftJoin('teams', 'team_members.team_id', 'teams.id')
.findOne({
global: true,
role: 'editors',
userId,
})
if (isEditor) return
}
const membershipsToDelete = await TeamMember.query(trx)
......
Markdown is supported
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