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

fix: join subteam as their respective organization role #12216

Merged
merged 8 commits into from
Dec 19, 2023

Conversation

SomayChauhan
Copy link
Member

Fixes #11732

Screencast.from.03-11-23.12.29.02.PM.IST.webm
  • Bug fix (non-breaking change which fixes an issue)

Copy link

vercel bot commented Nov 3, 2023

@SomayChauhan is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added Low priority Created by Linear-GitHub Sync organizations area: organizations, orgs ✅ good first issue Good for newcomers labels Nov 3, 2023
Copy link
Contributor

github-actions bot commented Nov 3, 2023

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link to collect XP and win prizes!

Copy link
Contributor

github-actions bot commented Nov 3, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@@ -373,7 +377,7 @@ export async function createAndAutoJoinIfInOrg({
userId: invitee.id,
teamId: team.id,
accepted: true,
role: role,
role: currentRole,
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about just doing this here:

orgMembership.role !== MembershipRole.MEMBER ? orgMembership.role : role ?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually can't we just consider that if orgMembership role exists we should just set that ?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, because lets say i have a user in my organization as MEMBER now I want to make that user as a admin/owner of this team

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you think about just doing this here:

orgMembership.role !== MembershipRole.MEMBER ? orgMembership.role : role ?

this I can do

Copy link
Contributor

github-actions bot commented Dec 2, 2023

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Dec 2, 2023
hariombalhara
hariombalhara previously approved these changes Dec 8, 2023
@hariombalhara
Copy link
Member

@SomayChauhan Please resolve the conflicts, otherwise it looks good to me.

@github-actions github-actions bot removed the Stale label Dec 9, 2023
userId: userToAutoJoin.id,
teamId: team.id,
accepted: true,
role:
Copy link
Member Author

Choose a reason for hiding this comment

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

this is to handle normal non pending members

Screencast.from.10-12-23.02.09.29.PM.IST.webm

const data = [];
// membership for the team
data.push({
teamId: input.teamId,
userId: invitee.id,
role: input.role as MembershipRole,
role:
Copy link
Member Author

Choose a reason for hiding this comment

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

this is to join the pending members as their respective org role

Screencast.from.10-12-23.02.10.03.PM.IST.webm

@@ -72,6 +90,21 @@ export const updateUserHandler = async ({ ctx, input }: UpdateUserOptions) => {
}),
]);

if (input.role === MembershipRole.ADMIN || input.role === MembershipRole.OWNER) {
Copy link
Member Author

Choose a reason for hiding this comment

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

When we make someone an admin in the organization, let's also make them an admin in all the teams they're part of. But, only do this when they go from being a regular member to an admin, We don't want to accidentally strip admin privileges of this user from sub-teams if we have explicitly defined it

Screencast.from.10-12-23.02.14.02.PM.IST.webm

Comment on lines 93 to 107
if (input.role === MembershipRole.ADMIN || input.role === MembershipRole.OWNER) {
await prisma.membership.updateMany({
where: {
userId: input.userId,
teamId: {
in: requestedMember.team.children.map((sub_team) => {
return sub_team.members.find((item) => item.userId === input.userId).teamId;
}),
},
},
data: {
role: input.role,
},
});
}
Copy link
Member

Choose a reason for hiding this comment

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

How about abstracting this in a separate function applyRoleToAllTeams ? It would make the code easy to understand and testable if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely

Copy link
Member

Choose a reason for hiding this comment

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

Approved it for now and it's ready to merge. You can push it in a separate PR, would be a quick merge.

role: input.role,
})),
data: autoJoinUsers.map((userToAutoJoin) => {
const organizationRole = userToAutoJoin?.teams?.[0]?.role;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const organizationRole = userToAutoJoin?.teams?.[0]?.role;
const organizationRole = userToAutoJoin.teams?.[0]?.role;

hariombalhara
hariombalhara previously approved these changes Dec 11, 2023
Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

Great work @SomayChauhan !!

@hariombalhara
Copy link
Member

@SomayChauhan There is a type error
image

@SomayChauhan
Copy link
Member Author

@hariombalhara
Made the suggested changes.

@hariombalhara
Copy link
Member

@SomayChauhan another TS error
image

@SomayChauhan
Copy link
Member Author

SomayChauhan commented Dec 11, 2023

Apologies!!, forgot to change that one

@kodiakhq kodiakhq bot merged commit 5751f0f into calcom:main Dec 19, 2023
33 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge ✅ good first issue Good for newcomers Low priority Created by Linear-GitHub Sync organizations area: organizations, orgs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

organization - org owners and admins should show their respective badge when they join a sub-team
3 participants