mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66ae221aae | |||
| 2b8f6752c0 |
@@ -1,42 +0,0 @@
|
||||
import type { Transaction } from "sequelize";
|
||||
import { Event, Group, type User } from "@server/models";
|
||||
|
||||
type Props = {
|
||||
name: string;
|
||||
externalId: string | undefined;
|
||||
actor: User;
|
||||
ip: string;
|
||||
transaction?: Transaction;
|
||||
};
|
||||
|
||||
export default async function groupCreator({
|
||||
name,
|
||||
externalId,
|
||||
actor,
|
||||
ip,
|
||||
transaction,
|
||||
}: Props): Promise<Group> {
|
||||
const group = await Group.create(
|
||||
{
|
||||
name,
|
||||
externalId,
|
||||
teamId: actor.teamId,
|
||||
createdById: actor.id,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
await Event.create(
|
||||
{
|
||||
name: "groups.create",
|
||||
modelId: group.id,
|
||||
teamId: actor.teamId,
|
||||
actorId: actor.id,
|
||||
data: {
|
||||
name: group.name,
|
||||
},
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
return group;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { Transaction } from "sequelize";
|
||||
import { Event, type Group, type User } from "@server/models";
|
||||
|
||||
type Props = {
|
||||
group: Group;
|
||||
actor: User;
|
||||
ip: string;
|
||||
transaction?: Transaction;
|
||||
};
|
||||
|
||||
export default async function groupDestroyer({
|
||||
group,
|
||||
actor,
|
||||
ip,
|
||||
transaction,
|
||||
}: Props): Promise<void> {
|
||||
await group.destroy({ transaction });
|
||||
await Event.create(
|
||||
{
|
||||
name: "groups.delete",
|
||||
modelId: group.id,
|
||||
teamId: actor.teamId,
|
||||
actorId: actor.id,
|
||||
data: {
|
||||
name: group.name,
|
||||
},
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
import type { Transaction } from "sequelize";
|
||||
import { Event, type Group, type User } from "@server/models";
|
||||
|
||||
type Props = {
|
||||
group: Group;
|
||||
name: string | undefined;
|
||||
externalId: string | undefined;
|
||||
actor: User;
|
||||
ip: string;
|
||||
transaction?: Transaction;
|
||||
};
|
||||
|
||||
export default async function groupUpdater({
|
||||
group,
|
||||
name,
|
||||
externalId,
|
||||
actor,
|
||||
ip,
|
||||
transaction,
|
||||
}: Props): Promise<Group> {
|
||||
if (name) {
|
||||
group.name = name;
|
||||
}
|
||||
if (externalId) {
|
||||
group.externalId = externalId;
|
||||
}
|
||||
|
||||
if (group.changed()) {
|
||||
await group.save({ transaction });
|
||||
await Event.create(
|
||||
{
|
||||
name: "groups.update",
|
||||
modelId: group.id,
|
||||
teamId: actor.teamId,
|
||||
actorId: actor.id,
|
||||
data: {
|
||||
name: group.name,
|
||||
},
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
@@ -60,6 +60,8 @@ class Group extends ParanoidModel<
|
||||
InferAttributes<Group>,
|
||||
Partial<InferCreationAttributes<Group>>
|
||||
> {
|
||||
static eventNamespace = "groups";
|
||||
|
||||
@Length({ min: 0, max: 255, msg: "name must be be 255 characters or less" })
|
||||
@NotContainsUrl
|
||||
@Column
|
||||
|
||||
@@ -81,6 +81,7 @@ describe("#groups.update", () => {
|
||||
});
|
||||
const events = await Event.findAll({
|
||||
where: {
|
||||
name: "groups.update",
|
||||
teamId: user.teamId,
|
||||
},
|
||||
});
|
||||
@@ -101,6 +102,7 @@ describe("#groups.update", () => {
|
||||
});
|
||||
const events = await Event.findAll({
|
||||
where: {
|
||||
name: "groups.update",
|
||||
teamId: user.teamId,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import Router from "koa-router";
|
||||
import { Op, WhereOptions } from "sequelize";
|
||||
import { MAX_AVATAR_DISPLAY } from "@shared/constants";
|
||||
import groupCreator from "@server/commands/groupCreator";
|
||||
import groupDestroyer from "@server/commands/groupDestroyer";
|
||||
import groupUpdater from "@server/commands/groupUpdater";
|
||||
import groupUserCreator from "@server/commands/groupUserCreator";
|
||||
import groupUserDestroyer from "@server/commands/groupUserDestroyer";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
@@ -128,15 +125,13 @@ router.post(
|
||||
async (ctx: APIContext<T.GroupsCreateReq>) => {
|
||||
const { name, externalId } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
authorize(user, "createGroup", user.team);
|
||||
|
||||
const group = await groupCreator({
|
||||
const group = await Group.createWithCtx(ctx, {
|
||||
name,
|
||||
externalId,
|
||||
actor: user,
|
||||
ip: ctx.request.ip,
|
||||
transaction,
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
@@ -152,21 +147,17 @@ router.post(
|
||||
validate(T.GroupsUpdateSchema),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.GroupsUpdateReq>) => {
|
||||
const { id, name, externalId } = ctx.input.body;
|
||||
const { id } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
|
||||
let group = await Group.findByPk(id, { transaction });
|
||||
const group = await Group.findByPk(id, {
|
||||
transaction,
|
||||
lock: transaction.LOCK.UPDATE,
|
||||
});
|
||||
authorize(user, "update", group);
|
||||
|
||||
group = await groupUpdater({
|
||||
group,
|
||||
name,
|
||||
externalId,
|
||||
actor: user,
|
||||
ip: ctx.request.ip,
|
||||
transaction,
|
||||
});
|
||||
await group.updateWithCtx(ctx, ctx.input.body);
|
||||
|
||||
ctx.body = {
|
||||
data: await presentGroup(group),
|
||||
@@ -185,15 +176,13 @@ router.post(
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
|
||||
const group = await Group.findByPk(id, { transaction });
|
||||
const group = await Group.findByPk(id, {
|
||||
transaction,
|
||||
lock: transaction.LOCK.UPDATE,
|
||||
});
|
||||
authorize(user, "delete", group);
|
||||
|
||||
await groupDestroyer({
|
||||
group,
|
||||
actor: user,
|
||||
ip: ctx.request.ip,
|
||||
transaction,
|
||||
});
|
||||
await group.destroyWithCtx(ctx);
|
||||
|
||||
ctx.body = {
|
||||
success: true,
|
||||
|
||||
@@ -354,9 +354,6 @@ export type GroupEvent = BaseEvent<Group> &
|
||||
| {
|
||||
name: "groups.create" | "groups.delete" | "groups.update";
|
||||
modelId: string;
|
||||
data: {
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user