Bugfix for AdminView
This commit is contained in:
@@ -129,9 +129,10 @@ public sealed class AdminEffects(IMoodleService moodleService, ILdapService ldap
|
|||||||
{
|
{
|
||||||
await cache.RemoveAsync(MoodleUsersCacheKey);
|
await cache.RemoveAsync(MoodleUsersCacheKey);
|
||||||
}
|
}
|
||||||
catch (RedisException)
|
catch (RedisException exception)
|
||||||
{
|
{
|
||||||
ReportMoodleDeletionFailure(dispatcher, "Moodle deletion did not start because the cache could not be invalidated.");
|
dispatcher.Dispatch(new MoodleUsersDeletionFailed());
|
||||||
|
snackbar.Add($"Moodle deletion did not start because the cache could not be invalidated: {exception.Message}", Severity.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,37 +163,83 @@ public sealed class AdminEffects(IMoodleService moodleService, ILdapService ldap
|
|||||||
await moodleService.DeleteUsers(userIds);
|
await moodleService.DeleteUsers(userIds);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (HttpRequestException)
|
catch (HttpRequestException exception)
|
||||||
{
|
{
|
||||||
ReportMoodleDeletionFailure(dispatcher, deletedUserCount, totalUserCount);
|
await ReportMoodleDeletionFailure(dispatcher, exception, userIds, deletedUserCount, totalUserCount);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException)
|
catch (InvalidOperationException exception)
|
||||||
{
|
{
|
||||||
ReportMoodleDeletionFailure(dispatcher, deletedUserCount, totalUserCount);
|
await ReportMoodleDeletionFailure(dispatcher, exception, userIds, deletedUserCount, totalUserCount);
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (TaskCanceledException exception)
|
||||||
{
|
{
|
||||||
ReportMoodleDeletionFailure(dispatcher, deletedUserCount, totalUserCount);
|
await ReportMoodleDeletionFailure(dispatcher, exception, userIds, deletedUserCount, totalUserCount);
|
||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException exception)
|
||||||
{
|
{
|
||||||
ReportMoodleDeletionFailure(dispatcher, deletedUserCount, totalUserCount);
|
await ReportMoodleDeletionFailure(dispatcher, exception, userIds, deletedUserCount, totalUserCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReportMoodleDeletionFailure(IDispatcher dispatcher, int deletedUserCount, int totalUserCount)
|
private async Task ReportMoodleDeletionFailure(
|
||||||
{
|
IDispatcher dispatcher,
|
||||||
ReportMoodleDeletionFailure(
|
Exception exception,
|
||||||
dispatcher,
|
IReadOnlyCollection<int> failedUserIds,
|
||||||
$"Moodle deletion stopped after deleting {deletedUserCount} of {totalUserCount} user(s). Later users were not processed.");
|
int deletedUserCount,
|
||||||
}
|
int totalUserCount)
|
||||||
|
|
||||||
private void ReportMoodleDeletionFailure(IDispatcher dispatcher, string message)
|
|
||||||
{
|
{
|
||||||
dispatcher.Dispatch(new MoodleUsersDeletionFailed());
|
dispatcher.Dispatch(new MoodleUsersDeletionFailed());
|
||||||
snackbar.Add(message, Severity.Error);
|
|
||||||
|
var reconciliationMessage = await ReconcileMoodleUsersAfterDeletionFailure(dispatcher, failedUserIds);
|
||||||
|
snackbar.Add(
|
||||||
|
$"Moodle deletion stopped after confirming {deletedUserCount} of {totalUserCount} user(s). Reason: {exception.Message}.{reconciliationMessage}",
|
||||||
|
Severity.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> ReconcileMoodleUsersAfterDeletionFailure(
|
||||||
|
IDispatcher dispatcher,
|
||||||
|
IReadOnlyCollection<int> failedUserIds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var users = await moodleService.GetAllUsers();
|
||||||
|
dispatcher.Dispatch(new SetMoodleUsers(users));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await cache.SetStringAsync(
|
||||||
|
MoodleUsersCacheKey,
|
||||||
|
JsonSerializer.Serialize(users),
|
||||||
|
new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(10) });
|
||||||
|
}
|
||||||
|
catch (RedisException exception)
|
||||||
|
{
|
||||||
|
return $" The user list was refreshed from Moodle, but Redis could not be updated: {exception.Message}";
|
||||||
|
}
|
||||||
|
|
||||||
|
var deletedFromFailedRequest = failedUserIds.Count(userId => !users.Any(user => user.Id == userId));
|
||||||
|
return deletedFromFailedRequest == 0
|
||||||
|
? " The user list was refreshed from Moodle."
|
||||||
|
: $" The user list was refreshed from Moodle; {deletedFromFailedRequest} user(s) from the failed request were deleted server-side.";
|
||||||
|
}
|
||||||
|
catch (HttpRequestException exception)
|
||||||
|
{
|
||||||
|
return $" The user list could not be refreshed: {exception.Message}";
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException exception)
|
||||||
|
{
|
||||||
|
return $" The user list could not be refreshed: {exception.Message}";
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException exception)
|
||||||
|
{
|
||||||
|
return $" The user list could not be refreshed: {exception.Message}";
|
||||||
|
}
|
||||||
|
catch (JsonException exception)
|
||||||
|
{
|
||||||
|
return $" The user list could not be refreshed: {exception.Message}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[EffectMethod]
|
[EffectMethod]
|
||||||
|
|||||||
Reference in New Issue
Block a user