Update to latest swaf changes on UserNameComponent
This commit is contained in:
parent
84081ccd8c
commit
14edb62823
|
@ -42,6 +42,7 @@ import AccountController from "swaf/auth/AccountController";
|
||||||
import packageJson = require('./package.json');
|
import packageJson = require('./package.json');
|
||||||
import AddUsedToMagicLinksMigration from "swaf/auth/magic_link/AddUsedToMagicLinksMigration";
|
import AddUsedToMagicLinksMigration from "swaf/auth/magic_link/AddUsedToMagicLinksMigration";
|
||||||
import MakeMagicLinksSessionNotUniqueMigration from "swaf/auth/magic_link/MakeMagicLinksSessionNotUniqueMigration";
|
import MakeMagicLinksSessionNotUniqueMigration from "swaf/auth/magic_link/MakeMagicLinksSessionNotUniqueMigration";
|
||||||
|
import AddNameChangedAtToUsersMigration from "swaf/auth/migrations/AddNameChangedAtToUsersMigration";
|
||||||
|
|
||||||
export default class App extends Application {
|
export default class App extends Application {
|
||||||
public constructor(
|
public constructor(
|
||||||
|
@ -66,6 +67,7 @@ export default class App extends Application {
|
||||||
DropLegacyLogsTable,
|
DropLegacyLogsTable,
|
||||||
AddUsedToMagicLinksMigration,
|
AddUsedToMagicLinksMigration,
|
||||||
MakeMagicLinksSessionNotUniqueMigration,
|
MakeMagicLinksSessionNotUniqueMigration,
|
||||||
|
AddNameChangedAtToUsersMigration,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,12 @@ export default class AccountMailboxController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check whether this identity can be created by this user
|
// Check whether this identity can be created by this user
|
||||||
|
if (!domain.canCreateAddresses(user)) {
|
||||||
|
throw new ForbiddenHttpError('domain', req.url);
|
||||||
|
}
|
||||||
if (domain.isPublic()) {
|
if (domain.isPublic()) {
|
||||||
await Validator.validate({
|
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);
|
}, req.body);
|
||||||
const actualPublicAddressesCount = await mailIdentityComponent.getPublicAddressesCount();
|
const actualPublicAddressesCount = await mailIdentityComponent.getPublicAddressesCount();
|
||||||
const maxPublicAddressesCount = mailIdentityComponent.getMaxPublicAddressesCount();
|
const maxPublicAddressesCount = mailIdentityComponent.getMaxPublicAddressesCount();
|
||||||
|
@ -68,10 +71,6 @@ export default class AccountMailboxController extends Controller {
|
||||||
res.redirect(Controller.route('account-mailbox'));
|
res.redirect(Controller.route('account-mailbox'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!domain.canCreateAddresses(user)) {
|
|
||||||
throw new ForbiddenHttpError('domain', req.url);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save identity
|
// Save identity
|
||||||
|
|
|
@ -59,7 +59,7 @@ export default class AccountBackendController extends Controller {
|
||||||
await user.as(UserPasswordComponent).setPassword(req.body.new_password, 'new_password');
|
await user.as(UserPasswordComponent).setPassword(req.body.new_password, 'new_password');
|
||||||
await user.save();
|
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'));
|
res.redirect(Controller.route('backend-list-users'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export default class MailboxBackendController extends Controller {
|
||||||
res.render('backend/mailboxes', {
|
res.render('backend/mailboxes', {
|
||||||
mailboxes: await Promise.all(users.map(async user => ({
|
mailboxes: await Promise.all(users.map(async user => ({
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.as(UserNameComponent).name,
|
username: user.as(UserNameComponent).getName(),
|
||||||
name: await (await user.as(UserMailIdentityComponent).mainMailIdentity.get())?.toEmail(),
|
name: await (await user.as(UserMailIdentityComponent).mainMailIdentity.get())?.toEmail(),
|
||||||
identity_count: (await user.as(UserMailIdentityComponent).mailIdentities.get()).length,
|
identity_count: (await user.as(UserMailIdentityComponent).mailIdentities.get()).length,
|
||||||
domain_count: (await user.as(UserMailIdentityComponent).mailDomains.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', {
|
res.render('backend/mailbox', {
|
||||||
mailbox: {
|
mailbox: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
userName: user.as(UserNameComponent).name,
|
userName: user.as(UserNameComponent).getName(),
|
||||||
name: await mainMailIdentity?.toEmail() || 'Not created.',
|
name: await mainMailIdentity?.toEmail() || 'Not created.',
|
||||||
exists: !!mainMailIdentity,
|
exists: !!mainMailIdentity,
|
||||||
},
|
},
|
||||||
|
@ -100,7 +100,7 @@ export default class MailboxBackendController extends Controller {
|
||||||
domains: await Promise.all(mailDomains.map(async domain => ({
|
domains: await Promise.all(mailDomains.map(async domain => ({
|
||||||
id: domain.id,
|
id: domain.id,
|
||||||
name: domain.name,
|
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,
|
identity_count: (await domain.identities.get()).length,
|
||||||
}))),
|
}))),
|
||||||
users: [{
|
users: [{
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Model from "swaf/db/Model";
|
||||||
import User from "swaf/auth/models/User";
|
import User from "swaf/auth/models/User";
|
||||||
import {ManyModelRelation, OneModelRelation} from "swaf/db/ModelRelation";
|
import {ManyModelRelation, OneModelRelation} from "swaf/db/ModelRelation";
|
||||||
import MailIdentity from "./MailIdentity";
|
import MailIdentity from "./MailIdentity";
|
||||||
|
import UserNameComponent from "swaf/auth/models/UserNameComponent";
|
||||||
|
|
||||||
export default class MailDomain extends Model {
|
export default class MailDomain extends Model {
|
||||||
public id?: number = undefined;
|
public id?: number = undefined;
|
||||||
|
@ -38,6 +39,6 @@ export default class MailDomain extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
public canCreateAddresses(user: User): boolean {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue