Skip to content

Commit

Permalink
fix(Webhooks): account association
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Oct 24, 2024
1 parent 2a96d5b commit 8ddeaa2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
40 changes: 40 additions & 0 deletions migrations/20241024103852-remove-invalid-webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
const webhooks = await queryInterface.sequelize.query(
`
DELETE FROM "Notifications"
WHERE channel = 'webhook'
AND "CollectiveId" IS NULL
RETURNING *
`,
{
type: queryInterface.sequelize.QueryTypes.SELECT,
},
);

await queryInterface.sequelize.query(
`
INSERT INTO "MigrationLogs"
("createdAt", "type", "description", "CreatedByUserId", "data")
VALUES (
NOW(),
'MIGRATION',
'migrations/20241024103852-remove-invalid-webhooks',
NULL,
:data
)
`,
{
replacements: { data: JSON.stringify(webhooks) },
type: queryInterface.sequelize.QueryTypes.INSERT,
},
);
},

async down() {
console.log(`No restore for this migration, look at the migration log for the deleted webhooks`);
},
};
2 changes: 1 addition & 1 deletion server/graphql/v2/mutation/WebhookMutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const createWebhook = {
type: args.webhook.activityType,
webhookUrl: args.webhook.webhookUrl,
UserId: req.remoteUser.id,
CollectiveId: account.CollectiveId,
CollectiveId: account.id,
};

return models.Notification.create(createParams);
Expand Down
4 changes: 3 additions & 1 deletion server/graphql/v2/object/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const GraphQLWebhook = new GraphQLObjectType({
account: {
type: new GraphQLNonNull(GraphQLAccount),
resolve(notification, args, req) {
return req.loaders.Collective.byId.load(notification.CollectiveId);
if (notification.CollectiveId) {
return req.loaders.Collective.byId.load(notification.CollectiveId);
}
},
},
}),
Expand Down

0 comments on commit 8ddeaa2

Please sign in to comment.