mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Merge pull request #5219 from Ombi-app/fix-users
fix(user-import): Do not import users that do not have access to the server
This commit is contained in:
commit
9227bc0b4c
7 changed files with 150 additions and 17 deletions
2
.github/workflows/automation-tests.yml
vendored
2
.github/workflows/automation-tests.yml
vendored
|
@ -24,7 +24,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
|
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
'**/node_modules'
|
'**/node_modules'
|
||||||
|
|
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
|
@ -15,7 +15,7 @@ jobs:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
|
|
||||||
- name: NodeModules Cache
|
- name: NodeModules Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: '**/node_modules'
|
path: '**/node_modules'
|
||||||
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
@ -42,7 +42,7 @@ jobs:
|
||||||
dotnet-version: '8.0.x'
|
dotnet-version: '8.0.x'
|
||||||
|
|
||||||
- name: Nuget Cache
|
- name: Nuget Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.nuget/packages
|
path: ~/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
|
@ -112,7 +112,7 @@ jobs:
|
||||||
dotnet-version: '5.0.x'
|
dotnet-version: '5.0.x'
|
||||||
|
|
||||||
- name: Nuget Cache
|
- name: Nuget Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.nuget/packages
|
path: ~/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
|
|
2
.github/workflows/chromatic.yml
vendored
2
.github/workflows/chromatic.yml
vendored
|
@ -17,7 +17,7 @@
|
||||||
# fetch-depth: 0
|
# fetch-depth: 0
|
||||||
|
|
||||||
# - name: NodeModules Cache
|
# - name: NodeModules Cache
|
||||||
# uses: actions/cache@v2
|
# uses: actions/cache@v4
|
||||||
# with:
|
# with:
|
||||||
# path: '**/node_modules'
|
# path: '**/node_modules'
|
||||||
# key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
# key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
|
6
.github/workflows/pr.yml
vendored
6
.github/workflows/pr.yml
vendored
|
@ -20,7 +20,7 @@ jobs:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
|
|
||||||
- name: NodeModules Cache
|
- name: NodeModules Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: '**/node_modules'
|
path: '**/node_modules'
|
||||||
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
@ -41,7 +41,7 @@ jobs:
|
||||||
dotnet-version: '8.0.x'
|
dotnet-version: '8.0.x'
|
||||||
|
|
||||||
- name: Nuget Cache
|
- name: Nuget Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.nuget/packages
|
path: ~/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
|
@ -101,7 +101,7 @@ jobs:
|
||||||
dotnet-version: '8.0.x'
|
dotnet-version: '8.0.x'
|
||||||
|
|
||||||
- name: Nuget Cache
|
- name: Nuget Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.nuget/packages
|
path: ~/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
|
|
|
@ -22,6 +22,18 @@ namespace Ombi.Api.Plex.Models.Friends
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlAttribute(AttributeName = "home")]
|
[XmlAttribute(AttributeName = "home")]
|
||||||
public bool HomeUser { get; set; }
|
public bool HomeUser { get; set; }
|
||||||
|
|
||||||
|
[XmlElement(ElementName = "Server")]
|
||||||
|
public PlexUserServer[] Server { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PlexUserServer
|
||||||
|
{
|
||||||
|
[XmlAttribute(AttributeName = "id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[XmlAttribute(AttributeName = "serverId")]
|
||||||
|
public string ServerId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[XmlRoot(ElementName = "MediaContainer")]
|
[XmlRoot(ElementName = "MediaContainer")]
|
||||||
|
|
|
@ -182,8 +182,6 @@ namespace Ombi.Schedule.Tests
|
||||||
_mocker.Verify<OmbiUserManager>(x => x.UpdateAsync(It.IsAny<OmbiUser>()), Times.Never);
|
_mocker.Verify<OmbiUserManager>(x => x.UpdateAsync(It.IsAny<OmbiUser>()), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Import_Doesnt_Import_Banned_Users()
|
public async Task Import_Doesnt_Import_Banned_Users()
|
||||||
{
|
{
|
||||||
|
@ -247,7 +245,15 @@ namespace Ombi.Schedule.Tests
|
||||||
Id = "id",
|
Id = "id",
|
||||||
Title = "title",
|
Title = "title",
|
||||||
Username = "username",
|
Username = "username",
|
||||||
HomeUser = true
|
HomeUser = true,
|
||||||
|
Server = new PlexUserServer[]
|
||||||
|
{
|
||||||
|
new PlexUserServer
|
||||||
|
{
|
||||||
|
Id = "1",
|
||||||
|
ServerId = "123"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -257,7 +263,6 @@ namespace Ombi.Schedule.Tests
|
||||||
_mocker.Setup<OmbiUserManager, Task<IdentityResult>>(x => x.AddToRoleAsync(It.Is<OmbiUser>(x => x.UserName == "plex"), OmbiRoles.RequestMovie))
|
_mocker.Setup<OmbiUserManager, Task<IdentityResult>>(x => x.AddToRoleAsync(It.Is<OmbiUser>(x => x.UserName == "plex"), OmbiRoles.RequestMovie))
|
||||||
.ReturnsAsync(IdentityResult.Success);
|
.ReturnsAsync(IdentityResult.Success);
|
||||||
|
|
||||||
|
|
||||||
await _subject.Execute(null);
|
await _subject.Execute(null);
|
||||||
|
|
||||||
_mocker.Verify<OmbiUserManager>(x => x.CreateAsync(It.IsAny<OmbiUser>()), Times.Once);
|
_mocker.Verify<OmbiUserManager>(x => x.CreateAsync(It.IsAny<OmbiUser>()), Times.Once);
|
||||||
|
@ -306,7 +311,15 @@ namespace Ombi.Schedule.Tests
|
||||||
{
|
{
|
||||||
Email = "email",
|
Email = "email",
|
||||||
Id = "id",
|
Id = "id",
|
||||||
Username = "plex"
|
Username = "plex",
|
||||||
|
Server = new PlexUserServer[]
|
||||||
|
{
|
||||||
|
new PlexUserServer
|
||||||
|
{
|
||||||
|
Id = "1",
|
||||||
|
ServerId = "123"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -331,9 +344,9 @@ namespace Ombi.Schedule.Tests
|
||||||
ImportPlexAdmin = false,
|
ImportPlexAdmin = false,
|
||||||
ImportPlexUsers = true,
|
ImportPlexUsers = true,
|
||||||
DefaultRoles = new List<string>
|
DefaultRoles = new List<string>
|
||||||
{
|
{
|
||||||
OmbiRoles.RequestMovie
|
OmbiRoles.RequestMovie
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||||
{
|
{
|
||||||
|
@ -343,7 +356,15 @@ namespace Ombi.Schedule.Tests
|
||||||
{
|
{
|
||||||
Email = "email",
|
Email = "email",
|
||||||
Id = "PLEX_ID",
|
Id = "PLEX_ID",
|
||||||
Username = "user"
|
Username = "user",
|
||||||
|
Server = new PlexUserServer[]
|
||||||
|
{
|
||||||
|
new PlexUserServer
|
||||||
|
{
|
||||||
|
Id = "1",
|
||||||
|
ServerId = "123"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -440,5 +461,98 @@ namespace Ombi.Schedule.Tests
|
||||||
|
|
||||||
_mocker.Verify<IUserDeletionEngine>(x => x.DeleteUser(It.Is<OmbiUser>(x => x.ProviderUserId == "ADMIN_ID" && x.Email == "ADMIN@ADMIN.CO" && x.UserName == "Admin")), Times.Never);
|
_mocker.Verify<IUserDeletionEngine>(x => x.DeleteUser(It.Is<OmbiUser>(x => x.ProviderUserId == "ADMIN_ID" && x.Email == "ADMIN@ADMIN.CO" && x.UserName == "Admin")), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Import_Skips_Users_Without_Server_Access()
|
||||||
|
{
|
||||||
|
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||||
|
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true });
|
||||||
|
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||||
|
{
|
||||||
|
User = new UserFriends[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Email = "email",
|
||||||
|
Id = "NoServer",
|
||||||
|
Title = "title",
|
||||||
|
Username = "username",
|
||||||
|
Server = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await _subject.Execute(null);
|
||||||
|
|
||||||
|
_mocker.Verify<OmbiUserManager>(x => x.CreateAsync(It.IsAny<OmbiUser>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Import_Skips_Users_With_Empty_Server_Array()
|
||||||
|
{
|
||||||
|
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||||
|
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true });
|
||||||
|
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||||
|
{
|
||||||
|
User = new UserFriends[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Email = "email",
|
||||||
|
Id = "EmptyServer",
|
||||||
|
Title = "title",
|
||||||
|
Username = "username",
|
||||||
|
Server = new PlexUserServer[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await _subject.Execute(null);
|
||||||
|
|
||||||
|
_mocker.Verify<OmbiUserManager>(x => x.CreateAsync(It.IsAny<OmbiUser>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Import_Creates_User_With_Server_Access()
|
||||||
|
{
|
||||||
|
_mocker.Setup<ISettingsService<UserManagementSettings>, Task<UserManagementSettings>>(x => x.GetSettingsAsync())
|
||||||
|
.ReturnsAsync(new UserManagementSettings { ImportPlexAdmin = false, ImportPlexUsers = true });
|
||||||
|
_mocker.Setup<IPlexApi, Task<PlexUsers>>(x => x.GetUsers(It.IsAny<string>())).ReturnsAsync(new PlexUsers
|
||||||
|
{
|
||||||
|
User = new UserFriends[]
|
||||||
|
{
|
||||||
|
new UserFriends
|
||||||
|
{
|
||||||
|
Email = "email",
|
||||||
|
Id = "HasServer",
|
||||||
|
Title = "title",
|
||||||
|
Username = "username",
|
||||||
|
Server = new PlexUserServer[]
|
||||||
|
{
|
||||||
|
new PlexUserServer
|
||||||
|
{
|
||||||
|
Id = "1",
|
||||||
|
ServerId = "123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_mocker.Setup<OmbiUserManager, Task<IdentityResult>>(x => x.CreateAsync(It.Is<OmbiUser>(x =>
|
||||||
|
x.UserName == "username" &&
|
||||||
|
x.Email == "email" &&
|
||||||
|
x.ProviderUserId == "HasServer" &&
|
||||||
|
x.UserType == UserType.PlexUser)))
|
||||||
|
.ReturnsAsync(IdentityResult.Success);
|
||||||
|
|
||||||
|
await _subject.Execute(null);
|
||||||
|
|
||||||
|
_mocker.Verify<OmbiUserManager>(x => x.CreateAsync(It.Is<OmbiUser>(x =>
|
||||||
|
x.UserName == "username" &&
|
||||||
|
x.Email == "email" &&
|
||||||
|
x.ProviderUserId == "HasServer" &&
|
||||||
|
x.UserType == UserType.PlexUser)), Times.Once);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,13 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
|
|
||||||
foreach (var plexUser in users.User)
|
foreach (var plexUser in users.User)
|
||||||
{
|
{
|
||||||
|
// Skip users without server access
|
||||||
|
if (plexUser.Server == null || !plexUser.Server.Any())
|
||||||
|
{
|
||||||
|
_log.LogInformation($"Skipping user {plexUser.Username ?? plexUser.Id} as they have no server access");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we should import this user
|
// Check if we should import this user
|
||||||
if (userManagementSettings.BannedPlexUserIds.Contains(plexUser.Id))
|
if (userManagementSettings.BannedPlexUserIds.Contains(plexUser.Id))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue