Added an ArgumentNullException sanity check to let devs know it’s not allowed here, and checked before calling the method. The standard validation pipeline does the rest as it is marked [Required]

This commit is contained in:
Sebastien Ros
2010-04-16 13:31:36 -07:00
parent d4b79ea272
commit bea0266688
2 changed files with 5 additions and 1 deletions

View File

@@ -172,7 +172,7 @@ namespace Orchard.Core.Common.Handlers {
var priorOwner = viewModel.Owner;
context.Updater.TryUpdateModel(viewModel, "CommonAspect", null, null);
if (viewModel.Owner != priorOwner) {
if (viewModel.Owner != null && viewModel.Owner != priorOwner) {
var newOwner = _membershipService.GetUser(viewModel.Owner);
if (newOwner == null) {
context.Updater.AddModelError("CommonAspect.Owner", T("Invalid user name"));
@@ -181,6 +181,7 @@ namespace Orchard.Core.Common.Handlers {
instance.Owner = newOwner;
}
}
context.AddEditor(new TemplateViewModel(viewModel, "CommonAspect") { TemplateName = "Parts/Common.Owner", ZoneName = "primary", Position = "999" });
}
}

View File

@@ -44,6 +44,9 @@ namespace Orchard.Users.Services {
}
public IUser GetUser(string username) {
if(username == null) {
throw new ArgumentNullException("username");
}
var userRecord = _userRepository.Get(x => x.NormalizedUserName == username.ToLower());
if (userRecord == null) {
return null;