public void Member_Can_Edit_Property()
        {
            IMemberType memberType = MockedContentTypes.CreateSimpleMemberType();

            ServiceContext.MemberTypeService.Save(memberType);
            var prop = memberType.PropertyTypes.First().Alias;

            memberType.SetMemberCanEditProperty(prop, true);
            ServiceContext.MemberTypeService.Save(memberType);
            //re-get
            memberType = ServiceContext.MemberTypeService.Get(memberType.Id);
            foreach (var p in memberType.PropertyTypes.Where(x => x.Alias != prop))
            {
                Assert.IsFalse(memberType.MemberCanEditProperty(p.Alias));
            }
            Assert.IsTrue(memberType.MemberCanEditProperty(prop));
        }
Beispiel #2
0
        // no MapAll - take care
        private void Map(MemberTypeSave source, IMemberType target, MapperContext context)
        {
            MapSaveToTypeBase <MemberTypeSave, MemberPropertyTypeBasic>(source, target, context);
            MapComposition(source, target, alias => _memberTypeService.Get(alias));

            foreach (var propertyType in source.Groups.SelectMany(x => x.Properties))
            {
                var localCopy = propertyType;
                var destProp  = target.PropertyTypes.SingleOrDefault(x => x.Alias.InvariantEquals(localCopy.Alias));
                if (destProp == null)
                {
                    continue;
                }
                target.SetMemberCanEditProperty(localCopy.Alias, localCopy.MemberCanEditProperty);
                target.SetMemberCanViewProperty(localCopy.Alias, localCopy.MemberCanViewProperty);
                target.SetIsSensitiveProperty(localCopy.Alias, localCopy.IsSensitiveData);
            }
        }
        public void Member_Can_Edit_Property()
        {
            IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

            MemberTypeService.Save(memberType);
            string prop = memberType.PropertyTypes.First().Alias;

            memberType.SetMemberCanEditProperty(prop, true);
            MemberTypeService.Save(memberType);

            // re-get
            memberType = MemberTypeService.Get(memberType.Id);
            foreach (IPropertyType p in memberType.PropertyTypes.Where(x => x.Alias != prop))
            {
                Assert.IsFalse(memberType.MemberCanEditProperty(p.Alias));
            }

            Assert.IsTrue(memberType.MemberCanEditProperty(prop));
        }
Beispiel #4
0
        private string AddMemberProperties()
        {
            bool          saveMemberContent = false;
            StringBuilder contentStatus     = new StringBuilder();

            string groupname = "Forum Settings";
            string mType     = "Member";

            contentStatus.Append("<ul>");

            var newaccountType = _localizationService.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType");

            if (newaccountType != null)
            {
                mType = newaccountType.GetDefaultValue();
            }
            IMemberType memberContentType = _memberTypeService.Get(mType);

            var dataTypeDefinitions = _dataTypeService.GetAll().ToArray();                                           //.ToArray() because arrays are fast and easy.

            var truefalse = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.truefalse"); //we want the TrueFalse data type.
            var textbox   = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.textbox");   //we want the TextBox data type.

            try
            {
                if (!memberContentType.PropertyGroups.Contains(groupname))
                {
                    memberContentType.AddPropertyGroup(groupname); //add a property group, not needed, but I wanted it
                    saveMemberContent = true;
                }
                contentStatus.Append("<li>");

                if (!memberContentType.PropertyTypeExists("receiveNotifications"))
                {
                    contentStatus.Append("Adding property receiveNotifications");

                    saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse)
                    {
                        Name        = "Receive Notifications",
                        Alias       = "receiveNotifications",
                        Description = "Get an email when someone posts in a topic you are participating.",
                        Mandatory   = false
                    }, groupname);
                    if (saveMemberContent)
                    {
                        memberContentType.SetMemberCanEditProperty("receiveNotifications", true);
                        memberContentType.SetMemberCanViewProperty("receiveNotifications", true);
                    }
                    contentStatus.Append("<strong>done</strong>");
                }
                else
                {
                    memberContentType.SetMemberCanEditProperty("receiveNotifications", true);
                    memberContentType.SetMemberCanViewProperty("receiveNotifications", true);
                }
                contentStatus.Append("</li><li>");

                if (!memberContentType.PropertyTypeExists("hasVerifiedAccount"))
                {
                    contentStatus.Append("Adding property hasVerifiedAccount");
                    saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse)
                    {
                        Name        = "Has verified Email",
                        Alias       = "hasVerifiedAccount",
                        Description = "User has verified their account.",
                        Mandatory   = false
                    }, groupname);

                    contentStatus.Append("<strong>done</strong>");
                }
                contentStatus.Append("</li><li>");

                if (!memberContentType.PropertyTypeExists("resetGuid"))
                {
                    contentStatus.Append("Adding property resetGuid");
                    saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox)
                    {
                        Name        = "Reset Guid",
                        Alias       = "resetGuid",
                        Description = "Guid set when user requests a password reset.",
                        Mandatory   = false
                    }, groupname);
                    if (saveMemberContent)
                    {
                        memberContentType.SetIsSensitiveProperty("resetGuid", true);
                    }
                    contentStatus.Append("<strong>done</strong>");
                }
                contentStatus.Append("</li><li>");

                if (!memberContentType.PropertyTypeExists("joinedDate"))
                {
                    contentStatus.Append("Adding property joinedDate");
                    saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox)
                    {
                        Name        = "Joined date",
                        Alias       = "joinedDate",
                        Description = "Date the user joined (validated email).",
                        Mandatory   = false
                    }, groupname);
                    if (saveMemberContent)
                    {
                        memberContentType.SetMemberCanViewProperty("joinedDate", true);
                    }
                    contentStatus.Append("<strong>done</strong>");
                }
                contentStatus.Append("</li>");
                if (saveMemberContent)
                {
                    _memberTypeService.Save(memberContentType); //save the content type
                }
                else
                {
                    throw new ArgumentException("Unable to add custom Member properties");
                }
            }
            catch (Exception e)
            {
                Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), e, "Executing ForumInstallHandler:Add member types");
                contentStatus.Append($"<li>Error adding properties: {e.Message}</li>");
            }
            contentStatus.Append("</ul>");

            return(contentStatus.ToString());
        }
 /// <summary>
 /// Set if the member should be able to edit the data defined by its propertytype
 /// </summary>
 /// <param name="pt">PropertyType</param>
 /// <param name="value">True/False if Members of the type shoúld be able to edit the data</param>
 public void setMemberCanEdit(PropertyType pt, bool value)
 {
     MemberTypeItem.SetMemberCanEditProperty(pt.Alias, value);
 }