-
Notifications
You must be signed in to change notification settings - Fork 41
Issue 5727 - Create an endpoint to create teamspace #5749
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
Open
Bogdan-Crn
wants to merge
10
commits into
staging
Choose a base branch
from
ISSUE_5727
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fb0007
Issue #5727 - add createTeamspace endpoint, validation and tests
Bogdan-Crn 58e5fa0
Issue #5727 - merge staging
Bogdan-Crn 2d12c81
Issue #5727 - pre merging commit
Bogdan-Crn 0fbc23a
Issue #5727 - merge staging
Bogdan-Crn 9ebf43a
Issue #5727 - fix tests
Bogdan-Crn f02855e
Issue #5727 - fix lint issues
Bogdan-Crn ab46b4b
Issue #5727 - slight update
Bogdan-Crn 1cc3560
Issue #5727 - last touch
Bogdan-Crn e441c73
ISSUE #5727 small fixes
ChristosTsiotsias f3e32d2
Merge branch 'staging' into ISSUE_5727
ChristosTsiotsias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,14 +15,21 @@ | |
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| const { canRemoveTeamspaceMember, memberExists, validateUpdateQuota } = require('../../middleware/dataConverter/inputs/teamspaces'); | ||
| const { canRemoveTeamspaceMember, memberExists, validateCreateTeamspaceData, validateUpdateQuota } = require('../../middleware/dataConverter/inputs/teamspaces'); | ||
|
|
||
| const { hasAccessToTeamspace, isMemberOfTeamspace, isTeamspaceAdmin } = require('../../middleware/permissions'); | ||
|
|
||
| const { DEFAULT_OWNER_JOB } = require('../../models/jobs.constants'); | ||
| const { Router } = require('express'); | ||
| const { SUBSCRIPTION_TYPES } = require('../../models/teamspaces.constants'); | ||
| const Teamspaces = require('../../processors/teamspaces'); | ||
| const Users = require('../../processors/users'); | ||
| /* istanbul ignore file */ | ||
| const { v4Path } = require('../../../interop'); | ||
| // eslint-disable-next-line import/no-dynamic-require, security/detect-non-literal-require, require-sort/require-sort | ||
| const { create: createInvite } = require(`${v4Path}/models/invitations`); | ||
| const { fileExtensionFromBuffer } = require('../../utils/helper/typeCheck'); | ||
| const { getUserByEmail } = require('../../models/users'); | ||
| const { notUserProvisioned } = require('../../middleware/permissions/components/teamspaces'); | ||
| const { respond } = require('../../utils/responder'); | ||
| const { templates } = require('../../utils/responseCodes'); | ||
|
|
@@ -131,6 +138,34 @@ const removeQuota = async (req, res) => { | |
| } | ||
| }; | ||
|
|
||
| const createTeamspace = async (req, res) => { | ||
| const { name, accountId, admin } = req.body; | ||
| let userName; | ||
|
|
||
| try { | ||
| if (admin) { | ||
| const result = await getUserByEmail(admin) | ||
| .catch((e) => { | ||
| if (e.message !== templates.userNotFound.message) throw e; | ||
| return {}; | ||
| }); | ||
|
|
||
| userName = result.user; | ||
| } | ||
|
|
||
| await Teamspaces.initTeamspace(name, userName, accountId); | ||
|
|
||
| if (!userName && admin) { | ||
| await createInvite(admin, name, DEFAULT_OWNER_JOB, undefined, { teamspace_admin: true }, false); | ||
| } | ||
|
|
||
| respond(req, res, templates.ok); | ||
| } catch (err) { | ||
| // istanbul ignore next | ||
| respond(req, res, err); | ||
| } | ||
| }; | ||
|
|
||
| const establishRoutes = (isInternal) => { | ||
| const router = Router({ mergeParams: true }); | ||
|
|
||
|
|
@@ -196,6 +231,42 @@ const establishRoutes = (isInternal) => { | |
| * description: quota has been removed | ||
| */ | ||
| router.delete('/:teamspace/quota', isMemberOfTeamspace, removeQuota); | ||
|
|
||
| /** | ||
| * @openapi | ||
| * /teamspaces: | ||
| * post: | ||
| * description: Create a new teamspace | ||
| * tags: [v:internal, Teamspaces] | ||
| * operationId: createTeamspace | ||
| * requestBody: | ||
| * required: true | ||
| * content: | ||
| * application/json: | ||
| * schema: | ||
| * type: object | ||
| * properties: | ||
| * name: | ||
| * type: string | ||
| * description: Name of the teamspace to be created | ||
| * example: New Teamspace | ||
| * accountId: | ||
| * type: string | ||
| * description: The account ID the teamspace will belong to | ||
| * example: 3fa85f64-5717-4562-b3fc-2c963f66afa6 | ||
| * admin: | ||
| * type: string | ||
| * description: The email of the owner of the teamspace | ||
| * example: [email protected] | ||
| * responses: | ||
| * 200: | ||
| * description: Teamspace created successfully | ||
| * 400: | ||
| * $ref: "#/components/responses/invalidArguments" | ||
| * 409: | ||
| * $ref: "#/components/responses/resourceAlreadyExists" | ||
| */ | ||
| router.post('/', validateCreateTeamspaceData, createTeamspace); | ||
| } else { | ||
| /** | ||
| * @openapi | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method should just call initTeamspace. The user invitation will be handled by frontegg.
In any case even if we had to send the invitation we should do this in the processor not in routes and not using a v4 method 😄