fix(plex): do not fail to import Plex users when Plex Home has managed users (#1699)

* fix(plex): do not fail to import Plex users when Plex Home has managed users

* fix: default display name to email when user has no username

also, do not set username or plexUsername when it is the same as the user's email address

* fix(ui): user display name placeholder should reflect fallback logic if username is not set

* fix(ui): hide email addresses of other users if logged-in user does not have Manage Users permission

* fix: always set Plex username even if same as user's email

* fix: remove unnecessary permission check

* fix: transform email addresses to lowercase
This commit is contained in:
TheCatLady
2021-05-30 19:38:52 -04:00
committed by GitHub
parent 6603dffe95
commit 310cdb36df
7 changed files with 68 additions and 61 deletions

View File

@@ -43,7 +43,7 @@ authRoutes.post('/plex', async (req, res, next) => {
let user = await userRepository
.createQueryBuilder('user')
.where('user.plexId = :id', { id: account.id })
.orWhere('LOWER(user.email) = :email', {
.orWhere('user.email = :email', {
email: account.email.toLowerCase(),
})
.getOne();
@@ -65,9 +65,6 @@ authRoutes.post('/plex', async (req, res, next) => {
user.plexId = account.id;
}
if (user.username === account.username) {
user.username = '';
}
await userRepository.save(user);
} else {
// Here we check if it's the first user. If it is, we create the user with no check
@@ -177,7 +174,7 @@ authRoutes.post('/local', async (req, res, next) => {
const user = await userRepository
.createQueryBuilder('user')
.select(['user.id', 'user.password'])
.where('LOWER(user.email) = :email', { email: body.email.toLowerCase() })
.where('user.email = :email', { email: body.email.toLowerCase() })
.getOne();
const isCorrectCredentials = await user?.passwordMatch(body.password);
@@ -244,7 +241,7 @@ authRoutes.post('/reset-password', async (req, res) => {
const user = await userRepository
.createQueryBuilder('user')
.where('LOWER(user.email) = :email', { email: body.email.toLowerCase() })
.where('user.email = :email', { email: body.email.toLowerCase() })
.getOne();
if (user) {