Update to latest swaf changes on UserNameComponent

This commit is contained in:
Alice Gaudon 2021-03-31 15:39:02 +02:00
parent 84081ccd8c
commit 14edb62823
5 changed files with 12 additions and 10 deletions

View File

@ -42,6 +42,7 @@ import AccountController from "swaf/auth/AccountController";
import packageJson = require('./package.json');
import AddUsedToMagicLinksMigration from "swaf/auth/magic_link/AddUsedToMagicLinksMigration";
import MakeMagicLinksSessionNotUniqueMigration from "swaf/auth/magic_link/MakeMagicLinksSessionNotUniqueMigration";
import AddNameChangedAtToUsersMigration from "swaf/auth/migrations/AddNameChangedAtToUsersMigration";
export default class App extends Application {
public constructor(
@ -66,6 +67,7 @@ export default class App extends Application {
DropLegacyLogsTable,
AddUsedToMagicLinksMigration,
MakeMagicLinksSessionNotUniqueMigration,
AddNameChangedAtToUsersMigration,
];
}

View File

@ -57,9 +57,12 @@ export default class AccountMailboxController extends Controller {
});
// Check whether this identity can be created by this user
if (!domain.canCreateAddresses(user)) {
throw new ForbiddenHttpError('domain', req.url);
}
if (domain.isPublic()) {
await Validator.validate({
name: new Validator<string>().defined().equals(user.as(UserNameComponent).name),
name: new Validator<string>().defined().equals(user.as(UserNameComponent).getName()),
}, req.body);
const actualPublicAddressesCount = await mailIdentityComponent.getPublicAddressesCount();
const maxPublicAddressesCount = mailIdentityComponent.getMaxPublicAddressesCount();
@ -68,10 +71,6 @@ export default class AccountMailboxController extends Controller {
res.redirect(Controller.route('account-mailbox'));
return;
}
} else {
if (!domain.canCreateAddresses(user)) {
throw new ForbiddenHttpError('domain', req.url);
}
}
// Save identity

View File

@ -59,7 +59,7 @@ export default class AccountBackendController extends Controller {
await user.as(UserPasswordComponent).setPassword(req.body.new_password, 'new_password');
await user.save();
req.flash('success', `New password set for ${user.as(UserNameComponent).name}`);
req.flash('success', `New password set for ${user.as(UserNameComponent).getName()}`);
res.redirect(Controller.route('backend-list-users'));
}
}

View File

@ -54,7 +54,7 @@ export default class MailboxBackendController extends Controller {
res.render('backend/mailboxes', {
mailboxes: await Promise.all(users.map(async user => ({
id: user.id,
username: user.as(UserNameComponent).name,
username: user.as(UserNameComponent).getName(),
name: await (await user.as(UserMailIdentityComponent).mainMailIdentity.get())?.toEmail(),
identity_count: (await user.as(UserMailIdentityComponent).mailIdentities.get()).length,
domain_count: (await user.as(UserMailIdentityComponent).mailDomains.get()).length,
@ -75,7 +75,7 @@ export default class MailboxBackendController extends Controller {
res.render('backend/mailbox', {
mailbox: {
id: user.id,
userName: user.as(UserNameComponent).name,
userName: user.as(UserNameComponent).getName(),
name: await mainMailIdentity?.toEmail() || 'Not created.',
exists: !!mainMailIdentity,
},
@ -100,7 +100,7 @@ export default class MailboxBackendController extends Controller {
domains: await Promise.all(mailDomains.map(async domain => ({
id: domain.id,
name: domain.name,
owner_name: (await domain.owner.get())?.as(UserNameComponent).name,
owner_name: (await domain.owner.get())?.as(UserNameComponent).getName(),
identity_count: (await domain.identities.get()).length,
}))),
users: [{

View File

@ -2,6 +2,7 @@ import Model from "swaf/db/Model";
import User from "swaf/auth/models/User";
import {ManyModelRelation, OneModelRelation} from "swaf/db/ModelRelation";
import MailIdentity from "./MailIdentity";
import UserNameComponent from "swaf/auth/models/UserNameComponent";
export default class MailDomain extends Model {
public id?: number = undefined;
@ -38,6 +39,6 @@ export default class MailDomain extends Model {
}
public canCreateAddresses(user: User): boolean {
return this.user_id === user.id || this.isPublic();
return this.user_id === user.id || this.isPublic() && user.as(UserNameComponent).hasName();
}
}