Implement ingress

This commit is contained in:
fflorent
2024-09-03 23:53:25 +02:00
parent 98f50d3c81
commit c38107aadc
4 changed files with 80 additions and 14 deletions

View File

@@ -541,6 +541,10 @@ export class HomeDBManager extends EventEmitter {
return this._usersManager.deleteUser(scope, userIdToDelete, name);
}
public async overrideUser(userId: number, props: UserProfile) {
return this._usersManager.overrideUser(userId, props);
}
/**
* Returns a QueryResult for the given organization. The orgKey
* can be a string (the domain from url) or the id of an org. If it is

View File

@@ -386,7 +386,7 @@ export class UsersManager {
// Set the user's name if our provider knows it. Otherwise use their username
// from email, for lack of something better. If we don't have a profile at this
// time, then leave the name blank in the hopes of learning it when the user logs in.
user.name = (profile && (profile.name || email.split('@')[0])) || '';
user.name = (profile && this._getNameOrDeduceFromEmail(profile.name, email)) || '';
needUpdate = true;
}
if (!user.picture && profile && profile.picture) {
@@ -561,6 +561,27 @@ export class UsersManager {
.filter(fullProfile => fullProfile);
}
/**
* Update users with passed property. Optional user properties that are missing will be reset to their default value.
*/
public async overrideUser(userId: number, props: UserProfile): Promise<User> {
return await this._connection.transaction(async manager => {
const user = await this.getUser(userId, {includePrefs: true});
if (!user) { throw new ApiError("unable to find user to update", 404); }
const login = user.logins[0];
user.name = this._getNameOrDeduceFromEmail(props.name, props.email);
user.picture = props.picture || '';
user.options = {...(user.options || {}), locale: props.locale ?? undefined};
if (props.email) {
login.email = normalizeEmail(props.email);
login.displayEmail = props.email;
}
await manager.save([user, login]);
return (await this.getUser(userId))!;
});
}
/**
* ==================================
*
@@ -748,6 +769,10 @@ export class UsersManager {
return id;
}
private _getNameOrDeduceFromEmail(name: string, email: string) {
return name || email.split('@')[0];
}
// This deals with the problem posed by receiving a PermissionDelta specifying a
// role for both alice@x and Alice@x. We do not distinguish between such emails.
// If there are multiple indistinguishabe emails, we preserve just one of them,