Skip to content

Commit

Permalink
feat: Ability to allow everyone to create projects (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanVss authored Jun 14, 2024
1 parent f0e9fe7 commit cc1e886
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/src/containers/ProjectsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import entryActions from '../entry-actions';
import Projects from '../components/Projects';

const mapStateToProps = (state) => {
const { allowAllToCreateProjects } = selectors.selectConfig(state);
const { isAdmin } = selectors.selectCurrentUser(state);
const projects = selectors.selectProjectsForCurrentUser(state);

return {
items: projects,
canAdd: isAdmin,
canAdd: allowAllToCreateProjects || isAdmin,
};
};

Expand Down
9 changes: 5 additions & 4 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3.8'

services:

server:
build:
context: ./server
Expand All @@ -13,6 +12,7 @@ services:
- NODE_ENV=development
- DATABASE_URL=postgresql://user:password@postgres:5432/planka_db
- SECRET_KEY=notsecretkey

# - TRUST_PROXY=0
# - TOKEN_EXPIRES_IN=365 # In days

Expand All @@ -23,6 +23,9 @@ services:

# Configure knex to accept SSL certificates
# - KNEX_REJECT_UNAUTHORIZED_SSL_CERTIFICATE=false

# - ALLOW_ALL_TO_CREATE_PROJECTS=true

# - OIDC_ISSUER=
# - OIDC_CLIENT_ID=
# - OIDC_CLIENT_SECRET=
Expand Down Expand Up @@ -56,7 +59,6 @@ services:

# - SLACK_BOT_TOKEN=
# - SLACK_CHANNEL_ID=

working_dir: /app
command: ["sh", "-c", "npm run start"]
depends_on:
Expand Down Expand Up @@ -85,11 +87,11 @@ services:
dockerfile: ../config/development/Dockerfile.server
environment:
- DATABASE_URL=postgresql://user:password@postgres:5432/planka_db

# - DEFAULT_ADMIN_EMAIL=demo@demo.demo # Do not remove if you want to prevent this user from being edited/deleted
# - DEFAULT_ADMIN_PASSWORD=demo
# - DEFAULT_ADMIN_NAME=Demo Demo
# - DEFAULT_ADMIN_USERNAME=demo

working_dir: /app
command: ["sh", "-c", "npm run db:init"]
volumes:
Expand Down Expand Up @@ -126,6 +128,5 @@ services:
- server
- client


volumes:
db-data:
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ services:
# - DEFAULT_ADMIN_NAME=Demo Demo
# - DEFAULT_ADMIN_USERNAME=demo

# - ALLOW_ALL_TO_CREATE_PROJECTS=true

# - OIDC_ISSUER=
# - OIDC_CLIENT_ID=
# - OIDC_CLIENT_SECRET=
Expand Down
2 changes: 2 additions & 0 deletions server/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SECRET_KEY=notsecretkey
# DEFAULT_ADMIN_NAME=Demo Demo
# DEFAULT_ADMIN_USERNAME=demo

# ALLOW_ALL_TO_CREATE_PROJECTS=true

# OIDC_ISSUER=
# OIDC_CLIENT_ID=
# OIDC_CLIENT_SECRET=
Expand Down
16 changes: 16 additions & 0 deletions server/api/controllers/projects/create.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
};

module.exports = {
inputs: {
name: {
Expand All @@ -6,9 +12,19 @@ module.exports = {
},
},

exits: {
notEnoughRights: {
responseType: 'forbidden',
},
},

async fn(inputs) {
const { currentUser } = this.req;

if (!currentUser.isAdmin && !sails.config.custom.allowAllToCreateProjects) {
throw Errors.NOT_ENOUGH_RIGHTS;
}

const values = _.pick(inputs, ['name']);

const { project, projectManager } = await sails.helpers.projects.createOne.with({
Expand Down
1 change: 1 addition & 0 deletions server/api/controllers/show-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
return {
item: {
oidc,
allowAllToCreateProjects: sails.config.custom.allowAllToCreateProjects,
},
};
},
Expand Down
2 changes: 2 additions & 0 deletions server/config/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports.custom = {
defaultAdminEmail:
process.env.DEFAULT_ADMIN_EMAIL && process.env.DEFAULT_ADMIN_EMAIL.toLowerCase(),

allowAllToCreateProjects: process.env.ALLOW_ALL_TO_CREATE_PROJECTS === 'true',

oidcIssuer: process.env.OIDC_ISSUER,
oidcClientId: process.env.OIDC_CLIENT_ID,
oidcClientSecret: process.env.OIDC_CLIENT_SECRET,
Expand Down
2 changes: 0 additions & 2 deletions server/config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module.exports.policies = {
'users/create': ['is-authenticated', 'is-admin'],
'users/delete': ['is-authenticated', 'is-admin'],

'projects/create': ['is-authenticated', 'is-admin'],

'show-config': true,
'access-tokens/create': true,
'access-tokens/exchange-using-oidc': true,
Expand Down

0 comments on commit cc1e886

Please sign in to comment.