* refactor: migrate MembershipRole usages to PBAC permission checks - Refactor get.handler.ts to use PermissionCheckService for canUpdateTeams - Refactor checkForInvalidAppCredentials.ts to use getTeamIdsWithPermission - Refactor outOfOffice.utils.ts to use checkPermission for ooo.update - Refactor checkIfOrgNeedsUpgrade.handler.ts to use organization.manageBilling - Refactor getActiveOnOptions.handler.ts to use eventType.update permission - Refactor WorkflowRepository.ts to use workflow.update permission - Refactor organization.tsx to use team.update permission - Refactor getEventTypesByViewer.ts to use eventType.update permission - Refactor getPublicEvent.ts to use team.read permission for private teams - Update CreateNewOutOfOfficeEntryButton.tsx to use canUpdateOOO prop Co-Authored-By: sean@cal.com <Sean@brydon.io> * fix: use organization.update permission instead of team.update for org management Co-Authored-By: sean@cal.com <Sean@brydon.io> * fix: rename teamsWithEventTypeManagePermission to teamsWithEventTypeUpdatePermission Renamed variable to match the permission string being used (eventType.update) Co-Authored-By: sean@cal.com <Sean@brydon.io> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { getAppFromSlug } from "@calcom/app-store/utils";
|
|
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
|
|
import { type InvalidAppCredentialBannerProps } from "@calcom/features/users/types/invalidAppCredentials";
|
|
import { prisma } from "@calcom/prisma";
|
|
import { MembershipRole } from "@calcom/prisma/enums";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
type checkInvalidAppCredentialsOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
};
|
|
|
|
export const checkInvalidAppCredentials = async ({ ctx }: checkInvalidAppCredentialsOptions) => {
|
|
const userId = ctx.user.id;
|
|
|
|
const permissionCheckService = new PermissionCheckService();
|
|
const userTeamIds = await permissionCheckService.getTeamIdsWithPermission({
|
|
userId,
|
|
permission: "team.update",
|
|
fallbackRoles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
|
});
|
|
|
|
const apps = await prisma.credential.findMany({
|
|
where: {
|
|
OR: [{ userId }, { teamId: { in: userTeamIds } }],
|
|
invalid: true,
|
|
},
|
|
select: {
|
|
appId: true,
|
|
},
|
|
});
|
|
|
|
const appNamesAndSlugs: InvalidAppCredentialBannerProps[] = [];
|
|
for (const app of apps) {
|
|
if (app.appId) {
|
|
const appId = app.appId;
|
|
const appMeta = await getAppFromSlug(appId);
|
|
const name = appMeta ? appMeta.name : appId;
|
|
appNamesAndSlugs.push({ slug: appId, name });
|
|
}
|
|
}
|
|
|
|
return appNamesAndSlugs;
|
|
};
|