Github integration (#6414)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { IntegrationType } from "@shared/types";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
import validate from "@server/middlewares/validate";
|
||||
import { Event, IntegrationAuthentication } from "@server/models";
|
||||
import { Event } from "@server/models";
|
||||
import Integration from "@server/models/Integration";
|
||||
import { authorize } from "@server/policies";
|
||||
import { presentIntegration, presentPolicies } from "@server/presenters";
|
||||
@@ -46,16 +46,22 @@ router.post(
|
||||
],
|
||||
};
|
||||
|
||||
const integrations = await Integration.findAll({
|
||||
where,
|
||||
order: [[sort, direction]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
});
|
||||
const [integrations, total] = await Promise.all([
|
||||
await Integration.findAll({
|
||||
where,
|
||||
order: [[sort, direction]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
Integration.count({
|
||||
where,
|
||||
}),
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
pagination: { ...ctx.state.pagination, total },
|
||||
data: integrations.map(presentIntegration),
|
||||
policies: presentPolicies(user, integrations),
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -80,6 +86,7 @@ router.post(
|
||||
|
||||
ctx.body = {
|
||||
data: presentIntegration(integration),
|
||||
policies: presentPolicies(user, [integration]),
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -127,6 +134,7 @@ router.post(
|
||||
|
||||
ctx.body = {
|
||||
data: presentIntegration(integration),
|
||||
policies: presentPolicies(user, [integration]),
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -141,19 +149,13 @@ router.post(
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
|
||||
const integration = await Integration.findByPk(id, { transaction });
|
||||
const integration = await Integration.findByPk(id, {
|
||||
rejectOnEmpty: true,
|
||||
transaction,
|
||||
});
|
||||
authorize(user, "delete", integration);
|
||||
|
||||
await integration.destroy({ transaction });
|
||||
// also remove the corresponding authentication if it exists
|
||||
if (integration.authenticationId) {
|
||||
await IntegrationAuthentication.destroy({
|
||||
where: {
|
||||
id: integration.authenticationId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
await Event.create(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user