Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(auth): Various build improvements and minor refactoring #2959

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
591792e
build(devel): Add a proxy hosting testbed
rpatterson May 26, 2021
a54a425
build(devel): Improve browsing API source code
rpatterson Jun 16, 2021
fb65481
build(devel): Wrong checkout default branch name
rpatterson Jun 16, 2021
27c65ca
docs(redux): Order folder structure per frameworks
rpatterson Jun 23, 2021
5f5e782
refactor(user): Factor user session state to selectors
rpatterson Jun 17, 2021
ee9cf27
refactor(actions): Easier action lookup by id
rpatterson Jun 21, 2021
faec2ae
fix(auth): UI logged-in detection for other auths
rpatterson Jun 21, 2021
e1fb3cb
Merge branch 'master' into fix-auth-unified-login
sneridagh Jun 26, 2021
31b026a
Merge branch 'master' into fix-auth-unified-login
sneridagh Jul 7, 2021
b92c67b
Fix prettier issues
sneridagh Jul 7, 2021
ca0b83f
build(semver): React props changes break custom
rpatterson Jul 14, 2021
4ec73ba
build(devel): Isolate Trafik proxy make testbed
rpatterson Jul 14, 2021
54d6883
Merge branch 'master' into fix-auth-unified-login
tisto Jul 17, 2021
e48de09
Merge branch 'master' into fix-auth-unified-login
sneridagh Sep 13, 2021
3b38635
Merge branch 'master' into fix-auth-unified-login
sneridagh Sep 21, 2021
ae88d91
Merge branch 'master' into fix-auth-unified-login
sneridagh Sep 21, 2021
04eee9c
Fix toolbar flash in initial state
sneridagh Sep 21, 2021
ef0b138
Fix @types missing
sneridagh Sep 21, 2021
1dcd0e4
Action should be a thunk...
sneridagh Sep 21, 2021
ffbaa4a
build(make): Reduce noise for doc/help target
rpatterson Dec 9, 2021
f9aed95
test(api): Restore test runner, ref'ed in Makefile
rpatterson Dec 9, 2021
412dfd6
build(make): Reduce build times, incremental
rpatterson Dec 9, 2021
e9946b0
Merge remote-tracking branch 'origin/master' into fix-flashy-toolbar-…
rpatterson Dec 10, 2021
aa42be0
docs(make): Consistent terminology hyphenation
rpatterson Dec 10, 2021
fd8ef01
build(proxy): Improve proxy testbed usage
rpatterson Dec 10, 2021
59a2bc6
Merge branch 'master' into build-rpatterson-improve-local-devel
sneridagh Dec 11, 2021
21f701c
Merge branch 'master' into build-rpatterson-improve-local-devel
sneridagh Dec 11, 2021
815fe06
Merge remote-tracking branch 'origin/master' into build-rpatterson-im…
rpatterson Dec 13, 2021
b6fffce
build(checkout): Cleanup merged branch reference
rpatterson Dec 13, 2021
520bc28
build(version): Fix version constraint conflicts
rpatterson Dec 13, 2021
9df9d4c
build(version): Improve version conflict resolution
rpatterson Dec 13, 2021
bf76714
Merge remote-tracking branch 'origin/master' into build-rpatterson-im…
rpatterson Dec 16, 2021
0594c16
build(deps): Constrain, pin, upgrade API versions
rpatterson Dec 16, 2021
3574ef6
build(clean): Fix clean checkout build issues
rpatterson Dec 20, 2021
60731b2
Merge branch 'master' into build-rpatterson-improve-local-devel
rpatterson Dec 21, 2021
067a780
Merge branch 'build-rpatterson-improve-local-devel' into build-versio…
rpatterson Dec 21, 2021
9d9b59a
build(make): Fix line continuation error
rpatterson Dec 21, 2021
26f3280
Merge remote-tracking branch 'origin/master' into build-rpatterson-im…
rpatterson Dec 26, 2021
c2c3044
Merge branch 'build-rpatterson-improve-local-devel' into build-versio…
rpatterson Dec 26, 2021
53cda26
Merge branch 'build-versions-constraints-pins' into fix-flashy-toolba…
rpatterson Dec 26, 2021
11029f7
build(devel): Improve browsing test and tools code
rpatterson Dec 26, 2021
a01f76b
build(data): Add clean data convenience target
rpatterson Dec 26, 2021
109bc55
test(auth): Fix test name typo mismatch
rpatterson Dec 28, 2021
65fd903
feat(auth): Unified log in/out both API/classic
rpatterson Dec 26, 2021
f145c3d
build(checkouts): Avoid merge issues, move to PR
rpatterson Dec 28, 2021
99046d6
Merge branch 'master' into fix-flashy-toolbar-in-2661
rpatterson Feb 16, 2022
8d887af
docs(history): Cleanup no longer relevant changes
rpatterson Feb 25, 2022
49efac5
build(checkouts): Easier development Plone sources
rpatterson Jan 5, 2022
a5ccfd7
docs(feedback): Clarifications from PR feedback
rpatterson Feb 25, 2022
ff43ee3
Merge remote-tracking branch 'origin/master' into fix-flashy-toolbar-…
rpatterson Feb 25, 2022
efdc687
docs(history): Missing changelog entry CI failure
rpatterson Feb 25, 2022
ffc731e
Make docstring verbose, yet accurate, while providing an example and …
stevepiercy Mar 2, 2022
495ab01
Merge remote-tracking branch 'origin/master' into fix-flashy-toolbar-…
rpatterson Mar 4, 2022
1a19b49
Merge branch 'master' into fix-flashy-toolbar-in-2661
avoinea Mar 11, 2022
aa938e3
Merge remote-tracking branch 'origin/master' into fix-flashy-toolbar-…
rpatterson Apr 13, 2022
5086f56
test(clean): Restore clean work tree testing
rpatterson Apr 13, 2022
813ba72
build(make): Unnecessary directory change
rpatterson Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

### Bugfix

- Fix redirect bug with URLs containing querystrings @robgietema
### Internal

- Various build improvements and minor refactoring captured during the effort to unify
Volto, Plone classic, and ZMI authentication. @rpatterson

### Internal

Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ MAKEFLAGS+=--no-builtin-rules
INSTANCE_PORT=8080
DOCKER_IMAGE=plone/plone-backend:5.2.6
KGS=plone.restapi==8.21.0 plone.volto==4.0.0a3 plone.rest==2.0.0a2 plone.app.iterate==4.0.2 plone.app.vocabularies==4.3.0
# The defaults from the UI configuration
# export RAZZLE_DEV_PROXY_API_PATH=http://localhost:$(INSTANCE_PORT)/Plone
# export RAZZLE_API_PATH=http://localhost:3000
# Uncomment the following to run against the proxy hosting testbed:
# export RAZZLE_DEV_PROXY_API_PATH=
# export RAZZLE_API_PATH=http://localhost:49080/api/Plone
# Then run everything:
# $ make run-proxy-all
# Finally, visit the parts of the stack in a browser:
# - ZMI: http://localhost:49080/api/manage_main
# - Plone Classic: http://localhost:49080/api/Plone
# - Volto: http://localhost:49080/

# Sphinx variables
# You can set these variables from the command line.
Expand Down Expand Up @@ -159,9 +171,9 @@ netlify:
docs-test: docs-clean docs-linkcheck docs-spellcheck ## Clean docs build, then run linkcheck, spellcheck

.PHONY: start
# Run both the back-end and the front end
# Run both the back-end and the front-end
start:
$(MAKE) -j 2 start-backend start-frontend
$(MAKE) -e -j 2 start-backend start-frontend

.PHONY: start-frontend
start-frontend:
Expand All @@ -179,6 +191,14 @@ start-backend-docker:
start-backend-docker-guillotina:
docker-compose -f g-api/docker-compose.yml up -d

.PHONY: run-proxy
run-proxy:
docker-compose up traefik
.PHONY: run-proxy-all
# Run the back-end, front-end, and proxy testbed with all output combined
run-proxy-all:
$(MAKE) -e -j 3 start-backend start-frontend run-proxy

.PHONY: start-test
start-test: ## Start Test
@echo "$(GREEN)==> Start Test$(RESET)"
Expand Down Expand Up @@ -231,8 +251,13 @@ test-acceptance-guillotina:
.PHONY: clean
clean:
$(MAKE) clean-tmp-worktrees
$(MAKE) -C "./api/" clean
$(MAKE) -C "./api/" "$(@)"
rm -rf node_modules
.PHONY: clean-data
clean-data: ## Remove all variable user data
# E.g., to run the proxy test bed against a fresh Plone + Volto site:
# $ make clean-data run-proxy-all
$(MAKE) -C "./api/" "$(@)"
.PHONY: clean-tmp-worktrees
clean-tmp-worktrees: ## Cleanup temporary worktrees managed by this `./Makefile`
git worktree list --porcelain | tail -n +5 |
Expand Down
13 changes: 11 additions & 2 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ test-acceptance-server-old: build
ZSERVER_PORT=55001 CONFIGURE_PACKAGES=plone.app.contenttypes,plone.restapi,plone.volto,plone.volto.cors APPLY_PROFILES=plone.app.contenttypes:plone-content,plone.restapi:default,plone.volto:default-homepage ./bin/robot-server plone.app.robotframework.testing.PLONE_ROBOT_TESTING

.PHONY: clean
clean:
clean: ## Remove all build artifacts
rm -rf bin eggs develop-eggs include lib parts .installed.cfg .mr.developer.cfg

.PHONY: clean-data
clean-data: ## Remove all variable user data
mkdir -pv "./var/backups/"
for data_path in ./var/*storage ./var/instance ./parts/instance
do
test '!' -e "$${data_path}" || (
mv --backup=numbered -f -v "$${data_path}" "./var/backups/"
)
done
touch -c "./buildout.cfg"

.PHONY: start
start: build ## Start Plone Backend
Expand Down
8 changes: 2 additions & 6 deletions api/buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[buildout]
index = https://pypi.org/simple/
extends =
https://raw.githubusercontent.com/plone/buildout.coredev/5.2.6/sources.cfg
http://dist.plone.org/release/5.2.6/versions.cfg
version-constraints.cfg
versions.cfg
Expand All @@ -14,11 +15,6 @@ auto-checkout =
always-checkout = force
show-picked-versions = true

[sources]
plone.volto = git https://github.com/plone/plone.volto.git branch=main
plone.rest = git git@github.com:plone/plone.rest.git branch=master
plone.restapi = git git://github.com/plone/plone.restapi.git pushurl=git@github.com:plone/plone.restapi.git branch=master

[instance]
recipe = plone.recipe.zope2instance
user = admin:admin
Expand Down Expand Up @@ -83,4 +79,4 @@ site-replace = True
# source code involved in the application in a way that's more readable and avoids
# duplicates from older versions of eggs.
recipe = collective.recipe.omelette
eggs = ${instance:eggs}
eggs = ${test:eggs}
3 changes: 0 additions & 3 deletions api/versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,3 @@ sortedcontainers = 2.4.0

# Added by buildout at 2022-02-14 13:57:43.277710
plone.volto = 4.0.0a3

# Added by buildout at 2022-02-14 13:57:43.277710
plone.volto = 4.0.0a3
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ services:
- SITE=Plone
- 'ADDONS=plone.restapi==8.21.0 plone.volto==4.0.0a3 plone.rest==2.0.0a2 plone.app.iterate==4.0.2 plone.app.vocabularies==4.3.0'
- 'PROFILES=plone.volto:default-homepage'
labels:
traefik.enable: "true"
traefik.http.routers.plone.entrypoints: "web"
traefik.http.routers.plone.rule: "PathPrefix(`/api`)"
# https://doc.traefik.io/traefik/middlewares/stripprefix/#configuration-examples
traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes: "/api"
traefik.http.middlewares.rewrite-api-vhost.replacepathregex.regex: "^(.*)$$"
traefik.http.middlewares.rewrite-api-vhost.replacepathregex.replacement: "/VirtualHostBase/http/localhost:49080/VirtualHostRoot/_vh_api$$1"
traefik.http.routers.plone.middlewares: "strip-api-prefix@docker,rewrite-api-vhost@docker"
traefik.http.services.plone.loadbalancer.server.port: "8080"

frontend:
image: 'plone/plone-frontend:latest'
Expand All @@ -25,3 +35,41 @@ services:
RAZZLE_DEV_PROXY_API_PATH: http://backend:8080/Plone
depends_on:
- backend
labels:
traefik.enable: "true"
traefik.http.routers.frontend.entrypoints: "web"
traefik.http.routers.frontend.rule: "PathPrefix(`/ui`)"
# https://doc.traefik.io/traefik/middlewares/stripprefix/#configuration-examples
traefik.http.middlewares.strip-ui-prefix.stripprefix.prefixes: "/ui"
traefik.http.routers.frontend.middlewares: "strip-ui-prefix@docker"
traefik.http.services.frontend.loadbalancer.server.port: "3000"

traefik:
image: "traefik"
# Disabled so that the proxy can also be used to test deployment scenarios against
# a back-end and/or front-end running on the local host.
# depends_on:
# - plone
# - frontend
command:
- "--log.level=INFO"
# - "--log.level=DEBUG"
# https://doc.traefik.io/traefik/observability/access-logs/#configuration
- "--accesslog=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:49080"
- "--providers.file.directory=/etc/traefik.d/"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik.d/:/etc/traefik.d/"
ports:
- "49080:49080"

networks:
default:
ipam:
driver: "default"
config:
# Use the same random subnet each time
- subnet: "192.168.80.0/24"
23 changes: 15 additions & 8 deletions docs/source/recipes/folder-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ Volto is based on React, Redux, and React-Router. All of the
code is located in the `src` folder. The following convention for locating
resources is used.

## Components

`components` contains all the React components, also known as views. This includes views
for the management interface and the theme.

## Actions

`actions` contains all the redux actions for fetching all backend data like
content, users and external resources that are pulled into our app in general.

## Components
## Reducers

`components` contains all the views. This includes views for the management
interface and the theme.
`reducers` contains all the Redux reducers that manage the life-cycle for Redux actions
and make the according changes to state.

## Config
## Selectors

In this folder all configuration is stored. All configuration can be overridden
in your theme package.
`selectors` contains all the [Redux
selectors](https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow#selectors)
that interpret state into the form used by UI components.

## Constants

Expand All @@ -35,9 +41,10 @@ The constants contain all constants including the action types.

`helpers` contains helper methods like for example url helpers.

## Reducers
## Config

All the reducers are located here.
In this folder all configuration is stored. All configuration can be overridden
in your theme package.

## Theme

Expand Down
14 changes: 8 additions & 6 deletions src/actions/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { LIST_ACTIONS } from '@plone/volto/constants/ActionTypes';
* @returns {Object} List actions action.
*/
export function listActions(url) {
return {
type: LIST_ACTIONS,
request: {
op: 'get',
path: `${url}/@actions`,
},
return async function (dispatch, getState) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this style of action needed? I don't know if this is a default feature of react-redux or it comes to us thanks to thunks support, but we're already able to treat the actions as async and wait their result, see for ex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @sneridagh is the one to weigh in on this, no?

dispatch({
type: LIST_ACTIONS,
request: {
op: 'get',
path: `${url}/@actions`,
},
});
};
}
15 changes: 11 additions & 4 deletions src/actions/actions/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ describe('Actions action', () => {
describe('listActions', () => {
it('should create an action to list the actions', () => {
const url = 'http://localhost';
const action = listActions(url);
const getState = () => ({});
const dispatch = jest.fn();

expect(action.type).toEqual(LIST_ACTIONS);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@actions`);
listActions(url)(dispatch, getState);

expect(dispatch).toHaveBeenCalledWith({
type: LIST_ACTIONS,
request: {
op: 'get',
path: `${url}/@actions`,
},
});
});
});
});
3 changes: 2 additions & 1 deletion src/actions/types/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { GET_TYPES } from '@plone/volto/constants/ActionTypes';
import { loggedIn } from '@plone/volto/selectors/userSession/userSession';

/**
* Get types function.
Expand All @@ -13,7 +14,7 @@ import { GET_TYPES } from '@plone/volto/constants/ActionTypes';
*/
export function getTypes(url) {
return (dispatch, getState) => {
if (getState().userSession.token) {
if (loggedIn(getState())) {
dispatch({
type: GET_TYPES,
request: {
Expand Down
13 changes: 7 additions & 6 deletions src/components/manage/Contents/Contents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
updateColumnsContent,
} from '@plone/volto/actions';
import Indexes, { defaultIndexes } from '@plone/volto/constants/Indexes';
import { loggedIn } from '@plone/volto/selectors/userSession/userSession';
import {
ContentsBreadcrumbs,
ContentsIndexHeader,
Expand Down Expand Up @@ -1099,9 +1100,7 @@ class Contents extends Component {
const selected = this.state.selected.length > 0;
const filteredItems = this.state.filteredItems || this.state.selected;
const path = getBaseUrl(this.props.pathname);
const folderContentsAction = find(this.props.objectActions, {
id: 'folderContents',
});
const folderContentsAction = this.props.actionsById.object.folderContents;

const loading =
(this.props.clipboardRequest?.loading &&
Expand All @@ -1111,7 +1110,7 @@ class Contents extends Component {
(this.props.orderRequest?.loading && !this.props.orderRequest?.error) ||
(this.props.searchRequest?.loading && !this.props.searchRequest?.error);

return this.props.token && this.props.objectActions.length > 0 ? (
return this.props.userLoggedIn && this.props.objectActions.length > 0 ? (
<>
{folderContentsAction ? (
<Container id="page-contents" className="folder-contents">
Expand Down Expand Up @@ -1796,7 +1795,8 @@ export const __test__ = compose(
connect(
(store, props) => {
return {
token: store.userSession.token,
userLoggedIn: loggedIn(store),
actionsById: store.actions.actionsById,
items: store.search.items,
sort: store.content.update.sort,
index: store.content.updatecolumns.idx,
Expand Down Expand Up @@ -1836,7 +1836,8 @@ export default compose(
connect(
(store, props) => {
return {
token: store.userSession.token,
userLoggedIn: loggedIn(store),
actionsById: store.actions.actionsById,
items: store.search.items,
sort: store.content.update.sort,
index: store.content.updatecolumns.idx,
Expand Down
26 changes: 14 additions & 12 deletions src/components/manage/Contents/Contents.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Provider } from 'react-intl-redux';
import { MemoryRouter } from 'react-router-dom';

import { __test__ as Contents } from './Contents';
import { arrayWIdsToObject } from '@plone/volto/helpers/Utils/Utils';

const mockStore = configureStore();

Expand All @@ -24,21 +25,22 @@ jest.mock('./ContentsUploadModal', () =>
jest.fn(() => <div className="UploadModal" />),
);

const actions = {
document_actions: [],
object: [
{
icon: '',
id: 'folderContents',
title: 'Contents',
},
],
};
const actionsById = arrayWIdsToObject(actions);

describe('Contents', () => {
it('renders a folder contents view component', () => {
const store = mockStore({
actions: {
actions: {
document_actions: [],
object: [
{
icon: '',
id: 'folderContents',
title: 'Contents',
},
],
},
},
actions: { actions, actionsById },
userSession: {
token: '14134234123qwdaf',
},
Expand Down
Loading