Commit 2a53a2e2 authored by Alf Eaton's avatar Alf Eaton
Browse files

Apply prettier to editoria-app

parent df3c2955
function isOwner (user, object) {
function isOwner(user, object) {
if (!user) return false
if (object && object.owners) {
const owner = object.owners.find((o) => {
const owner = object.owners.find(o => {
return o.id === user.id
})
if (owner) return true
......@@ -12,27 +11,27 @@ function isOwner (user, object) {
return false
}
function belongsToTeam (user, team) {
const teams = user.teams.filter((t) => {
function belongsToTeam(user, team) {
const teams = user.teams.filter(t => {
return t.teamType.name === team
})
return teams.length > 0
}
function isAuthor (user) {
function isAuthor(user) {
return belongsToTeam(user, 'Author')
}
function isCopyEditor (user) {
function isCopyEditor(user) {
return belongsToTeam(user, 'Copy Editor')
}
function isProductionEditor (user) {
function isProductionEditor(user) {
return belongsToTeam(user, 'Production Editor')
}
function hasRightsOnCollection (user, collectionId) {
const collectionInTeams = user.teams.find((team) => {
function hasRightsOnCollection(user, collectionId) {
const collectionInTeams = user.teams.find(team => {
const type = team.object.type
const id = team.object.id
return type === 'collection' && id === collectionId
......@@ -75,7 +74,8 @@ const editoria = (user, operation, object) => {
// only here to get the collection's production editor
// edit: also here for the user to be able to read the teams
// TODO eventually the user should only get his teams
if ((isCopyEditor(user) || isAuthor(user)) && operation === 'read') return true
if ((isCopyEditor(user) || isAuthor(user)) && operation === 'read')
return true
return false
}
......@@ -99,7 +99,12 @@ const editoria = (user, operation, object) => {
if (isProductionEditor(user)) return true
// TO DO -- what about create and delete?
if (operation === 'read' || operation === 'delete' || operation === 'create') return true
if (
operation === 'read' ||
operation === 'delete' ||
operation === 'create'
)
return true
// temporarily here -- change when you see what the update was
if (operation === 'update') return true
......
......@@ -8,5 +8,5 @@ module.exports = {
'pubsweet-client': universal.pubsweetClient,
'pubsweet-component-ink-backend': universal.inkBackend,
'pubsweet-server': universal.pubsweetServer,
validations: universal.validations
validations: universal.validations,
}
......@@ -8,5 +8,5 @@ module.exports = {
'pubsweet-client': universal.pubsweetClient,
'pubsweet-component-ink-backend': universal.inkBackend,
'pubsweet-server': universal.pubsweetServer,
validations: universal.validations
validations: universal.validations,
}
......@@ -10,22 +10,22 @@ const inkPassword = process.env.INK_PASSWORD
const teams = {
teamProduction: {
name: 'Production Editor',
permissions: 'all'
permissions: 'all',
},
teamCopyEditor: {
name: 'Copy Editor',
permissions: 'update'
permissions: 'update',
},
teamauthors: {
name: 'Author',
permissions: 'update'
}
permissions: 'update',
},
}
module.exports = {
authsome: {
mode: editoriaMode,
teams
teams,
},
bookBuilder: {
chapter: {
......@@ -43,25 +43,21 @@ module.exports = {
'Preface 7',
'Preface 8',
'Preface 9',
'Preface 10'
'Preface 10',
],
back: [
'Appendix A',
'Appendix B',
'Appendix C'
]
}
back: ['Appendix A', 'Appendix B', 'Appendix C'],
},
},
teamTypes: teams
teamTypes: teams,
},
dashboard: {
teamTypes: teams
teamTypes: teams,
},
inkBackend: {
inkEndpoint: inkEndpoint || 'http://ink-api.coko.foundation',
email: inkUsername,
password: inkPassword,
maxRetries: 60
maxRetries: 60,
},
pubsweet: {
components: [
......@@ -69,27 +65,29 @@ module.exports = {
'pubsweet-component-ink-frontend',
'pubsweet-component-login',
'pubsweet-component-signup',
'pubsweet-component-wax'
]
'pubsweet-component-wax',
],
},
pubsweetClient: {
navigation: 'app/components/Navigation/Navigation.jsx',
routes: 'app/routes.jsx',
theme: 'ThemeEditoria'
theme: 'ThemeEditoria',
},
pubsweetServer: {
API_ENDPOINT: '/api',
dbPath: process.env.PUBSWEET_DB || path.join(__dirname, '..', 'api', 'db'),
secret: process.env.PUBSWEET_SECRET
secret: process.env.PUBSWEET_SECRET,
},
validations: {
collection: {
productionEditor: Joi.object().allow(null)
productionEditor: Joi.object().allow(null),
},
fragment: {
alignment: Joi.object(),
author: Joi.string().allow(''),
book: Joi.string().guid().required(),
book: Joi.string()
.guid()
.required(),
comments: Joi.object(),
division: Joi.string(),
index: Joi.number(),
......@@ -101,7 +99,7 @@ module.exports = {
status: Joi.string(),
subCategory: Joi.string(),
title: Joi.string(),
trackChanges: Joi.boolean()
}
}
trackChanges: Joi.boolean(),
},
},
}
const book = {
id: '0',
title: 'Test Book'
title: 'Test Book',
}
const chapters = [
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -20,18 +20,18 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'component',
title: 'Preface',
trackChanges: false
trackChanges: false,
},
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -44,18 +44,18 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'component',
title: 'Introduction',
trackChanges: false
trackChanges: false,
},
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -68,18 +68,18 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'chapter',
title: 'Chapter One',
trackChanges: false
trackChanges: false,
},
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -92,18 +92,18 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'chapter',
title: 'Chapter Two',
trackChanges: false
trackChanges: false,
},
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -116,18 +116,18 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'component',
title: 'Preface',
trackChanges: false
trackChanges: false,
},
{
alignment: {
left: false,
right: false
right: false,
},
author: '',
book: book.id,
......@@ -140,31 +140,23 @@ const chapters = [
style: 0,
edit: 0,
review: 0,
clean: 0
clean: 0,
},
source: '',
status: 'unpublished',
subCategory: 'component',
title: 'Preface',
trackChanges: false
}
trackChanges: false,
},
]
const teams = []
const user = {
teams: [],
username: 'test-user'
username: 'test-user',
}
const users = [
user
]
const users = [user]
export {
book,
chapters,
teams,
user,
users
}
export { book, chapters, teams, user, users }
......@@ -3,5 +3,5 @@ global.PUBSWEET_COMPONENTS = []
global.mock = {
data: require('./dataMock'),
redux: require('./reduxMock')
redux: require('./reduxMock'),
}
......@@ -9,7 +9,7 @@ const actions = {
getTeams: sinon.stub().resolves(teams),
getUsers: sinon.stub().resolves(users),
ink: sinon.spy(),
updateFragment: sinon.spy()
updateFragment: sinon.spy(),
}
module.exports = { actions }
......@@ -5,7 +5,7 @@ var babelIncludes = [
new RegExp(path.join(__dirname, '../app')),
new RegExp(path.join(__dirname, '../node_modules/pubsweet-.*')),
new RegExp(path.join(__dirname, '../node_modules/editoria-.*')),
new RegExp(path.join(__dirname, '../node_modules/wax-editor-.*'))
new RegExp(path.join(__dirname, '../node_modules/wax-editor-.*')),
]
module.exports = babelIncludes
......@@ -12,24 +12,24 @@ const resolve = (type, entry) => {
const resolvePreset = entry => resolve('preset', entry)
const resolvePlugin = entry => resolve('plugin', entry)
const frontendComponents = config.pubsweet.components.filter(name => require(name).frontend)
const frontendComponents = config.pubsweet.components.filter(
name => require(name).frontend
)
module.exports = [
{
test: /\.js$|\.jsx$/,
loader: 'babel-loader',
query: {
presets: [
['es2015', { 'modules': 'commonjs' }],
'react',
'stage-2'
].map(resolvePreset),
presets: [['es2015', { modules: 'commonjs' }], 'react', 'stage-2'].map(
resolvePreset
),
plugins: [
'react-hot-loader/babel',
resolvePlugin('transform-decorators-legacy')
]
resolvePlugin('transform-decorators-legacy'),
],
},
include: babelIncludes
include: babelIncludes,
},
{ test: /\.png$/, loader: 'url-loader' },
{
......@@ -39,58 +39,65 @@ module.exports = [
loader: 'url-loader',
options: {
prefix: 'font',
limit: 1000
}
}
]
limit: 1000,
},
},
],
},
{ test: /\.html$/, loader: 'html-loader' },
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.css$|\.scss$/,
{
test: /\.css$|\.scss$/,
exclude: /\.local\.s?css$/, // Exclude local styles from global
loader: [
{
loader: 'style-loader'
loader: 'style-loader',
},
{
loader: 'css-loader'
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
includePaths: [path.join(__dirname, '..', 'node_modules')]
}
}
]
includePaths: [path.join(__dirname, '..', 'node_modules')],
},
},
],
},
{ test: /\.css$|\.scss$/,
{
test: /\.css$|\.scss$/,
include: /\.local\.s?css/, // Local styles
loader: [
{
loader: 'style-loader'
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1
}
importLoaders: 1,
},
},
{
loader: 'sass-loader',
options: {
includePaths: [path.join(__dirname, '..', 'node_modules')]
}
}
]
includePaths: [path.join(__dirname, '..', 'node_modules')],
},
},
],
},
{
test: /\.js$|\.jsx$/,
loader: 'string-replace-loader',
query: {
search: 'PUBSWEET_COMPONENTS',
replace: '[' + frontendComponents.map(component => `require('${component}')`).join(', ') + ']'
replace:
'[' +
frontendComponents
.map(component => `require('${component}')`)
.join(', ') +
']',
},
include: babelIncludes
}
include: babelIncludes,
},
]
......@@ -13,33 +13,31 @@ const environment = process.env.NODE_ENV
module.exports = {
context: path.join(__dirname, '..', 'app'),
module: {
rules: commonRules
rules: commonRules,
},
name: 'app',
node: {
__dirname: true,
dns: 'empty',
fs: 'empty',
net: 'empty'
net: 'empty',
},
output: {
path: path.join(__dirname, '..', '_build', 'assets'),
publicPath: '/assets/'
publicPath: '/assets/',
},
plugins: {
aggressiveMerging: new webpack.optimize.AggressiveMergingPlugin(),
compression: new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/
test: /\.js$|\.css$|\.html$/,
}),
copy: new CopyWebpackPlugin([
{ from: '../static' }
]),
copy: new CopyWebpackPlugin([{ from: '../static' }]),
occurrenceOrder: new webpack.optimize.OccurrenceOrderPlugin(),
provide: new webpack.ProvidePlugin({
CONFIG: path.resolve(__dirname, '..', 'config', `${environment}.js`)
})
CONFIG: path.resolve(__dirname, '..', 'config', `${environment}.js`),
}),
},
resolve: {
// alias: {
......@@ -49,10 +47,10 @@ module.exports = {
modules: [
path.resolve(__dirname, '..'),
path.resolve(__dirname, '..', 'node_modules'),
'node_modules'
'node_modules',
],
plugins: [new ThemePlugin(config.pubsweetClient.theme)],
symlinks: false
symlinks: false,
},
target: 'web'
target: 'web',
}
......@@ -9,16 +9,12 @@ module.exports = [
target: universal.target,
context: universal.context,
entry: {
app: [
'react-hot-loader/patch',
'webpack-hot-middleware/client',
'./app'
]
app: ['react-hot-loader/patch', 'webpack-hot-middleware/client', './app'],
},
output: {
path: universal.output.path,
filename: '[name].js',
publicPath: universal.output.publicPath
publicPath: universal.output.publicPath,
},
devtool: 'cheap-module-source-map',
module: universal.module,
......@@ -29,15 +25,15 @@ module.exports = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('dev'),
REDUXLOG_OFF: process.env.REDUXLOG_OFF
}
REDUXLOG_OFF: process.env.REDUXLOG_OFF,
},
}),
universal.plugins.provide,
universal.plugins.copy,
universal.plugins.aggressiveMerging,
universal.plugins.occurrenceOrder,
universal.plugins.compression
universal.plugins.compression,
],
node: universal.node
}
node: universal.node,
},
]
......@@ -12,14 +12,12 @@ module.exports = [
target: universal.target,
context: universal.context,
entry: {
app: [
'./app'
]
app: ['./app'],