...
 
Commits (2)
......@@ -23,9 +23,9 @@ const StyledTextField = styled(UiTextField)`
}
`
const Error = styled.div.attrs({
const Error = styled.div.attrs(props => ({
role: 'alert',
})`
}))`
align-self: flex-end;
animation: ${fadeIn} 0.2s;
color: ${th('colorError')};
......
......@@ -41,10 +41,10 @@ const small = css`
width: 500px;
`
const StyledModal = styled(ReactModalAdapter).attrs({
const StyledModal = styled(ReactModalAdapter).attrs(props => ({
modalClassName: 'Modal',
overlayClassName: 'Overlay',
})`
}))`
.Overlay {
background-color: rgba(240, 240, 240, 0.85);
bottom: 0;
......
......@@ -46,7 +46,7 @@ const seed = async () => {
logger.warn('No Science Officers team found')
await makeTeam('scienceOfficers')
} else {
logger.info('Scince Officers team already exists')
logger.info('Science Officers team already exists')
}
}
} catch (err) {
......
const clone = require('lodash/clone')
const { Team } = require('@pubsweet/models')
const { Team, TeamMember } = require('@pubsweet/models')
const Manuscript = require('../../manuscript/src/manuscript')
const ExternalTeam = require('../../models/externalTeam/externalTeam')
......@@ -35,82 +35,70 @@ const createManuscript = async (_, variables, ctx) => {
const teams = [
// Author team with current user as member
{
members: [userId],
// members: [userId],
name: `author-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'author',
},
// Editor team
{
members: [],
// members: [],
name: `editor-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'editor',
},
// Science officer team
{
members: [],
// members: [],
name: `science-officer-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'scienceOfficer',
},
// Reviewer team
{
members: [],
// members: [],
name: `reviewers-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'reviewers',
},
// Invited reviewers team
{
members: [],
// members: [],
name: `reviewers-invited-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'reviewersInvited',
},
// Reviewers that accepted
{
members: [],
// members: [],
name: `reviewers-accepted-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'reviewersAccepted',
},
// Reviewers that rejected
{
members: [],
// members: [],
name: `reviewers-rejected-${manuscript.id}`,
object: {
objectId: manuscript.id,
objectType: 'article',
},
objectId: manuscript.id,
objectType: 'article',
role: 'reviewersRejected',
},
]
const createdTeamIds = {}
/*
We unfortunately need to execute these serially, otherwise `user.teams`
gets corrupted. Replace with `Promise.all` once you stop using `user.teams`.
......@@ -118,9 +106,18 @@ const createManuscript = async (_, variables, ctx) => {
/* eslint-disable-next-line no-restricted-syntax */
for (const teamData of teams) {
/* eslint-disable-next-line no-await-in-loop */
await new Team(teamData).save()
await new Team(teamData).save().then(t => {
createdTeamIds[t.name] = t.id
})
}
// Do I need an aliasId?
await TeamMember.query().insert({
// aliasId:,
teamId: createdTeamIds[`author-${manuscript.id}`],
userId,
})
const externalTeams = [
// Reviewers that are not users that have been added to the reviewer list
{
......
......@@ -21,7 +21,8 @@ const cleanScienceOfficerStatus = {
pending: false,
}
const isMember = (team, userId) => team && team.members.includes(userId)
const isMember = (team, userId) =>
team && team.members.some(tm => tm.userId === userId)
const isUserInGlobalTeams = (globalTeams, user) =>
user.admin || globalTeams.some(team => isMember(team, user.id))
......@@ -186,7 +187,7 @@ const resolvers = {
const articles = await Manuscript.query().orderBy('updated', 'desc')
const currentUser = await User.find(currentUserId)
const reviews = await Review.all()
const teams = await Team.all()
const teams = await Team.query().eager('[members.[user, alias]]')
const globalTeams = teams.filter(t => t.global)
const isGlobal = isUserInGlobalTeams(globalTeams, currentUser)
......@@ -201,7 +202,7 @@ const resolvers = {
const articleCopy = clone(article)
const articleTeams = teams.filter(
t => t.object && t.object.objectId === article.id,
t => t.objectId && t.objectId === article.id,
)
/* Create reviewer status */
......
......@@ -10,5 +10,5 @@ create table external_team (
members jsonb not null, -- make array of foreign keys
-- own
team_type text not null
role text not null
);
......@@ -115,7 +115,7 @@ const resolvers = {
reviewer: async (manuscript, args, ctx) => {
const { model: Manuscript } = require('../../manuscript/src') // eslint-disable-line global-require
const teams = await Team.all()
const teams = await Team.query().eager('[members.[user, alias]]')
const userReviews = await Review.findByField('reviewerId', ctx.user)
const articles = await Manuscript.query()
......@@ -123,7 +123,7 @@ const resolvers = {
articles.forEach(article => {
const articleTeams = teams.filter(
a => a.object && a.object.objectId === article.id,
a => a.objectId && a.objectId === article.id,
)
// Is user a reviewer of article
......