Prevent the creation of files where slugs are already taken by URLs

This commit is contained in:
Alice Gaudon 2020-07-06 11:05:04 +02:00
parent 9b5a0b2824
commit e911089c97
1 changed files with 2 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import Controller from "wms-core/Controller";
import config from "config";
import User from "wms-core/auth/models/User";
import {Request} from "express";
import URLRedirect from "./URLRedirect";
export default class FileModel extends Model {
public static get table(): string {
@ -29,7 +30,7 @@ export default class FileModel extends Model {
protected init() {
this.addProperty('user_id', new Validator().defined().exists(User, 'id'));
this.addProperty('slug', new Validator().defined().minLength(1).maxLength(259).unique(this, 'slug'));
this.addProperty('slug', new Validator().defined().minLength(1).maxLength(259).unique(FileModel, 'slug').unique(URLRedirect, 'slug'));
this.addProperty('real_name', new Validator().defined().minLength(1).maxLength(259));
this.addProperty('storage_type', new Validator().defined().maxLength(64));
this.addProperty('storage_path', new Validator().defined().maxLength(1745));