Backend/MailDomain: allow setting domain owner to public

This commit is contained in:
Alice Gaudon 2020-07-30 11:14:35 +02:00
parent 4dede38da4
commit 21e327251a
2 changed files with 3 additions and 2 deletions

View File

@ -128,7 +128,7 @@ export default class MailboxBackendController extends Controller {
.first();
if (!domain) throw new NotFoundHttpError('Domain', req.url);
domain.user_id = req.body.user_id;
domain.updateWithData(req.body);
await domain.save();
req.flash('success', `Domain ${domain.name} updated successfully.`);

View File

@ -28,7 +28,8 @@ export default class MailDomain extends Model {
}
protected init(): void {
this.setValidation('name').defined().maxLength(252)
this.setValidation('name').acceptUndefined()
.maxLength(252)
.regexp(/^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/)
.unique(this);
this.setValidation('user_id').acceptUndefined().exists(User, 'id');