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));
        }
예제 #2
0
        private IEnumerable <UmbracoProperty> GetMemberPropertiesViewModel(IMemberType memberType, IEnumerable <string> builtIns, IMember member = null)
        {
            var viewProperties = new List <UmbracoProperty>();

            foreach (var prop in memberType.PropertyTypes
                     .Where(x => builtIns.Contains(x.Alias) == false && memberType.MemberCanEditProperty(x.Alias))
                     .OrderBy(p => p.SortOrder))
            {
                var value = string.Empty;
                if (member != null)
                {
                    var propValue = member.Properties[prop.Alias];
                    if (propValue != null && propValue.GetValue() != null)
                    {
                        value = propValue.GetValue().ToString();
                    }
                }

                var viewProperty = new UmbracoProperty
                {
                    Alias = prop.Alias,
                    Name  = prop.Name,
                    Value = value
                };

                // TODO: Perhaps one day we'll ship with our own EditorTempates but for now developers
                // can just render their own.

                ////This is a rudimentary check to see what data template we should render
                //// if developers want to change the template they can do so dynamically in their views or controllers
                //// for a given property.
                ////These are the default built-in MVC template types: “Boolean”, “Decimal”, “EmailAddress”, “HiddenInput”, “HTML”, “Object”, “String”, “Text”, and “Url”
                //// by default we'll render a text box since we've defined that metadata on the UmbracoProperty.Value property directly.
                //if (prop.DataTypeId == new Guid(Constants.PropertyEditors.TrueFalse))
                //{
                //    viewProperty.EditorTemplate = "UmbracoBoolean";
                //}
                //else
                //{
                //    switch (prop.DataTypeDatabaseType)
                //    {
                //        case DataTypeDatabaseType.Integer:
                //            viewProperty.EditorTemplate = "Decimal";
                //            break;
                //        case DataTypeDatabaseType.Ntext:
                //            viewProperty.EditorTemplate = "Text";
                //            break;
                //        case DataTypeDatabaseType.Date:
                //        case DataTypeDatabaseType.Nvarchar:
                //            break;
                //    }
                //}

                viewProperties.Add(viewProperty);
            }
            return(viewProperties);
        }
        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));
        }
        public void Member_Cannot_Edit_Property()
        {
            IMemberType memberType = MockedContentTypes.CreateSimpleMemberType();

            ServiceContext.MemberTypeService.Save(memberType);
            //re-get
            memberType = ServiceContext.MemberTypeService.Get(memberType.Id);
            foreach (var p in memberType.PropertyTypes)
            {
                Assert.IsFalse(memberType.MemberCanEditProperty(p.Alias));
            }
        }
        public void Member_Cannot_Edit_Property()
        {
            IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType();

            MemberTypeService.Save(memberType);

            // re-get
            memberType = MemberTypeService.Get(memberType.Id);
            foreach (IPropertyType p in memberType.PropertyTypes)
            {
                Assert.IsFalse(memberType.MemberCanEditProperty(p.Alias));
            }
        }
예제 #6
0
        private async Task <IdentityResult> UpdateMemberAsync(ProfileModel model, MemberIdentityUser currentMember)
        {
            using IScope scope = _scopeProvider.CreateScope(autoComplete: true);

            currentMember.Email    = model.Email;
            currentMember.Name     = model.Name;
            currentMember.UserName = model.UserName;
            currentMember.Comments = model.Comments;

            IdentityResult saveResult = await _memberManager.UpdateAsync(currentMember);

            if (!saveResult.Succeeded)
            {
                return(saveResult);
            }

            // now we can update the custom properties
            // TODO: Ideally we could do this all through our MemberIdentityUser

            IMember member = _memberService.GetByKey(currentMember.Key);

            if (member == null)
            {
                // should never happen
                throw new InvalidOperationException($"Could not find a member with key: {member.Key}.");
            }

            IMemberType memberType = _memberTypeService.Get(member.ContentTypeId);

            if (model.MemberProperties != null)
            {
                foreach (MemberPropertyModel property in model.MemberProperties
                         //ensure the property they are posting exists
                         .Where(p => memberType.PropertyTypeExists(p.Alias))
                         .Where(property => member.Properties.Contains(property.Alias))
                         //needs to be editable
                         .Where(p => memberType.MemberCanEditProperty(p.Alias)))
                {
                    member.Properties[property.Alias].SetValue(property.Value);
                }
            }

            _memberService.Save(member);

            return(saveResult);
        }
예제 #7
0
        // no MapAll - take care
        private void Map(IMemberType source, MemberTypeDisplay target, MapperContext context)
        {
            MapTypeToDisplayBase <MemberTypeDisplay, MemberPropertyTypeDisplay>(source, target);

            //map the MemberCanEditProperty,MemberCanViewProperty,IsSensitiveData
            foreach (var propertyType in source.PropertyTypes)
            {
                var localCopy   = propertyType;
                var displayProp = target.Groups.SelectMany(dest => dest.Properties).SingleOrDefault(dest => dest.Alias.InvariantEquals(localCopy.Alias));
                if (displayProp == null)
                {
                    continue;
                }
                displayProp.MemberCanEditProperty = source.MemberCanEditProperty(localCopy.Alias);
                displayProp.MemberCanViewProperty = source.MemberCanViewProperty(localCopy.Alias);
                displayProp.IsSensitiveData       = source.IsSensitiveProperty(localCopy.Alias);
            }
        }
        public void Is_Built_Correctly()
        {
            // Arrange
            const int    testId                = 99;
            var          testKey               = Guid.NewGuid();
            const string testAlias             = "memberType";
            const string testName              = "Member Type";
            const string testPropertyGroupName = "Content";
            const int    testParentId          = 98;
            const int    testCreatorId         = 22;
            DateTime     testCreateDate        = DateTime.Now.AddHours(-1);
            DateTime     testUpdateDate        = DateTime.Now;
            const int    testLevel             = 3;
            const string testPath              = "-1, 4, 10";
            const int    testSortOrder         = 5;
            const string testDescription       = "The description";
            const string testIcon              = "icon";
            const string testThumbnail         = "thumnail";
            const bool   testTrashed           = true;
            const int    testPropertyTypeIdsIncrementingFrom = 200;
            var          testPropertyType1 = new PropertyTypeDetail {
                Alias = "title", Name = "Title", SortOrder = 1, DataTypeId = -88
            };
            var testPropertyType2 = new PropertyTypeDetail {
                Alias = "bodyText", Name = "Body Text", SortOrder = 2, DataTypeId = -87
            };
            var testPropertyData1 = new KeyValuePair <string, object>("title", "Name member");

            var builder = new MemberTypeBuilder();

            // Act
            IMemberType memberType = builder
                                     .WithId(testId)
                                     .WithKey(testKey)
                                     .WithAlias(testAlias)
                                     .WithName(testName)
                                     .WithCreatorId(testCreatorId)
                                     .WithCreateDate(testCreateDate)
                                     .WithUpdateDate(testUpdateDate)
                                     .WithParentId(testParentId)
                                     .WithLevel(testLevel)
                                     .WithPath(testPath)
                                     .WithSortOrder(testSortOrder)
                                     .WithDescription(testDescription)
                                     .WithIcon(testIcon)
                                     .WithThumbnail(testThumbnail)
                                     .WithTrashed(testTrashed)
                                     .WithPropertyTypeIdsIncrementingFrom(200)
                                     .WithMembershipPropertyGroup()
                                     .AddPropertyGroup()
                                     .WithId(1)
                                     .WithName(testPropertyGroupName)
                                     .WithSortOrder(1)
                                     .AddPropertyType()
                                     .WithAlias(testPropertyType1.Alias)
                                     .WithName(testPropertyType1.Name)
                                     .WithSortOrder(testPropertyType1.SortOrder)
                                     .Done()
                                     .AddPropertyType()
                                     .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.TextBox)
                                     .WithValueStorageType(ValueStorageType.Ntext)
                                     .WithAlias(testPropertyType2.Alias)
                                     .WithName(testPropertyType2.Name)
                                     .WithSortOrder(testPropertyType2.SortOrder)
                                     .WithDataTypeId(testPropertyType2.DataTypeId)
                                     .Done()
                                     .Done()
                                     .WithMemberCanEditProperty(testPropertyType1.Alias, true)
                                     .WithMemberCanViewProperty(testPropertyType2.Alias, true)
                                     .Build();

            // Assert
            Assert.AreEqual(testId, memberType.Id);
            Assert.AreEqual(testAlias, memberType.Alias);
            Assert.AreEqual(testName, memberType.Name);
            Assert.AreEqual(testKey, memberType.Key);
            Assert.AreEqual(testCreateDate, memberType.CreateDate);
            Assert.AreEqual(testUpdateDate, memberType.UpdateDate);
            Assert.AreEqual(testCreatorId, memberType.CreatorId);
            Assert.AreEqual(testParentId, memberType.ParentId);
            Assert.AreEqual(testLevel, memberType.Level);
            Assert.AreEqual(testPath, memberType.Path);
            Assert.AreEqual(testSortOrder, memberType.SortOrder);
            Assert.AreEqual(testDescription, memberType.Description);
            Assert.AreEqual(testIcon, memberType.Icon);
            Assert.AreEqual(testThumbnail, memberType.Thumbnail);
            Assert.AreEqual(testTrashed, memberType.Trashed);
            Assert.IsFalse(memberType.IsContainer);
            Assert.AreEqual(9, memberType.PropertyTypes.Count());   // 7 from membership properties group, 2 custom

            IOrderedEnumerable <int> propertyTypeIds = memberType.PropertyTypes.Select(x => x.Id).OrderBy(x => x);

            Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 1, propertyTypeIds.Min());
            Assert.AreEqual(testPropertyTypeIdsIncrementingFrom + 9, propertyTypeIds.Max());

            Assert.IsTrue(memberType.MemberCanEditProperty(testPropertyType1.Alias));
            Assert.IsFalse(memberType.MemberCanViewProperty(testPropertyType1.Alias));
            Assert.IsTrue(memberType.MemberCanViewProperty(testPropertyType2.Alias));
            Assert.IsFalse(memberType.MemberCanEditProperty(testPropertyType2.Alias));
        }
예제 #9
0
 /// <summary>
 /// Get an true/false if the Member can edit the given data defined in the propertytype
 /// </summary>
 /// <param name="pt">Propertytype to edit</param>
 /// <returns>True if the Member can edit the data</returns>
 public bool MemberCanEdit(PropertyType pt)
 {
     return(MemberTypeItem.MemberCanEditProperty(pt.Alias));
 }