mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
remove url from custom emoji record
This commit is contained in:
1 parent
cf918e45a5
commit
af7e932c56
7 files changed
+48
-20
No files matched your search
@@ -64,7 +64,7 @@ export function EmojiCreateDialog({ onSubmit }: Props) {
|
||||
|
||||
const emoji = await emojis.create({
|
||||
name: name.trim(),
|
||||
url: attachment.url,
|
||||
attachmentId: attachment.id,
|
||||
});
|
||||
|
||||
emojis.add(emoji);
|
||||
|
||||
@@ -17,6 +17,11 @@ class Emoji extends Model {
|
||||
@observable
|
||||
url: string;
|
||||
|
||||
/** The ID */
|
||||
@Field
|
||||
@observable
|
||||
attachmentId: string;
|
||||
|
||||
/** The user who created this emoji */
|
||||
@Relation(() => User)
|
||||
@observable
|
||||
|
||||
@@ -16,9 +16,14 @@ module.exports = {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
url: {
|
||||
type: Sequelize.STRING,
|
||||
attachmentId: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: "attachments",
|
||||
key: "id",
|
||||
},
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
teamId: {
|
||||
type: Sequelize.UUID,
|
||||
@@ -52,6 +57,9 @@ module.exports = {
|
||||
|
||||
await queryInterface.addIndex("emojis", ["teamId"], { transaction });
|
||||
await queryInterface.addIndex("emojis", ["createdById"], { transaction });
|
||||
await queryInterface.addIndex("emojis", ["attachmentId"], {
|
||||
transaction,
|
||||
});
|
||||
await queryInterface.addIndex("emojis", ["teamId", "name"], {
|
||||
unique: true,
|
||||
transaction,
|
||||
|
||||
+9
-12
@@ -18,7 +18,6 @@ import Team from "./Team";
|
||||
import User from "./User";
|
||||
import IdModel from "./base/IdModel";
|
||||
import Fix from "./decorators/Fix";
|
||||
import IsUrlOrRelativePath from "./validators/IsUrlOrRelativePath";
|
||||
import Length from "./validators/Length";
|
||||
import { Matches } from "class-validator";
|
||||
import FileStorage from "@server/storage/files";
|
||||
@@ -32,7 +31,7 @@ class Emoji extends IdModel<
|
||||
> {
|
||||
@Length({
|
||||
max: EmojiValidation.maxNameLength,
|
||||
msg: `emoji name must be less than ${EmojiValidation.maxNameLength} characters`,
|
||||
msg: `emoji name must be less than ${EmojiValidation.maxNameLength} characters`,
|
||||
})
|
||||
@Matches(EmojiValidation.allowedNameCharacters, {
|
||||
message:
|
||||
@@ -41,11 +40,14 @@ class Emoji extends IdModel<
|
||||
@Column(DataType.STRING)
|
||||
name: string;
|
||||
|
||||
@IsUrlOrRelativePath
|
||||
@Column(DataType.STRING)
|
||||
url: string;
|
||||
|
||||
// associations
|
||||
@BelongsTo(() => Attachment, "attachmentId")
|
||||
attachment: Attachment;
|
||||
|
||||
@ForeignKey(() => Attachment)
|
||||
@Column(DataType.UUID)
|
||||
attachmentId: string;
|
||||
|
||||
@BelongsTo(() => Team, "teamId")
|
||||
team: Team;
|
||||
|
||||
@@ -81,12 +83,7 @@ class Emoji extends IdModel<
|
||||
|
||||
@BeforeDestroy
|
||||
static async deleteAttachmentFromS3(model: Emoji) {
|
||||
const attachment = await Attachment.findOne({
|
||||
where: {
|
||||
key: model.url,
|
||||
},
|
||||
});
|
||||
|
||||
const attachment = await Attachment.findByPk(model.attachmentId);
|
||||
if (attachment) {
|
||||
await FileStorage.deleteFile(attachment.key);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ export default function present(emoji: Emoji) {
|
||||
return {
|
||||
id: emoji.id,
|
||||
name: emoji.name,
|
||||
url: emoji.url,
|
||||
teamId: emoji.teamId,
|
||||
url: emoji.attachment?.url,
|
||||
createdBy: emoji.createdBy ? presentUser(emoji.createdBy) : undefined,
|
||||
createdById: emoji.createdById,
|
||||
createdAt: emoji.createdAt,
|
||||
|
||||
@@ -4,7 +4,7 @@ import auth from "@server/middlewares/authentication";
|
||||
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
||||
import { transaction } from "@server/middlewares/transaction";
|
||||
import validate from "@server/middlewares/validate";
|
||||
import { Emoji, User } from "@server/models";
|
||||
import { Emoji, User, Attachment } from "@server/models";
|
||||
import { authorize } from "@server/policies";
|
||||
import { presentEmoji, presentPolicies } from "@server/presenters";
|
||||
import { APIContext } from "@server/types";
|
||||
@@ -28,6 +28,11 @@ router.post(
|
||||
as: "createdBy",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
model: Attachment,
|
||||
as: "attachment",
|
||||
paranoid: false,
|
||||
},
|
||||
];
|
||||
|
||||
let emoji;
|
||||
@@ -87,6 +92,11 @@ router.post(
|
||||
as: "createdBy",
|
||||
paranoid: false,
|
||||
},
|
||||
{
|
||||
model: Attachment,
|
||||
as: "attachment",
|
||||
paranoid: false,
|
||||
},
|
||||
],
|
||||
order: [["createdAt", "DESC"]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
@@ -112,17 +122,25 @@ router.post(
|
||||
validate(T.EmojisCreateSchema),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.EmojisCreateReq>) => {
|
||||
const { name, url } = ctx.input.body;
|
||||
const { name, attachmentId } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
|
||||
const attachment = await Attachment.findByPk(attachmentId, {
|
||||
transaction,
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
authorize(user, "read", attachment);
|
||||
|
||||
const emoji = await Emoji.createWithCtx(ctx, {
|
||||
name,
|
||||
url,
|
||||
attachmentId,
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
createdBy: user,
|
||||
});
|
||||
emoji.createdBy = user;
|
||||
emoji.attachment = attachment;
|
||||
|
||||
ctx.body = {
|
||||
data: presentEmoji(emoji),
|
||||
|
||||
@@ -27,7 +27,7 @@ export const EmojisCreateSchema = BaseSchema.extend({
|
||||
/** Name/shortcode for the emoji (e.g., "awesome") */
|
||||
name: z.string().min(1).max(EmojiValidation.maxNameLength),
|
||||
/** URL to the emoji image */
|
||||
url: z.string(),
|
||||
attachmentId: z.string().uuid(),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user