如何在Umbraco中创建新的UserType

时间:2016-01-25 11:15:07

标签: c# umbraco

我正在寻找用户服务并找到了一个可爱的方法:

https://github.com/umbraco/Umbraco-CMS/blob/ae1b6d95b803f11594ec27a15674b0a6b0d41f5f/src/Umbraco.Core/Services/UserService.cs

public void SaveUserType(IUserType userType, bool raiseEvents = true)

需要IUserType。我可以在Github上看到的实现:

https://github.com/umbraco/Umbraco-CMS/blob/d50e49ad37fd5ca7bad2fd6e8fc994f3408ae70c/src/Umbraco.Core/Models/Membership/UserType.cs

是内部的。

如何在Umbraco中以编程方式创建新的UserType

我也尝试过:

Roles.Provider.CreateRole("Test User Type");

1 个答案:

答案 0 :(得分:0)

创建自己的类版本:

请务必添加参考:System.Runtime.Serialization;

[Serializable]
[DataContract(IsReference = true)]
public class ProvisioningUserType : Entity, IUserType
{
    [DataMember]
    public string Alias { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public IEnumerable<string> Permissions { get; set; }
}

实例化并使用SaveUserType方法

  

如果您收到此错误:字符串或二进制数据将是   截短的

     

然后您可能使用了错误的权限值。这些似乎   工作:

public class UserTypes
{
    public const string CultureAndHostNames = "I";//"Culture and Hostnames";
    public const string AuditTrail = "Z";//"Audit Trail";
    public const string BrowseNode = "F";//"Browse Node";
    public const string ChangeDocumentType = "7";//"Change Document Type";
    public const string Copy = "O";//"Copy";
    public const string Delete = "D";//"Delete";
    public const string Move = "M";//"Move";
    public const string Create = "C";//"Create";
    public const string PublicAccess = "P";//"Public access";
    public const string Publish = "U";//"Publish";
    public const string Permissions = "R";//"Permissions";
    public const string Rollback = "K";//"Rollback";
    public const string SendToTranslation = "5";//"Send To Translation";
    public const string Sort = "S";//"Sort";
    public const string SendToPublish = "H";//"Send To Publish";
    public const string Translate = "4";//"Translate";
    public const string Update = "A";//"Update";
    public const string UserGroupPermission = "œ";//"User Group Permissions";
}