using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Models.ContentEditing;
///
/// Used to assign user group permissions to a content node
///
[DataContract(Name = "contentPermission", Namespace = "")]
public class UserGroupPermissionsSave
{
public UserGroupPermissionsSave() => AssignedPermissions = new Dictionary>();
// TODO: we should have an option to clear the permissions assigned to this node and instead just have them inherit - yes once we actually have inheritance!
[DataMember(Name = "contentId", IsRequired = true)]
[Required]
public int ContentId { get; set; }
///
/// A dictionary of permissions to assign, the key is the user group id
///
[DataMember(Name = "permissions")]
public IDictionary> AssignedPermissions { get; set; }
[Obsolete("This is not used and will be removed in Umbraco 10")]
public IEnumerable Validate(ValidationContext validationContext)
{
if (AssignedPermissions.SelectMany(x => x.Value).Any(x => x.IsNullOrWhiteSpace()))
{
yield return new ValidationResult("A permission value cannot be null or empty", new[] { "Permissions" });
}
}
}