mirror of
https://github.com/outline/outline.git
synced 2026-12-02 17:52:07 +03:00
fix: Special case actorId for user creation from SSO signup (#9747)
This commit is contained in:
1 parent
48fcb4e1ca
commit
cdd4cc56c2
4 files changed
+41
-3
No files matched your search
@@ -115,7 +115,7 @@ class Event extends IdModel<
|
||||
|
||||
@ForeignKey(() => User)
|
||||
@Column(DataType.UUID)
|
||||
actorId: string;
|
||||
actorId: string | null;
|
||||
|
||||
@BelongsTo(() => Collection, "collectionId")
|
||||
collection: Collection | null;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { createContext } from "@server/context";
|
||||
import { Event } from "@server/models";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import {
|
||||
buildUser,
|
||||
buildTeam,
|
||||
buildCollection,
|
||||
buildAdmin,
|
||||
} from "@server/test/factories";
|
||||
import { withAPIContext } from "@server/test/support";
|
||||
import User from "./User";
|
||||
import UserMembership from "./UserMembership";
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -18,6 +21,36 @@ afterAll(() => {
|
||||
});
|
||||
|
||||
describe("user model", () => {
|
||||
describe("createWithCtx", () => {
|
||||
it("should create an event with the new user as both actorId and userId", async () => {
|
||||
const team = await buildTeam();
|
||||
const email = faker.internet.email().toLowerCase();
|
||||
const name = faker.person.fullName();
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
const user = await sequelize.transaction(async (transaction) =>
|
||||
User.createWithCtx(createContext({ ip, transaction }), {
|
||||
email,
|
||||
name,
|
||||
teamId: team.id,
|
||||
})
|
||||
);
|
||||
|
||||
const event = await Event.findOne({
|
||||
where: {
|
||||
name: "users.create",
|
||||
modelId: user.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(event).toBeDefined();
|
||||
expect(event?.actorId).toEqual(user.id);
|
||||
expect(event?.userId).toEqual(user.id);
|
||||
expect(event?.teamId).toEqual(user.teamId);
|
||||
expect(event?.ip).toEqual(ip);
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
it("should not allow URLs in name", async () => {
|
||||
await expect(
|
||||
|
||||
@@ -275,7 +275,11 @@ class Model<
|
||||
: model instanceof models.team
|
||||
? model.id
|
||||
: context.auth?.user.teamId,
|
||||
actorId: context.auth?.user?.id,
|
||||
actorId:
|
||||
(context.auth?.user?.id ??
|
||||
(model instanceof models.user && name === "create"))
|
||||
? model.id
|
||||
: undefined,
|
||||
authType: context.auth?.type,
|
||||
ip: context.ip,
|
||||
changes: model.previousChangeset,
|
||||
|
||||
@@ -33,6 +33,7 @@ router.post(
|
||||
|
||||
let where: WhereOptions<Event> = {
|
||||
teamId: user.teamId,
|
||||
actorId: { [Op.ne]: null },
|
||||
};
|
||||
|
||||
if (auditLog) {
|
||||
|
||||
Reference in new issue
Block a user