1
1
using Umbraco . Cms . Api . Management . ViewModels ;
2
2
using Umbraco . Cms . Api . Management . ViewModels . AuditLog ;
3
+ using Umbraco . Cms . Core ;
3
4
using Umbraco . Cms . Core . Models ;
4
5
using Umbraco . Cms . Core . Models . Membership ;
5
6
using Umbraco . Cms . Core . Services ;
@@ -19,19 +20,17 @@ public AuditLogPresentationFactory(IUserService userService, IUserIdKeyResolver
19
20
20
21
public IEnumerable < AuditLogResponseModel > CreateAuditLogViewModel ( IEnumerable < IAuditItem > auditItems ) => auditItems . Select ( CreateAuditLogViewModel ) ;
21
22
22
- private AuditLogResponseModel CreateAuditLogViewModel ( IAuditItem auditItem )
23
- {
24
- Guid userKey = _userIdKeyResolver . GetAsync ( auditItem . UserId ) . GetAwaiter ( ) . GetResult ( ) ;
25
- IUser user = _userService . GetAsync ( userKey ) . GetAwaiter ( ) . GetResult ( )
26
- ?? throw new ArgumentException ( $ "Could not find user with id { auditItem . UserId } ") ;
27
-
28
- return new AuditLogResponseModel
23
+ private AuditLogResponseModel CreateAuditLogViewModel ( IAuditItem auditItem ) =>
24
+ new ( )
29
25
{
30
26
Comment = auditItem . Comment ,
31
27
LogType = auditItem . AuditType ,
32
28
Parameters = auditItem . Parameters ,
33
29
Timestamp = auditItem . CreateDate ,
34
- User = new ReferenceByIdModel ( user . Key )
30
+ User = auditItem . UserId switch
31
+ {
32
+ Constants . Security . UnknownUserId => new ReferenceByIdModel ( ) ,
33
+ _ => new ReferenceByIdModel ( _userIdKeyResolver . GetAsync ( auditItem . UserId ) . GetAwaiter ( ) . GetResult ( ) ) ,
34
+ } ,
35
35
} ;
36
- }
37
36
}
0 commit comments