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

Enforce limits on number of teams that can be created #959

Merged
merged 4 commits into from
Sep 8, 2022
Merged

Conversation

knolleary
Copy link
Member

Closes #778 #955

This limits how many teams can be created on the platform.

The limit is applied in the beforeCreate hook of the Team model.

There are three ways a team can be created:

  1. A user creates a team - this is policed via the beforeCreate hook and an error returned to the ui
  2. An admin creates a user and ticks 'create personal team' - by the time it comes to create the team, the user has already been created - so too late to reject the request. So this does its own check of the limit before attempting to create the user.
  3. A user registers on the platform and the 'auto-create team' option is enabled - same as above (does explicit limit check)

Aside: for 2 & 3, I identified a bug (#955) that was stopping them from working. This PR addresses that bug by ensuring the TeamType is set on the projects they create. In fact, I have added a beforeCreate check to ensure TeamTypeId is always provided when creating a team. This required a couple tests to be updated as they weren't doing so.

@knolleary knolleary linked an issue Sep 8, 2022 that may be closed by this pull request
@knolleary knolleary changed the title Enfore limits on number of teams that can be created Enforce limits on number of teams that can be created Sep 8, 2022
Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

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

all good

@Steve-Mcl
Copy link
Contributor

@knolleary code looks fine but there is an error in Project Lifecycle test...

Project Lifecycle
       "before all" hook for "login user":
     Error: Cannot create team without TeamTypeId
      at Function.beforeCreate (forge/db/models/Team.js:21:27)
      at Function.runHooks (node_modules/sequelize/lib/hooks.js:94:18)
      at model.save (node_modules/sequelize/lib/model.js:2378:30)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async Function.create (node_modules/sequelize/lib/model.js:1344:12)
      at async Context.<anonymous> (test/system/100-project-lifecycle_spec.js:51:29)

Can I ask if this ran ok under SQLITE locally?

@knolleary
Copy link
Member Author

@Steve-Mcl fix pushed. I verified the unit tests but overlooked the system test folder when looking for calls to Team.create that needed updating.

@Steve-Mcl Steve-Mcl merged commit d37ea0a into main Sep 8, 2022
@Steve-Mcl Steve-Mcl deleted the team-limits branch September 8, 2022 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants