Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const REJECTION_REASON_RAW = " we dont support your usecase ";

vi.mock("@calcom/features/oauth/repositories/OAuthClientRepository", () => ({
OAuthClientRepository: class {
constructor() {}
constructor() { }
findByClientId = mocks.findByClientId;
findByClientIdIncludeUser = mocks.findByClientIdIncludeUser;
},
Expand Down Expand Up @@ -487,4 +487,62 @@ describe("updateClientHandler", () => {
})
);
});

it("sets status to PENDING when an owner updates a field of a REJECTED client", async () => {
mocks.findByClientIdIncludeUser.mockResolvedValue({
clientId: CLIENT_ID,
userId: OWNER_USER_ID,
name: CLIENT_NAME,
purpose: CLIENT_PURPOSE,
redirectUri: REDIRECT_URI,
websiteUrl: null,
logo: null,
status: "REJECTED",
user: null,
});

const newPurpose = "Updated purpose to fix rejection issues";

const prismaUpdate = vi.fn().mockResolvedValue({
clientId: CLIENT_ID,
name: CLIENT_NAME,
purpose: newPurpose,
status: "PENDING",
redirectUri: REDIRECT_URI,
websiteUrl: null,
logo: null,
rejectionReason: null,
});

const ctx = {
user: {
id: OWNER_USER_ID,
role: UserPermissionRole.USER,
},
prisma: {
oAuthClient: {
update: prismaUpdate,
},
} as unknown as PrismaClient,
};

await updateClientHandler({
ctx,
input: {
clientId: CLIENT_ID,
purpose: newPurpose,
},
});

expect(prismaUpdate).toHaveBeenCalledWith(
expect.objectContaining({
where: { clientId: CLIENT_ID },
data: {
purpose: newPurpose,
status: "PENDING",
rejectionReason: null,
},
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const updateClientHandler = async ({
requestedStatus,
triggersReapprovalForOwnerEdit: shouldTriggerReapprovalForOwnerEdit,
currentStatus: clientWithUser.status,
isOwnerUpdatingFields: isUpdatingFields && isOwner && !isAdmin,
});

const updateData = buildUpdateClientUpdateData({
Expand Down Expand Up @@ -188,7 +189,7 @@ function triggersReapprovalForOwnerEdit(params: {
) {
return true;
}

if (
proposedUpdates.websiteUrl !== undefined &&
toNullableString(proposedUpdates.websiteUrl) !== toNullableString(currentClient.websiteUrl)
Expand All @@ -207,10 +208,12 @@ function computeNextStatus(params: {
requestedStatus: OAuthClientStatus | undefined;
triggersReapprovalForOwnerEdit: boolean;
currentStatus: OAuthClientStatus;
isOwnerUpdatingFields: boolean;
}): OAuthClientStatus {
const { requestedStatus, triggersReapprovalForOwnerEdit, currentStatus } = params;
const { requestedStatus, triggersReapprovalForOwnerEdit, currentStatus, isOwnerUpdatingFields } = params;
if (requestedStatus !== undefined) return requestedStatus;
if (triggersReapprovalForOwnerEdit) return "PENDING";
if (currentStatus === "REJECTED" && isOwnerUpdatingFields) return "PENDING";
return currentStatus;
}

Expand Down
Loading