-
Notifications
You must be signed in to change notification settings - Fork 110
Feat: Admin configuration UI #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JW-CH
wants to merge
2
commits into
main
Choose a base branch
from
admin_ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
ImmichFrame.Core.Tests/Logic/ReloadingImmichFrameLogicTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| using ImmichFrame.Core.Interfaces; | ||
| using ImmichFrame.Core.Logic; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using Moq; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace ImmichFrame.Core.Tests.Logic; | ||
|
|
||
| [TestFixture] | ||
| public class ReloadingImmichFrameLogicTests | ||
| { | ||
| private class FakeSettingsProvider : ISettingsProvider | ||
| { | ||
| public IServerSettings Current { get; set; } = Mock.Of<IServerSettings>(); | ||
| public event EventHandler<SettingsChangedEventArgs>? SettingsChanged; | ||
|
|
||
| public void Raise(bool accountsChanged) => SettingsChanged?.Invoke(this, new SettingsChangedEventArgs | ||
| { | ||
| NewSettings = Current, | ||
| AccountsChanged = accountsChanged, | ||
| GeneralChanged = true | ||
| }); | ||
| } | ||
|
|
||
| private class DisposableLogicMock : Mock<IImmichFrameLogic> | ||
| { | ||
| public DisposableLogicMock() : base(MockBehavior.Loose) | ||
| { | ||
| As<IDisposable>(); | ||
| } | ||
|
|
||
| public bool IsDisposed | ||
| { | ||
| get | ||
| { | ||
| try | ||
| { | ||
| As<IDisposable>().Verify(d => d.Dispose(), Times.AtLeastOnce); | ||
| return true; | ||
| } | ||
| catch (MockException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private FakeSettingsProvider _provider; | ||
| private List<DisposableLogicMock> _created; | ||
| private ReloadingImmichFrameLogic _logic; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| _provider = new FakeSettingsProvider(); | ||
| _created = new List<DisposableLogicMock>(); | ||
| _logic = new ReloadingImmichFrameLogic(_provider, () => | ||
| { | ||
| var mock = new DisposableLogicMock(); | ||
| _created.Add(mock); | ||
| return mock.Object; | ||
| }, NullLogger<ReloadingImmichFrameLogic>.Instance, disposeGraceDelay: TimeSpan.Zero); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() => _logic.Dispose(); | ||
|
|
||
| [Test] | ||
| public void Constructor_BuildsInnerOnce() | ||
| { | ||
| Assert.That(_created, Has.Count.EqualTo(1)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task AccountsChanged_SwapsInnerAndDisposesOld() | ||
| { | ||
| _provider.Raise(accountsChanged: true); | ||
|
|
||
| Assert.That(_created, Has.Count.EqualTo(2)); | ||
|
|
||
| await _logic.GetTotalAssets(); | ||
| _created[0].Verify(l => l.GetTotalAssets(), Times.Never); | ||
| _created[1].Verify(l => l.GetTotalAssets(), Times.Once); | ||
|
|
||
| // Old instance is disposed after the (zero) grace delay | ||
| await WaitUntil(() => _created[0].IsDisposed); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task GeneralOnlyChange_KeepsInner() | ||
| { | ||
| _provider.Raise(accountsChanged: false); | ||
|
|
||
| Assert.That(_created, Has.Count.EqualTo(1)); | ||
| await _logic.GetTotalAssets(); | ||
| _created[0].Verify(l => l.GetTotalAssets(), Times.Once); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Dispose_DisposesCurrentInnerAndUnsubscribes() | ||
| { | ||
| _logic.Dispose(); | ||
|
|
||
| Assert.That(_created[0].IsDisposed, Is.True); | ||
|
|
||
| // Raising after dispose must not rebuild | ||
| _provider.Raise(accountsChanged: true); | ||
| Assert.That(_created, Has.Count.EqualTo(1)); | ||
| } | ||
|
|
||
| private static async Task WaitUntil(Func<bool> condition, int timeoutMs = 2000) | ||
| { | ||
| var start = DateTime.UtcNow; | ||
| while (!condition()) | ||
| { | ||
| if ((DateTime.UtcNow - start).TotalMilliseconds > timeoutMs) | ||
| { | ||
| Assert.Fail("Condition was not met in time"); | ||
| } | ||
|
|
||
| await Task.Delay(10); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| namespace ImmichFrame.Core.Interfaces | ||
| { | ||
| public interface ISettingsProvider | ||
| { | ||
| IServerSettings Current { get; } | ||
| event EventHandler<SettingsChangedEventArgs>? SettingsChanged; | ||
| } | ||
|
|
||
| public class SettingsChangedEventArgs : EventArgs | ||
| { | ||
| public required IServerSettings NewSettings { get; init; } | ||
| // Accounts list changed or RefreshAlbumPeopleInterval changed — the account | ||
| // logic graph (pools, caches) must be rebuilt for these to take effect. | ||
| public bool AccountsChanged { get; init; } | ||
| public bool GeneralChanged { get; init; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| using ImmichFrame.Core.Api; | ||
| using ImmichFrame.Core.Interfaces; | ||
| using ImmichFrame.Core.Models; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace ImmichFrame.Core.Logic; | ||
|
|
||
| /// <summary> | ||
| /// Delegates to an inner <see cref="IImmichFrameLogic"/> that is rebuilt whenever the | ||
| /// account settings change, so account changes apply without a restart. The previous | ||
| /// instance is disposed after a grace delay to let in-flight requests finish. | ||
| /// </summary> | ||
| public class ReloadingImmichFrameLogic : IImmichFrameLogic, IDisposable | ||
| { | ||
| private static readonly TimeSpan DefaultDisposeGraceDelay = TimeSpan.FromSeconds(60); | ||
|
|
||
| private readonly Func<IImmichFrameLogic> _innerFactory; | ||
| private readonly ISettingsProvider _settingsProvider; | ||
| private readonly ILogger<ReloadingImmichFrameLogic> _logger; | ||
| private readonly TimeSpan _disposeGraceDelay; | ||
| private readonly object _swapLock = new(); | ||
| private volatile IImmichFrameLogic _inner; | ||
| private bool _disposed; | ||
|
|
||
| public ReloadingImmichFrameLogic(ISettingsProvider settingsProvider, Func<IImmichFrameLogic> innerFactory, | ||
| ILogger<ReloadingImmichFrameLogic> logger, TimeSpan? disposeGraceDelay = null) | ||
| { | ||
| _settingsProvider = settingsProvider; | ||
| _innerFactory = innerFactory; | ||
| _logger = logger; | ||
| _disposeGraceDelay = disposeGraceDelay ?? DefaultDisposeGraceDelay; | ||
| _inner = innerFactory(); | ||
| _settingsProvider.SettingsChanged += OnSettingsChanged; | ||
| } | ||
|
|
||
| private void OnSettingsChanged(object? sender, SettingsChangedEventArgs args) | ||
| { | ||
| if (!args.AccountsChanged) | ||
| return; | ||
|
|
||
| IImmichFrameLogic? old; | ||
| lock (_swapLock) | ||
| { | ||
| if (_disposed) | ||
| return; | ||
|
|
||
| _logger.LogInformation("Account settings changed, rebuilding asset logic"); | ||
| old = Interlocked.Exchange(ref _inner, _innerFactory()); | ||
| } | ||
|
|
||
| if (old is IDisposable disposable) | ||
| { | ||
| var delay = _disposeGraceDelay; | ||
| _ = Task.Run(async () => | ||
| { | ||
| await Task.Delay(delay); | ||
| DisposeInner(disposable); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private void DisposeInner(IDisposable disposable) | ||
| { | ||
| try | ||
| { | ||
| disposable.Dispose(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogWarning(ex, "Failed to dispose previous asset logic"); | ||
| } | ||
| } | ||
|
|
||
| public Task<AssetResponseDto?> GetNextAsset() => _inner.GetNextAsset(); | ||
|
|
||
| public Task<IEnumerable<AssetResponseDto>> GetAssets() => _inner.GetAssets(); | ||
|
|
||
| public Task<AssetResponseDto> GetAssetInfoById(Guid assetId) => _inner.GetAssetInfoById(assetId); | ||
|
|
||
| public Task<IEnumerable<AssetFaceResponseDto>> GetAssetFacesById(Guid assetId) => _inner.GetAssetFacesById(assetId); | ||
|
|
||
| public Task<IEnumerable<AlbumResponseDto>> GetAlbumInfoById(Guid assetId) => _inner.GetAlbumInfoById(assetId); | ||
|
|
||
| public Task<AssetResponse> GetAsset(Guid assetId, AssetTypeEnum? assetType = null, string? rangeHeader = null) | ||
| => _inner.GetAsset(assetId, assetType, rangeHeader); | ||
|
|
||
| public Task<long> GetTotalAssets() => _inner.GetTotalAssets(); | ||
|
|
||
| public Task SendWebhookNotification(IWebhookNotification notification) => _inner.SendWebhookNotification(notification); | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _settingsProvider.SettingsChanged -= OnSettingsChanged; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| IImmichFrameLogic? current; | ||
| lock (_swapLock) | ||
| { | ||
| if (_disposed) | ||
| return; | ||
|
|
||
| _disposed = true; | ||
| current = _inner; | ||
| } | ||
|
|
||
| if (current is IDisposable disposable) | ||
| { | ||
| DisposeInner(disposable); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: immichFrame/ImmichFrame
Length of output: 17769
🏁 Script executed:
Repository: immichFrame/ImmichFrame
Length of output: 16052
🤖 get_repo_knowledge executed:
get_repo_knowledge immichFrame/ImmichFrame /tmp/coderabbit-repo-knowledge/immichframe-immichframe-ea64c960/learningsLength of output: 1429
Sensitive Data Exposure (CWE-256)
Reachability: External · Exploitability: Difficult
Store an admin password verifier instead of the admin password.
AdminPasswordis serialized into the SQLite settings document and used directly for authentication. Anyone who obtainsimmichframe.dbor a backup can recover the password and authenticate as admin.FixedTimeEqualsdoes not protect the stored value.Store a salted password verifier for UI-managed passwords. Keep
IMMICHFRAME_ADMIN_PASSWORDexternal. Add migration handling for existing cleartext values.🤖 Prompt for AI Agents