Commit 0f5bf093 authored by Alexandros Georgantas's avatar Alexandros Georgantas

global teams functionality

parent e144864b
......@@ -81,10 +81,13 @@ class Navigation extends React.Component {
<NavItem>Books</NavItem>
</LinkContainer>
<Authorize operation="can view nav links" object="users">
<Authorize object="users" operation="can view nav links">
<LinkContainer to="/users">
<NavItem>Users</NavItem>
</LinkContainer>
<LinkContainer to="/globalTeams">
<NavItem>Global Teams</NavItem>
</LinkContainer>
</Authorize>
{BackToBooks}
......
......@@ -3,6 +3,7 @@ import { Redirect, Route, Switch } from 'react-router-dom'
// Users and Teams
import UsersManager from 'pubsweet-component-users-manager/UsersManagerContainer'
import GlobalTeamsManager from 'pubsweet-component-booksprints-globalteams/src/GlobalTeamsManager'
// import TeamsManager from 'pubsweet-component-teams-manager/TeamsManagerContainer'
// Authentication
......@@ -108,6 +109,7 @@ export default (
path="/books/:bookId/fragments/:fragmentId"
/>
<PrivateRoute component={UsersManager} path="/users" />
<PrivateRoute component={GlobalTeamsManager} path="/globalTeams" />
</Manage>
</Switch>
)
......
......@@ -55,7 +55,7 @@ class EditoriaMode {
team.object &&
team.object.id === object.id
} else {
membershipCondition = team => team.teamType === teamType
membershipCondition = team => team.teamType === teamType && team.global
}
const memberships = await Promise.all(
......@@ -79,9 +79,10 @@ class EditoriaMode {
collection = object
}
const membershipCondition = team => team.object.id === collection.id
const membershipCondition = team =>
!team.global && team.object.id === collection.id
const memberships = await Promise.all(
const memberships = await Promise.all(
this.user.teams.map(async teamId => {
const teamFound = await this.context.models.Team.find(teamId)
if (teamFound) {
......@@ -105,9 +106,10 @@ class EditoriaMode {
return this.isTeamMember('productionEditor', object)
}
isProductionEditor() {
async isGlobalProductionEditor() {
return this.isTeamMember('productionEditor')
}
async findCollectionByObject(object) {
let id
if (object.collection) {
......@@ -179,7 +181,7 @@ class EditoriaMode {
async canListTeams() {
this.user = await this.context.models.User.find(this.userId)
// if (await this.isProductionEditor()) {
// if (await this.isGlobalProductionEditor()) {
// return true
// }
......@@ -209,7 +211,7 @@ class EditoriaMode {
async canCreateTeam() {
this.user = await this.context.models.User.find(this.userId)
return this.isProductionEditor()
return this.isGlobalProductionEditor()
}
async canUpdateTeam() {
......@@ -227,7 +229,7 @@ class EditoriaMode {
async canCreateCollection() {
this.user = await this.context.models.User.find(this.userId)
return this.isProductionEditor()
return this.isGlobalProductionEditor()
}
async canInteractWithCollections() {
......
......@@ -36,6 +36,7 @@
"pubsweet-client": "^2.5.5",
"pubsweet-component-bookbuilder": "^1.1.2",
"pubsweet-component-editoria-dashboard": "^0.1.1",
"pubsweet-component-editoria-global-teams": "^0.1.1",
"pubsweet-component-epub": "^0.5.2",
"pubsweet-component-epub-frontend": "^0.1.3",
"pubsweet-component-ink-backend": "^0.1.1",
......@@ -154,11 +155,12 @@
]
},
"scripts": {
"setupdb": "pubsweet setupdb ./",
"setupdb": "pubsweet setupdb && npm run seed",
"start": "pubsweet start",
"server": "pubsweet start",
"resetdb": "pubsweet setupdb --clobber ./",
"resetdb": "pubsweet setupdb --clobber && npm run seed",
"start:services": "docker-compose up postgres",
"seed": "node ./scripts/seedGlobalTeams.js",
"test": "NODE_ENV=test jest",
"test:watch": "NODE_ENV=test jest --watch",
"test:cover": "NODE_ENV=test jest --coverage",
......
#!/usr/bin/env node
const logger = require('@pubsweet/logger')
const { Team } = require('pubsweet-server/src/models')
const makeTeam = async type => {
const names = {
productionEditor: 'Production Editor',
}
logger.info(`Create ${names[type]} team`)
const team = new Team({
global: true,
members: [],
name: names[type],
teamType: type,
})
await team.save()
logger.info(`${names[type]} team successfully created`)
}
const seed = async () => {
logger.info('### RUNNING GLOBAL TEAMS SEED SCRIPTS ###')
logger.info('=> Checking if global teams exist...')
try {
const teams = await Team.findByField({ global: true })
const editorsTeam = teams.find(t => t.teamType === 'productionEditor')
const scienceOfficersTeam = teams.find(t => t.teamType === 'author')
if (editorsTeam && scienceOfficersTeam) {
logger.info('All global teams found, exiting...')
} else {
if (!editorsTeam) {
logger.warn('No Production Editor team found')
await makeTeam('productionEditor')
} else {
logger.info('Production Editor team already exists')
}
if (!scienceOfficersTeam) {
logger.warn('No Author team found')
await makeTeam('author')
} else {
logger.info('Author team already exists')
}
}
} catch (err) {
logger.warn('No global teams found')
await makeTeam('productionEditor')
await makeTeam('author')
}
logger.info('Team seed successfully finished')
}
seed()
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