2023-07-06 09:33:31 +00:00
import { describe , it , vi , expect } from "vitest" ;
2023-08-01 15:55:31 +00:00
import { isTeamAdmin } from "@calcom/lib/server/queries" ;
2023-07-06 09:33:31 +00:00
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations" ;
2023-08-01 15:55:31 +00:00
import type { User } from "@calcom/prisma/client" ;
2023-07-06 09:33:31 +00:00
import { MembershipRole } from "@calcom/prisma/enums" ;
2023-08-01 15:55:31 +00:00
2023-07-06 09:33:31 +00:00
import { TRPCError } from "@trpc/server" ;
2023-08-01 15:55:31 +00:00
2023-07-06 09:33:31 +00:00
import type { TeamWithParent } from "./types" ;
2023-08-01 15:55:31 +00:00
import {
checkInputEmailIsValid ,
checkPermissions ,
getEmailsToInvite ,
getIsOrgVerified ,
getOrgConnectionInfo ,
throwIfInviteIsToOrgAndUserExists ,
createAndAutoJoinIfInOrg ,
} from "./utils" ;
2023-07-06 09:33:31 +00:00
vi . mock ( "@calcom/lib/server/queries" , ( ) = > {
return {
isTeamAdmin : vi.fn ( ) ,
} ;
} ) ;
vi . mock ( "@calcom/lib/server/queries/organisations" , ( ) = > {
return {
isOrganisationAdmin : vi.fn ( ) ,
} ;
} ) ;
2023-08-01 15:55:31 +00:00
const mockedReturnSuccessCheckPerms = {
accepted : true ,
disableImpersonation : false ,
id : 1 ,
role : MembershipRole.ADMIN ,
userId : 1 ,
teamId : 1 ,
} ;
2023-07-06 09:33:31 +00:00
const mockedTeam : TeamWithParent = {
id : 1 ,
name : "Team A" ,
slug : null ,
logo : null ,
appLogo : null ,
appIconLogo : null ,
bio : null ,
hideBranding : false ,
hideBookATeamMember : false ,
createdAt : new Date ( ) ,
brandColor : "#292929" ,
darkBrandColor : "#fafafa" ,
timeZone : "Europe/London" ,
weekStart : "Sunday" ,
theme : null ,
timeFormat : null ,
metadata : null ,
parentId : null ,
feat: from org team invite (#9569)
* Initial commit
* Adding feature flag
* Desktop first banner, mobile pending
* Removing dead code and img
* AppInstallButtonBase
* WIP
* Adds Email verification template+translations for organizations (#9202)
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Session logic to show org label
* Step 2 done, avatar not working
* List orgs and list teams specific if orgs exist
* Conditionally show org - fix settings layout - add labels for all pages
* Profile Page + update
* Org specific team creation
* appearance page
* Ensure members cant of org cant update settings in UI
* Fix update handler imports
* hide billing on sub teams
* Update profile slug page
* Letting duplicate slugs for teams to support orgs
* Add slug coliisions for org
* Covering null on unique clauses
* Covering null on unique clauses
* Extract to utils
* Update settings to use subdomain path in team url , team + org
* Supporting having the orgId in the session cookie
* Onboarding admins step
* Last step to create teams
* Update handler comments
* Upgrade ORG banner - disabled team banner for child teams
* Handle publishing ORGS
* Fix licenese issue
* Update packages/trpc/server/routers/viewer/teams/create.handler.ts
* Split into function calls to make this file more explisit
* Update parents stripe sub not teamID
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Create org membership also - billing portal page
* A11ly
* Hide create team if no valid permisisons
* Get Org members router
* Handle updating subscription if orgId
* Fix double upgrade banner
* Update constants
* Feedback
* Copy change
* Making an org avatar (temp)
* Add slug colission detection for user and team name
* Fix Import
* Remove update password func
* Fix module import over relative
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Fix import again
* Throw no team found before auth error
* Check if invited found user is already in differnt org
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Move to for of loop to throw errors in usenamelist
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Remove app install button sa its in 9337
* Remove i18n key not being used
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Fix router
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: organization settings general and members page (#9266)
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Type fixes
* Use org Stripe product when upgrading
* Removed unused code
* UI completed
* Reverting changes
* Update UsernameTextfield.tsx
* More reverts
* Update next-auth-options.ts
* Update common.json
* Type fixes
* Include invite token for orgs
* Update org schema
* Make token settings optional as it isnt used in orgs yet
* Reverts
* Add correct array logic and move to controlled component
* Fix toggle group default | Update toggle group bg
* Darkmode toggle group
* Distinct user
* Hide modal if no org members
* Extract toggle logic
* Update packages/features/ee/organizations/components/TeamInviteFromOrg.tsx
* remove yarn.lock from commit
* Fix types
* Add getMember router back
* As a query lol
* Fix types
* Fix accepted param defaulting to true as we want both
* Fix list not pulling back people who have not joined the org yet
* Fix tests to handle invite a existing org user to a team
* Fix test
* Fix an error sometimes when existing org user is invited
* Updates radix & fixes bug
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com>
2023-07-10 09:46:51 +00:00
parent : null ,
2023-08-01 15:55:31 +00:00
isPrivate : false ,
2023-07-06 09:33:31 +00:00
} ;
const mockUser : User = {
id : 4 ,
2023-08-01 15:55:31 +00:00
username : "pro" ,
name : "Pro Example" ,
email : "pro@example.com" ,
2023-07-06 09:33:31 +00:00
emailVerified : new Date ( ) ,
2023-08-01 15:55:31 +00:00
password : "" ,
2023-07-06 09:33:31 +00:00
bio : null ,
avatar : null ,
2023-08-01 15:55:31 +00:00
timeZone : "Europe/London" ,
weekStart : "Sunday" ,
2023-07-06 09:33:31 +00:00
startTime : 0 ,
endTime : 1440 ,
bufferTime : 0 ,
hideBranding : false ,
theme : null ,
createdDate : new Date ( ) ,
trialEndsAt : null ,
defaultScheduleId : null ,
completedOnboarding : true ,
2023-08-01 15:55:31 +00:00
locale : "en" ,
2023-07-06 09:33:31 +00:00
timeFormat : 12 ,
twoFactorSecret : null ,
twoFactorEnabled : false ,
2023-08-01 15:55:31 +00:00
identityProvider : "CAL" ,
2023-07-06 09:33:31 +00:00
identityProviderId : null ,
invitedTo : null ,
2023-08-01 15:55:31 +00:00
brandColor : "#292929" ,
darkBrandColor : "#fafafa" ,
2023-07-06 09:33:31 +00:00
away : false ,
allowDynamicBooking : true ,
metadata : null ,
verified : false ,
2023-08-01 15:55:31 +00:00
role : "USER" ,
2023-07-06 09:33:31 +00:00
disableImpersonation : false ,
2023-08-01 15:55:31 +00:00
organizationId : null ,
} ;
2023-07-06 09:33:31 +00:00
describe ( "Invite Member Utils" , ( ) = > {
describe ( "checkPermissions" , ( ) = > {
it ( "It should throw an error if the user is not an admin of the ORG" , async ( ) = > {
vi . mocked ( isOrganisationAdmin ) . mockResolvedValue ( false ) ;
await expect ( checkPermissions ( { userId : 1 , teamId : 1 , isOrg : true } ) ) . rejects . toThrow ( ) ;
2023-08-01 15:55:31 +00:00
} ) ;
2023-07-06 09:33:31 +00:00
it ( "It should NOT throw an error if the user is an admin of the ORG" , async ( ) = > {
vi . mocked ( isOrganisationAdmin ) . mockResolvedValue ( mockedReturnSuccessCheckPerms ) ;
await expect ( checkPermissions ( { userId : 1 , teamId : 1 , isOrg : true } ) ) . resolves . not . toThrow ( ) ;
2023-08-01 15:55:31 +00:00
} ) ;
2023-07-06 09:33:31 +00:00
it ( "It should throw an error if the user is not an admin of the team" , async ( ) = > {
vi . mocked ( isTeamAdmin ) . mockResolvedValue ( false ) ;
await expect ( checkPermissions ( { userId : 1 , teamId : 1 } ) ) . rejects . toThrow ( ) ;
2023-08-01 15:55:31 +00:00
} ) ;
2023-07-06 09:33:31 +00:00
it ( "It should NOT throw an error if the user is an admin of a team" , async ( ) = > {
vi . mocked ( isTeamAdmin ) . mockResolvedValue ( mockedReturnSuccessCheckPerms ) ;
await expect ( checkPermissions ( { userId : 1 , teamId : 1 } ) ) . resolves . not . toThrow ( ) ;
2023-08-01 15:55:31 +00:00
} ) ;
} ) ;
describe ( "getEmailsToInvite" , ( ) = > {
it ( "should throw a TRPCError with code BAD_REQUEST if no emails are provided" , async ( ) = > {
2023-07-06 09:33:31 +00:00
await expect ( getEmailsToInvite ( [ ] ) ) . rejects . toThrow ( TRPCError ) ;
} ) ;
2023-08-01 15:55:31 +00:00
it ( "should return an array with one email if a string is provided" , async ( ) = > {
const result = await getEmailsToInvite ( "test@example.com" ) ;
expect ( result ) . toEqual ( [ "test@example.com" ] ) ;
2023-07-06 09:33:31 +00:00
} ) ;
2023-08-01 15:55:31 +00:00
it ( "should return an array with multiple emails if an array is provided" , async ( ) = > {
const result = await getEmailsToInvite ( [ "test1@example.com" , "test2@example.com" ] ) ;
expect ( result ) . toEqual ( [ "test1@example.com" , "test2@example.com" ] ) ;
2023-07-06 09:33:31 +00:00
} ) ;
} ) ;
2023-08-01 15:55:31 +00:00
describe ( "checkInputEmailIsValid" , ( ) = > {
it ( "should throw a TRPCError with code BAD_REQUEST if the email is invalid" , ( ) = > {
const invalidEmail = "invalid-email" ;
2023-07-06 09:33:31 +00:00
expect ( ( ) = > checkInputEmailIsValid ( invalidEmail ) ) . toThrow ( TRPCError ) ;
expect ( ( ) = > checkInputEmailIsValid ( invalidEmail ) ) . toThrowError (
2023-08-01 15:55:31 +00:00
"Invite failed because invalid-email is not a valid email address"
2023-07-06 09:33:31 +00:00
) ;
} ) ;
2023-08-01 15:55:31 +00:00
it ( "should not throw an error if the email is valid" , ( ) = > {
const validEmail = "valid-email@example.com" ;
2023-07-06 09:33:31 +00:00
expect ( ( ) = > checkInputEmailIsValid ( validEmail ) ) . not . toThrow ( ) ;
} ) ;
} ) ;
describe ( "getOrgConnectionInfo" , ( ) = > {
const orgAutoAcceptDomain = "example.com" ;
const usersEmail = "user@example.com" ;
it ( "should return orgId and autoAccept as true if team has parent and usersEmail domain matches orgAutoAcceptDomain and orgVerified is true" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
orgVerified : true ,
usersEmail ,
team : {
. . . mockedTeam ,
parentId : 2 ,
} ,
isOrg : false ,
} ) ;
expect ( result ) . toEqual ( { orgId : 2 , autoAccept : true } ) ;
} ) ;
it ( "should return orgId and autoAccept as false if team has parent and usersEmail domain does not match orgAutoAcceptDomain" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
usersEmail : "user@other.com" ,
team : {
. . . mockedTeam ,
parentId : 2 ,
} ,
isOrg : false ,
} ) ;
expect ( result ) . toEqual ( { orgId : undefined , autoAccept : false } ) ;
} ) ;
it ( "should return orgId and autoAccept as false if team has parent and usersEmail domain matches orgAutoAcceptDomain but orgVerified is false" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
orgVerified : false ,
usersEmail ,
team : { . . . mockedTeam } ,
isOrg : false ,
} ) ;
expect ( result ) . toEqual ( { orgId : undefined , autoAccept : false } ) ;
} ) ;
it ( "should return orgId and autoAccept as true if team has no parent and isOrg is true and usersEmail domain matches orgAutoAcceptDomain and orgVerified is true" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
orgVerified : true ,
usersEmail ,
team : { . . . mockedTeam , parentId : null } ,
isOrg : true ,
} ) ;
expect ( result ) . toEqual ( { orgId : 1 , autoAccept : true } ) ;
} ) ;
it ( "should return orgId and autoAccept as false if team has no parent and isOrg is true and usersEmail domain does not match orgAutoAcceptDomain" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
usersEmail : "user@other.com" ,
team : { . . . mockedTeam , parentId : null } ,
isOrg : true ,
} ) ;
expect ( result ) . toEqual ( { orgId : undefined , autoAccept : false } ) ;
} ) ;
it ( "should return orgId and autoAccept as false if team has no parent and isOrg is true and usersEmail domain matches orgAutoAcceptDomain but orgVerified is false" , ( ) = > {
const result = getOrgConnectionInfo ( {
orgAutoAcceptDomain ,
orgVerified : false ,
usersEmail ,
team : { . . . mockedTeam , parentId : null } ,
isOrg : true ,
} ) ;
expect ( result ) . toEqual ( { orgId : mockedTeam.id , autoAccept : false } ) ;
} ) ;
} ) ;
describe ( "getIsOrgVerified" , ( ) = > {
it ( "should return the correct values when isOrg is true and teamMetadata.orgAutoAcceptEmail is true" , ( ) = > {
const team = {
metadata : {
isOrganizationVerified : true ,
orgAutoAcceptEmail : "example.com" ,
} ,
parent : null ,
} ;
const result = getIsOrgVerified ( true , { . . . mockedTeam , . . . team } ) ;
expect ( result ) . toEqual ( {
isInOrgScope : true ,
orgVerified : true ,
autoAcceptEmailDomain : "example.com" ,
} ) ;
} ) ;
it ( "should return the correct values when orgMetadataIfExists.orgAutoAcceptEmail is true" , ( ) = > {
const team = {
metadata : { } ,
parent : {
. . . mockedTeam ,
metadata : {
isOrganizationVerified : false ,
orgAutoAcceptEmail : "example.com" ,
} ,
} ,
} ;
const result = getIsOrgVerified ( false , { . . . mockedTeam , . . . team } ) ;
expect ( result ) . toEqual ( {
isInOrgScope : true ,
orgVerified : false ,
autoAcceptEmailDomain : "example.com" ,
} ) ;
} ) ;
it ( "should return the correct values when neither isOrg nor orgMetadataIfExists.orgAutoAcceptEmail is true" , ( ) = > {
const team = {
metadata : { } ,
parent : null ,
} ;
const result = getIsOrgVerified ( false , { . . . mockedTeam , . . . team } ) ;
expect ( result ) . toEqual ( {
isInOrgScope : false ,
} ) ;
} ) ;
} ) ;
describe ( "throwIfInviteIsToOrgAndUserExists" , ( ) = > {
const invitee : User = {
. . . mockUser ,
id : 1 ,
username : "testuser" ,
email : "testuser@example.com" ,
organizationId : null ,
} ;
const isOrg = false ;
feat: from org team invite (#9569)
* Initial commit
* Adding feature flag
* Desktop first banner, mobile pending
* Removing dead code and img
* AppInstallButtonBase
* WIP
* Adds Email verification template+translations for organizations (#9202)
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Session logic to show org label
* Step 2 done, avatar not working
* List orgs and list teams specific if orgs exist
* Conditionally show org - fix settings layout - add labels for all pages
* Profile Page + update
* Org specific team creation
* appearance page
* Ensure members cant of org cant update settings in UI
* Fix update handler imports
* hide billing on sub teams
* Update profile slug page
* Letting duplicate slugs for teams to support orgs
* Add slug coliisions for org
* Covering null on unique clauses
* Covering null on unique clauses
* Extract to utils
* Update settings to use subdomain path in team url , team + org
* Supporting having the orgId in the session cookie
* Onboarding admins step
* Last step to create teams
* Update handler comments
* Upgrade ORG banner - disabled team banner for child teams
* Handle publishing ORGS
* Fix licenese issue
* Update packages/trpc/server/routers/viewer/teams/create.handler.ts
* Split into function calls to make this file more explisit
* Update parents stripe sub not teamID
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Create org membership also - billing portal page
* A11ly
* Hide create team if no valid permisisons
* Get Org members router
* Handle updating subscription if orgId
* Fix double upgrade banner
* Update constants
* Feedback
* Copy change
* Making an org avatar (temp)
* Add slug colission detection for user and team name
* Fix Import
* Remove update password func
* Fix module import over relative
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Fix import again
* Throw no team found before auth error
* Check if invited found user is already in differnt org
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Move to for of loop to throw errors in usenamelist
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Remove app install button sa its in 9337
* Remove i18n key not being used
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Fix router
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: organization settings general and members page (#9266)
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Type fixes
* Use org Stripe product when upgrading
* Removed unused code
* UI completed
* Reverting changes
* Update UsernameTextfield.tsx
* More reverts
* Update next-auth-options.ts
* Update common.json
* Type fixes
* Include invite token for orgs
* Update org schema
* Make token settings optional as it isnt used in orgs yet
* Reverts
* Add correct array logic and move to controlled component
* Fix toggle group default | Update toggle group bg
* Darkmode toggle group
* Distinct user
* Hide modal if no org members
* Extract toggle logic
* Update packages/features/ee/organizations/components/TeamInviteFromOrg.tsx
* remove yarn.lock from commit
* Fix types
* Add getMember router back
* As a query lol
* Fix types
* Fix accepted param defaulting to true as we want both
* Fix list not pulling back people who have not joined the org yet
* Fix tests to handle invite a existing org user to a team
* Fix test
* Fix an error sometimes when existing org user is invited
* Updates radix & fixes bug
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com>
2023-07-10 09:46:51 +00:00
it ( "should not throw when inviting an existing user to the same organization" , ( ) = > {
2023-07-06 09:33:31 +00:00
const inviteeWithOrg : User = {
. . . invitee ,
organizationId : 2 ,
} ;
const teamWithOrg = {
. . . mockedTeam ,
parentId : 2 ,
2023-08-01 15:55:31 +00:00
} ;
expect ( ( ) = > throwIfInviteIsToOrgAndUserExists ( inviteeWithOrg , teamWithOrg , isOrg ) ) . not . toThrow ( ) ;
feat: from org team invite (#9569)
* Initial commit
* Adding feature flag
* Desktop first banner, mobile pending
* Removing dead code and img
* AppInstallButtonBase
* WIP
* Adds Email verification template+translations for organizations (#9202)
* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)
* Change scopedMembers to orgMembers
* Change to orgUsers
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Session logic to show org label
* Step 2 done, avatar not working
* List orgs and list teams specific if orgs exist
* Conditionally show org - fix settings layout - add labels for all pages
* Profile Page + update
* Org specific team creation
* appearance page
* Ensure members cant of org cant update settings in UI
* Fix update handler imports
* hide billing on sub teams
* Update profile slug page
* Letting duplicate slugs for teams to support orgs
* Add slug coliisions for org
* Covering null on unique clauses
* Covering null on unique clauses
* Extract to utils
* Update settings to use subdomain path in team url , team + org
* Supporting having the orgId in the session cookie
* Onboarding admins step
* Last step to create teams
* Update handler comments
* Upgrade ORG banner - disabled team banner for child teams
* Handle publishing ORGS
* Fix licenese issue
* Update packages/trpc/server/routers/viewer/teams/create.handler.ts
* Split into function calls to make this file more explisit
* Update parents stripe sub not teamID
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Create org membership also - billing portal page
* A11ly
* Hide create team if no valid permisisons
* Get Org members router
* Handle updating subscription if orgId
* Fix double upgrade banner
* Update constants
* Feedback
* Copy change
* Making an org avatar (temp)
* Add slug colission detection for user and team name
* Fix Import
* Remove update password func
* Fix module import over relative
* feat: organization event type filter (#9253)
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Missing changes to support orgs schema changes
* Fix import again
* Throw no team found before auth error
* Check if invited found user is already in differnt org
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Move to for of loop to throw errors in usenamelist
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Remove app install button sa its in 9337
* Remove i18n key not being used
* feat: Onboarding process to create an organization (#9184)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* feedback
* Making sure we check requestedSlug now
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* feat: [CAL-1816] Organization subdomain support (#9345)
* Desktop first banner, mobile pending
* Removing dead code and img
* WIP
* Adds Email verification template+translations for organizations (#9202)
* First step done
* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding
* Step 2 done, avatar not working
* Covering null on unique clauses
* Onboarding admins step
* Last step to create teams
* Moving change password handler, improving verifying code flow
* Clearing error before submitting
* Reverting email testing api changes
* Reverting having the banner for now
* Consistent exported components
* Remove unneeded files from banner
* Removing uneeded code
* Fixing avatar selector
* Using meta component for head/descr
* Missing i18n strings
* Feedback
* Making an org avatar (temp)
* Check for subteams slug clashes with usernames
* Fixing create teams onsuccess
* Covering users and subteams, excluding non-org users
* Unpublished teams shows correctly
* Create subdomain in Vercel
* feedback
* Renaming Vercel env vars
* Vercel domain check before creation
* Supporting cal-staging.com
* Change to have vercel detect it
* vercel domain check data message error
* Remove check domain
* Making sure we check requestedSlug now
* Feedback and unneeded code
* Reverting unneeded changes
* Unneeded changes
---------
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
* Vercel subdomain creation in PROD only
* Fix router
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: organization settings general and members page (#9266)
* feat: organization settings general page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* feat: add members page
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore: remove
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use invalidate
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: delete mutation
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: remove organization id
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* chore
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* fix: use zod schema
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
* Type fixes
* Use org Stripe product when upgrading
* Removed unused code
* UI completed
* Reverting changes
* Update UsernameTextfield.tsx
* More reverts
* Update next-auth-options.ts
* Update common.json
* Type fixes
* Include invite token for orgs
* Update org schema
* Make token settings optional as it isnt used in orgs yet
* Reverts
* Add correct array logic and move to controlled component
* Fix toggle group default | Update toggle group bg
* Darkmode toggle group
* Distinct user
* Hide modal if no org members
* Extract toggle logic
* Update packages/features/ee/organizations/components/TeamInviteFromOrg.tsx
* remove yarn.lock from commit
* Fix types
* Add getMember router back
* As a query lol
* Fix types
* Fix accepted param defaulting to true as we want both
* Fix list not pulling back people who have not joined the org yet
* Fix tests to handle invite a existing org user to a team
* Fix test
* Fix an error sometimes when existing org user is invited
* Updates radix & fixes bug
---------
Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: Leo Giovanetti <hello@leog.me>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com>
2023-07-10 09:46:51 +00:00
} ) ;
it ( "should throw a TRPCError with code FORBIDDEN if the invitee is already a member of another organization" , ( ) = > {
const inviteeWithOrg : User = {
. . . invitee ,
organizationId : 2 ,
} ;
const teamWithOrg = {
. . . mockedTeam ,
parentId : 3 ,
2023-08-01 15:55:31 +00:00
} ;
expect ( ( ) = > throwIfInviteIsToOrgAndUserExists ( inviteeWithOrg , teamWithOrg , isOrg ) ) . toThrow ( TRPCError ) ;
2023-07-06 09:33:31 +00:00
} ) ;
it ( "should throw a TRPCError with code FORBIDDEN if the invitee already exists in Cal.com and is being invited to an organization" , ( ) = > {
const isOrg = true ;
2023-08-01 15:55:31 +00:00
expect ( ( ) = > throwIfInviteIsToOrgAndUserExists ( invitee , mockedTeam , isOrg ) ) . toThrow ( TRPCError ) ;
2023-07-06 09:33:31 +00:00
} ) ;
it ( "should not throw an error if the invitee does not already belong to another organization and is not being invited to an organization" , ( ) = > {
2023-08-01 15:55:31 +00:00
expect ( ( ) = > throwIfInviteIsToOrgAndUserExists ( invitee , mockedTeam , isOrg ) ) . not . toThrow ( ) ;
2023-07-06 09:33:31 +00:00
} ) ;
} ) ;
2023-07-28 16:43:35 +00:00
describe ( "createAndAutoJoinIfInOrg" , ( ) = > {
it ( "should return autoJoined: false if the user is not in the same organization as the team" , async ( ) = > {
const result = await createAndAutoJoinIfInOrg ( {
team : mockedTeam ,
role : MembershipRole.ADMIN ,
invitee : mockUser ,
} ) ;
expect ( result ) . toEqual ( { autoJoined : false } ) ;
} ) ;
2023-08-01 15:55:31 +00:00
2023-07-28 16:43:35 +00:00
it ( "should return autoJoined: false if the team does not have a parent organization" , async ( ) = > {
const result = await createAndAutoJoinIfInOrg ( {
team : { . . . mockedTeam , parentId : null } ,
role : MembershipRole.ADMIN ,
invitee : mockUser ,
} ) ;
expect ( result ) . toEqual ( { autoJoined : false } ) ;
} ) ;
// TODO: Add test for when the user is already a member of the organization - need to mock prisma response value
} ) ;
2023-08-01 15:55:31 +00:00
} ) ;