Commit 94192a69 authored by Jure's avatar Jure

feat: update and minimize starter

parent aa768ddf
Pipeline #10704 failed with stages
in 2 minutes and 12 seconds
......@@ -2,19 +2,13 @@ import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import Authorize from 'pubsweet-client/src/helpers/Authorize'
import actions from 'pubsweet-client/src/actions'
import { Action, AppBar } from '@pubsweet/ui'
const Navigation = ({ logoutUser, currentUser }) => (
<AppBar
brand={<img alt="pubsweet" src="/assets/pubsweet.jpg" />}
navLinkComponents={[
<Action to="/manage/posts">Posts</Action>,
<Authorize object={{ path: '/users' }} operation="GET">
<Action to="/manage/users">Users</Action>
</Authorize>,
]}
navLinkComponents={[<Action to="/helloworld">Hello World</Action>]}
onLogoutClick={logoutUser}
user={currentUser}
/>
......
import React from 'react'
import { Route, Switch } from 'react-router-dom'
// Manage
import PostsManager from 'pubsweet-component-posts-manager/PostsManagerContainer'
import UsersManager from 'pubsweet-component-users-manager/src/UsersManagerContainer'
import TeamsManager from 'pubsweet-component-teams-manager/src/TeamsManagerContainer'
// Public
import Blog from 'pubsweet-component-blog/BlogContainer'
import HTML from 'pubsweet-component-html/HTMLContainer'
// Authentication
import Login from 'pubsweet-component-login/LoginContainer'
import Signup from 'pubsweet-component-signup/SignupContainer'
......@@ -18,29 +9,19 @@ import AuthenticatedComponent from 'pubsweet-client/src/components/Authenticated
import App from './components/App'
// eslint-disable-next-line
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={props => (
<AuthenticatedComponent>
<Component {...props} />
</AuthenticatedComponent>
)}
/>
const HelloWorld = () => (
<AuthenticatedComponent>
<div>Hello World!</div>
</AuthenticatedComponent>
)
export default (
<App>
<Switch>
<PrivateRoute component={UsersManager} path="/manage/users" />
<PrivateRoute component={PostsManager} path="/manage/posts" />
<PrivateRoute component={TeamsManager} path="/manage/teams" />
<Route component={Blog} exact path="/" />
<Route component={HelloWorld} path="/dashboard" />
<Route component={Login} path="/login" />
<Route component={Signup} path="/signup" />
<Route component={PasswordReset} path="/password-reset" />
<Route component={HTML} path="/:id" />
</Switch>
</App>
)
......@@ -164,14 +164,14 @@ class AuthsomeMode {
module.exports = {
before: async (userId, operation, object, context) => {
const user = await context.models.User.find(userId)
const user = userId && (await context.models.User.find(userId))
return user && user.admin
},
GET: (userId, operation, object, context) => {
// const mode = new AuthsomeMode(userId, operation, object, context)
// GET /api/collections
if (object && object.path === '/collections') {
if (object && object.path === '/api/collections') {
return true
}
// GET /api/collection
......@@ -180,7 +180,7 @@ module.exports = {
}
// GET /api/collections/:collectionId/fragments
if (object && object.path === '/fragments') {
if (object && object.path === '/api/fragments') {
return true
}
// GET /api/collections/:collectionId/fragments/:fragmentId
......@@ -189,12 +189,12 @@ module.exports = {
}
// GET /api/users
if (object && object.path === '/users') {
if (object && object.path === '/api/users') {
return true
}
// // GET /api/teams
if (object && object.path === '/teams') {
if (object && object.path === '/api/teams') {
return true
}
......@@ -213,19 +213,25 @@ module.exports = {
POST: (userId, operation, object, context) => {
const mode = new AuthsomeMode(userId, operation, object, context)
// POST /api/collections
if (object && object.path === '/collections') {
if (object && object.path === '/api/collections') {
return mode.canCreateCollection()
}
// POST /api/users
if (object && object.path === '/users') {
if (object && object.path === '/api/users') {
return true
}
// POST /api/users/authenticate
if (object && object.token) {
return true
}
// POST /api/fragments
if (object && object.path === '/collections/:collectionId/fragments') {
if (object && object.path === '/api/collections/:collectionId/fragments') {
return true
}
// POST /api/teams
if (object && object.path === '/teams') {
if (object && object.path === '/api/teams') {
return true
}
......
[
"pubsweet-component-blog",
"pubsweet-component-login",
"pubsweet-component-manage",
"pubsweet-component-pepper-theme",
"pubsweet-component-posts-manager",
"pubsweet-component-password-reset-backend",
"pubsweet-component-signup"
"pubsweet-component-signup",
"@pubsweet/model-user",
"@pubsweet/model-team",
"@pubsweet/model-blog",
"@pubsweet/model-blogpost"
]
......@@ -15,8 +15,7 @@ module.exports = {
'pubsweet-client': {
API_ENDPOINT: '/api',
theme: 'PepperTheme',
'login-redirect': '/manage/posts',
'redux-log': false,
'login-redirect': '/dashboard',
},
authsome: {
// this should be either an npm package or an absolute path, not a relative path
......@@ -38,11 +37,8 @@ module.exports = {
sender: 'noreply@pubsweet.org',
},
mailer: {
path: path.join(__dirname, 'mailer'),
from: 'nobody@example.com',
transport: {
sendmail: true,
},
},
validations: path.join(__dirname, 'validations'),
publicKeys: ['pubsweet-client', 'authsome', 'pubsweet', 'validations'],
}
module.exports = {
transport: {
sendmail: true,
},
}
module.exports = {
transport: {
sendmail: false,
port: 1025,
auth: {
user: 'user',
pass: 'pass',
},
},
}
const logger = require('winston')
const path = require('path')
module.exports = {
'pubsweet-server': {
......@@ -9,14 +10,7 @@ module.exports = {
secret: 'test',
},
mailer: {
transport: {
sendmail: false,
port: 1025,
auth: {
user: 'user',
pass: 'pass',
},
},
path: path.join(__dirname, 'mailer_test.js'),
},
'password-reset': {
url: 'http://localhost:4000/password-reset',
......
......@@ -10,30 +10,23 @@
],
"main": "app.js",
"dependencies": {
"@pubsweet/coko-theme": "^4.1.0",
"@pubsweet/coko-theme": "^5.0.3",
"@pubsweet/db-manager": "^2.0.5",
"@pubsweet/default-theme": "3.0.0",
"@pubsweet/default-theme": "4.0.3",
"@pubsweet/logger": "^0.2.6",
"@pubsweet/ui": "^8.7.0",
"@pubsweet/model-blog": "^0.0.2",
"@pubsweet/model-blogpost": "^0.0.2",
"@pubsweet/model-team": "^1.0.1",
"@pubsweet/model-user": "^2.0.0",
"@pubsweet/ui": "^9.0.3",
"authsome": "^0.1.0",
"pubsweet": "^3.0.5",
"pubsweet-client": "^6.0.0",
"pubsweet-component-blog": "^1.0.5",
"pubsweet-component-form-group": "1.1.25",
"pubsweet-component-html": "^0.2.5",
"pubsweet-component-login": "1.1.17",
"pubsweet-component-manage": "^1.0.0",
"pubsweet-component-medium-draft": "^0.2.3",
"pubsweet-component-navigation": "^1.0.1",
"pubsweet-component-password-reset-backend": "^1.0.5",
"pubsweet-component-password-reset-frontend": "^2.0.15",
"pubsweet-component-pepper-theme": "^0.0.5",
"pubsweet-component-posts-manager": "1.0.40",
"pubsweet": "^3.0.13",
"pubsweet-client": "^8.0.0",
"pubsweet-component-login": "^1.2.3",
"pubsweet-component-password-reset-backend": "^2.0.0",
"pubsweet-component-password-reset-frontend": "^3.0.3",
"pubsweet-component-signup": "^1.0.31",
"pubsweet-component-teams-manager": "^1.1.24",
"pubsweet-component-users-manager": "^2.0.1",
"pubsweet-server": "^10.0.0",
"pubsweet-theme-plugin": "^0.0.3",
"pubsweet-server": "^11.0.0",
"react-router-redux": "next"
},
"devDependencies": {
......@@ -81,7 +74,7 @@
"smtp-server": "^3.3.0",
"string-replace-loader": "^1.2.0",
"style-loader": "^0.21.0",
"testcafe": "^0.22.0",
"testcafe": "^0.23.3",
"testcafe-react-selectors": "^3.0.0",
"url-loader": "^0.6.2",
"webpack": "^3.11.0",
......
......@@ -3,87 +3,17 @@ import config from 'config'
import { startServer, setup } from './helpers/setup'
import mailHelper from './helpers/mail'
import {
login,
managePosts,
manageTeams,
manageUsers,
passwordReset,
} from './pageObjects'
import { login, passwordReset, helloWorld } from './pageObjects'
let admin
let collection
fixture('Admin user')
.before(startServer)
.beforeEach(async () => {
const result = await setup()
admin = result.userData
collection = result.collectionData
})
test('Manage posts journey', async t => {
await login
.doLogin(admin.username, admin.password)
.expect(managePosts.title.innerText)
.eql(collection.title)
// create a post
const postTitle = faker.lorem.words()
await t
.typeText(managePosts.newPostInput, postTitle)
.click(managePosts.newPostButton)
.expect(managePosts.postTitle(0).innerText)
.match(new RegExp(`^${postTitle}`))
// publish it
await t
.click(managePosts.postPublish(0))
.expect(managePosts.postPublish(0).exists)
.notOk()
.expect(managePosts.postUnpublish(0).exists)
.ok()
// delete it
await t
.click(managePosts.postDelete(0))
.expect(managePosts.post(0).exists)
.notOk()
})
test('Manage teams journey', async t => {
await login
.doLogin(admin.username, admin.password)
.navigateTo(manageTeams.url)
// create a team
const teamName = faker.lorem.words()
await t
.typeText(manageTeams.teamName, teamName)
.click(manageTeams.teamType)
.click(manageTeams.option)
.click(manageTeams.collection)
.click(manageTeams.option)
.click(manageTeams.create)
.expect(manageTeams.teamTitle(0).innerText)
.eql(teamName)
// delete it
await t
.click(manageTeams.teamDelete(0))
.expect(manageTeams.team(0).exists)
.notOk()
})
test('Manage users journey', async t => {
await login
.doLogin(admin.username, admin.password)
.navigateTo(manageUsers.url)
// check user is shown
await t.expect(manageUsers.userTitle(0).innerText).eql(admin.username)
})
test('Password reset journey', async t => {
// start mail server
mailHelper.start()
......@@ -98,7 +28,7 @@ test('Password reset journey', async t => {
// extract reset URL from email content
const mail = await mailHelper.nextEmail()
console.log(mail)
const matchResult = mail
.replace(/=3D/g, '=')
.replace(/=\r?\n/g, '')
......@@ -115,6 +45,6 @@ test('Password reset journey', async t => {
// login
await login
.doLogin(admin.username, newPass)
.expect(managePosts.title.innerText)
.eql(collection.title)
.expect(helloWorld.text.innerText)
.eql('Hello World!')
})
import faker from 'faker'
import { login, signup, managePosts } from './pageObjects'
import { login, signup } from './pageObjects'
import { startServer, setup } from './helpers/setup'
fixture('Guest user')
......@@ -35,5 +35,5 @@ test('Signup journey', async t => {
await login
.doLogin(user.username, user.password)
.expect(t.eval(() => window.location.href))
.eql(managePosts.url)
.eql('http://localhost:4000/dashboard')
})
import { SMTPServer } from 'smtp-server'
import config from 'config'
import { SMTPServer } from 'smtp-server'
const { transport } = require(config.get('mailer.path'))
const promiseQueue = []
const resolveQueue = []
......@@ -21,7 +23,7 @@ function start() {
},
})
server.listen(config.get('mailer.transport.port'))
server.listen(transport.port)
}
// get the next email (wait if necessary)
......
import config from 'config'
import { ReactSelector } from 'testcafe-react-selectors'
const helloWorld = {
url: `${config.get('pubsweet-server.baseUrl')}/dashboard`,
text: ReactSelector('HelloWorld').nth(0),
}
export default helloWorld
export { default as login } from './login'
export { default as signup } from './signup'
export { default as passwordReset } from './passwordReset'
export { default as managePosts } from './manage/posts'
export { default as manageTeams } from './manage/teams'
export { default as manageUsers } from './manage/users'
export { default as helloWorld } from './helloWorld'
import config from 'config'
import { ReactSelector } from 'testcafe-react-selectors'
const managePosts = {
url: `${config.get('pubsweet-server.baseUrl')}/manage/posts`,
title: ReactSelector('PostsManager').find('h2'),
post: n => ReactSelector('Post').nth(n),
postTitle: n => managePosts.post(n).findReact('EditableValue'),
postEdit: n =>
managePosts
.post(n)
.find('button')
.withText(/^Edit/i),
postPublish: n =>
managePosts
.post(n)
.find('button')
.withText(/^Publish/i),
postUnpublish: n =>
managePosts
.post(n)
.find('button')
.withText(/^Unpublish/i),
postDelete: n =>
managePosts
.post(n)
.find('button')
.withText(/^Delete/i),
newPostInput: ReactSelector('PostCreator TextField'),
newPostButton: ReactSelector('PostCreator styled.button'),
}
export default managePosts
import config from 'config'
import { ReactSelector } from 'testcafe-react-selectors'
const manageTeams = {
url: `${config.get('pubsweet-server.baseUrl')}/manage/teams`,
title: ReactSelector('TeamManager').find('h2'),
team: n => ReactSelector('Team').nth(n),
teamTitle: n =>
manageTeams
.team(n)
.find('td')
.nth(1),
teamDelete: n =>
manageTeams
.team(n)
.find('button')
.withText(/^Delete/i),
teamName: ReactSelector('TeamCreator TextField'),
teamType: ReactSelector('TeamCreator Menu').nth(0),
collection: ReactSelector('TeamCreator Menu').nth(1),
option: ReactSelector('TeamCreator Menu DefaultMenuOption'),
create: ReactSelector('TeamCreator')
.find('button')
.withText(/^Create/i),
}
export default manageTeams
import config from 'config'
import { ReactSelector } from 'testcafe-react-selectors'
const manageUsers = {
url: `${config.get('pubsweet-server.baseUrl')}/manage/users`,
title: ReactSelector('UserManager').find('h2'),
user: n => ReactSelector('User').nth(n),
userTitle: n =>
manageUsers
.user(n)
.find('td')
.nth(1),
}
export default manageUsers
const path = require('path')
const ThemePlugin = require('pubsweet-theme-plugin')
const fs = require('fs-extra')
const config = require('config')
const { pick } = require('lodash')
......@@ -43,7 +42,6 @@ module.exports = [
joi: 'joi-browser',
config: clientConfigPath,
},
plugins: [new ThemePlugin(config['pubsweet-client'].theme)],
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
......
const path = require('path')
const ThemePlugin = require('pubsweet-theme-plugin')
const fs = require('fs-extra')
const config = require('config')
const { pick } = require('lodash')
......@@ -42,7 +41,6 @@ module.exports = [
joi: 'joi-browser',
config: clientConfigPath,
},
plugins: [new ThemePlugin(config['pubsweet-client'].theme)],
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
......
This diff is collapsed.
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