Skip to content
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

Bug fix#17149 User Validation on Audit Repository .Save Method #17248

Open
wants to merge 6 commits into
base: contrib
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;

internal class AuditRepository : EntityRepositoryBase<int, IAuditItem>, IAuditRepository
{
private readonly ICollection<int> _cachedUserIds;
public AuditRepository(IScopeAccessor scopeAccessor, ILogger<AuditRepository> logger)
: base(scopeAccessor, AppCaches.NoCache, logger)
{
_cachedUserIds = new List<int>();
}

public IEnumerable<IAuditItem> Get(AuditType type, IQuery<IAuditItem> query)
Expand Down Expand Up @@ -69,10 +71,7 @@ public IEnumerable<IAuditItem> GetPagedResultsByQuery(
AuditType[]? auditTypeFilter,
IQuery<IAuditItem>? customFilter)
{
if (auditTypeFilter == null)
{
auditTypeFilter = Array.Empty<AuditType>();
}
auditTypeFilter ??= Array.Empty<AuditType>();

Sql<ISqlContext> sql = GetBaseQuery(false);

Expand Down Expand Up @@ -187,4 +186,17 @@ protected override Sql<ISqlContext> GetBaseQuery(bool isCount)
protected override string GetBaseWhereClause() => "id = @id";

protected override IEnumerable<string> GetDeleteClauses() => throw new NotImplementedException();

public override void Save(IAuditItem entity)
{
if (!_cachedUserIds.Any(x => x == entity.UserId))
{

int? userIdQueryResult = Database.FirstOrDefault<int?>(
" select id from umbracoUser where " + GetBaseWhereClause(),
new { id = entity.UserId }) ?? throw new InvalidOperationException("The user id does not exist");
_cachedUserIds.Add(userIdQueryResult.Value);
}
base.Save(entity);
}
}
Loading