Fixes invite user and setting the model correctly. Fixes server side validation to ensure any created user MUST have a group assigned.

This commit is contained in:
Shannon
2017-08-08 13:20:21 +10:00
parent 2d42a6ca16
commit bbe8271c35
3 changed files with 12 additions and 7 deletions
@@ -472,6 +472,7 @@
.then(function (saved) {
//success
vm.page.createButtonState = "success";
vm.newUser = saved;
setUsersViewState('inviteUserSuccess');
getUsers();
}, function (err) {
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
@@ -8,7 +9,7 @@ namespace Umbraco.Web.Models.ContentEditing
/// Represents the data used to invite a user
/// </summary>
[DataContract(Name = "user", Namespace = "")]
public class UserInvite : EntityBasic
public class UserInvite : EntityBasic, IValidatableObject
{
[DataMember(Name = "userGroups")]
[Required]
@@ -21,6 +22,11 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "message")]
public string Message { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (UserGroups.Any() == false)
yield return new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" });
}
}
}
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
@@ -47,11 +48,8 @@ namespace Umbraco.Web.Models.ContentEditing
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
//TODO: Add other server side validation
//if (CultureInfo.GetCultureInfo(Culture))
// yield return new ValidationResult("The culture is invalid", new[] { "Culture" });
yield break;
if (UserGroups.Any() == false)
yield return new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" });
}
}
}