Пример #1
0
        public ExecutionResult Execute()
        {
            var memberType = _memberTypeService.Get(UsersInstallationConstants.DataTypeAliases.Member);

            var phoneProperty = new PropertyType("Umbraco.Textbox", DataTypeDatabaseType.Nvarchar)
            {
                Alias = UsersInstallationConstants.DataTypePropertyAliases.Phone,
                Name  = UsersInstallationConstants.DataTypePropertyNames.Phone
            };
            var departmentProperty = new PropertyType("Umbraco.Textbox", DataTypeDatabaseType.Nvarchar)
            {
                Alias = UsersInstallationConstants.DataTypePropertyAliases.Department,
                Name  = UsersInstallationConstants.DataTypePropertyNames.Department
            };

            var profileTab = UsersInstallationConstants.DataTypeTabAliases.ProfileTabAlias;

            if (!memberType.PropertyTypeExists(phoneProperty.Alias))
            {
                memberType.AddPropertyType(phoneProperty, profileTab);
            }

            if (!memberType.PropertyTypeExists(departmentProperty.Alias))
            {
                memberType.AddPropertyType(departmentProperty, profileTab);
            }

            _memberTypeService.Save(memberType);

            return(ExecutionResult.Success);
        }
        public void Empty_Description_Is_Always_Null_After_Saving_Member_Type()
        {
            IMemberTypeService service    = MemberTypeService;
            MemberType         memberType = MemberTypeBuilder.CreateSimpleMemberType();

            memberType.Description = null;
            service.Save(memberType);

            MemberType memberType2 = MemberTypeBuilder.CreateSimpleMemberType("memberType2", "Member Type 2");

            memberType2.Description = string.Empty;
            service.Save(memberType2);

            Assert.IsNull(memberType.Description);
            Assert.IsNull(memberType2.Description);
        }
Пример #3
0
        public override SyncAttempt <IMemberType> DeserializeSecondPass(IMemberType item, XElement node, SyncSerializerOptions options)
        {
            CleanTabAliases(item);
            var details = CleanTabs(item, node, options).ToList();

            SetSafeAliasValue(item, node, false);

            bool saveInSerializer = !options.Flags.HasFlag(SerializerFlags.DoNotSave);

            if (saveInSerializer && item.IsDirty())
            {
                memberTypeService.Save(item);
            }

            return(SyncAttempt <IMemberType> .Succeed(item.Name, item, ChangeType.Import, string.Empty, saveInSerializer, details));
        }
Пример #4
0
        public ActionResult <MemberTypeDisplay?> PostSave(MemberTypeSave contentTypeSave)
        {
            //get the persisted member type
            var ctId = Convert.ToInt32(contentTypeSave.Id);
            var ct   = ctId > 0 ? _memberTypeService.Get(ctId) : null;

            if (_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasAccessToSensitiveData() == false)
            {
                //We need to validate if any properties on the contentTypeSave have had their IsSensitiveValue changed,
                //and if so, we need to check if the current user has access to sensitive values. If not, we have to return an error
                var props = contentTypeSave.Groups.SelectMany(x => x.Properties);
                if (ct != null)
                {
                    foreach (var prop in props)
                    {
                        // Id 0 means the property was just added, no need to look it up
                        if (prop.Id == 0)
                        {
                            continue;
                        }

                        var foundOnContentType = ct.PropertyTypes.FirstOrDefault(x => x.Id == prop.Id);
                        if (foundOnContentType == null)
                        {
                            return(NotFound(new
                                            { Message = "No property type with id " + prop.Id + " found on the content type" }));
                        }

                        if (ct.IsSensitiveProperty(foundOnContentType.Alias) && prop.IsSensitiveData == false)
                        {
                            //if these don't match, then we cannot continue, this user is not allowed to change this value
                            return(Forbid());
                        }
                    }
                }
                else
                {
                    //if it is new, then we can just verify if any property has sensitive data turned on which is not allowed
                    if (props.Any(prop => prop.IsSensitiveData))
                    {
                        return(Forbid());
                    }
                }
            }


            var savedCt = PerformPostSave <MemberTypeDisplay, MemberTypeSave, MemberPropertyTypeBasic>(
                contentTypeSave:            contentTypeSave,
                getContentType:             i => ct,
                saveContentType:            type => _memberTypeService.Save(type));

            if (!(savedCt.Result is null))
            {
                return(savedCt.Result);
            }

            var display = _umbracoMapper.Map <MemberTypeDisplay>(savedCt.Value);

            display?.AddSuccessNotification(
                _localizedTextService.Localize("speechBubbles", "memberTypeSavedHeader"),
                string.Empty);

            return(display);
        }
Пример #5
0
        public IMemberType AddDialogueMemberType()
        {
            #region DataType Ids
            //-49	    Umbraco.TrueFalse
            //-51	    Umbraco.Integer
            //-87	    Umbraco.TinyMCEv3
            //-88	    Umbraco.Textbox
            //-89	    Umbraco.TextboxMultiple
            //-90	    Umbraco.UploadField
            //-92	    Umbraco.NoEdit
            //-36	    Umbraco.DateTime
            //-37	    Umbraco.ColorPickerAlias
            //-38	    Umbraco.FolderBrowser
            //-39	    Umbraco.DropDownMultiple
            //-40	    Umbraco.RadioButtonList
            //-41	    Umbraco.Date
            //-42	    Umbraco.DropDown
            //-43	    Umbraco.CheckBoxList
            //1034	    Umbraco.ContentPickerAlias
            //1035	    Umbraco.MediaPicker
            //1036	    Umbraco.MemberPicker
            //1040	    Umbraco.RelatedLinks
            //1041	    Umbraco.Tags
            //1045	    Umbraco.MultipleMediaPicker
            //1077	    Apt.PartialPicker
            //1089	    Umbraco.ImageCropper
            //1092	    Umbraco.TinyMCEv3
            //1103	    Our.Umbraco.FilePicker
            //1104	    Umbraco.MemberGroupPicker
            //1105	    Apt.CssPicker
            //1128	    Dialogue.ThemePicker
            //1132	    Dialogue.Permissions
            //1147	    Umbraco.MultipleTextstring
            #endregion

            var label           = _dataTypeService.GetDataTypeDefinitionById(-92);
            var upload          = _dataTypeService.GetDataTypeDefinitionById(-90);
            var textstring      = _dataTypeService.GetDataTypeDefinitionById(-88);
            var textboxMultiple = _dataTypeService.GetDataTypeDefinitionById(-89);
            var truefalse       = _dataTypeService.GetDataTypeDefinitionById(-49);
            var numeric         = _dataTypeService.GetDataTypeDefinitionById(-51);
            var datetime        = _dataTypeService.GetDataTypeDefinitionById(-36);

            // Profile, Settings, Social Tokens

            // Create the member Type
            var memType = new MemberType(-1)
            {
                Alias = AppConstants.MemberTypeAlias,
                Name  = "Dialogue Member"
            };

            // Create the Profile group/tab
            var profileGroup = new PropertyGroup
            {
                Name = "Profile",
            };
            profileGroup.PropertyTypes.Add(new PropertyType(label)
            {
                Alias       = "email",
                Name        = "Email",
                SortOrder   = 0,
                Description = "This is a bit rubbish, but it's the only way to get the email from the new member service at the current time"
            });
            profileGroup.PropertyTypes.Add(new PropertyType(upload)
            {
                Alias       = "avatar",
                Name        = "Avatar",
                SortOrder   = 0,
                Description = ""
            });
            profileGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Alias       = "website",
                Name        = "Website",
                SortOrder   = 0,
                Description = ""
            });
            profileGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Alias       = "twitter",
                Name        = "Twitter",
                SortOrder   = 0,
                Description = ""
            });
            profileGroup.PropertyTypes.Add(new PropertyType(textboxMultiple)
            {
                Alias       = "signature",
                Name        = "Signature",
                SortOrder   = 0,
                Description = ""
            });
            profileGroup.PropertyTypes.Add(new PropertyType(datetime)
            {
                Alias       = "lastActiveDate",
                Name        = "Last Active Date",
                SortOrder   = 0,
                Description = ""
            });
            memType.PropertyGroups.Add(profileGroup);

            // Create the Settings group/tab
            var settingsGroup = new PropertyGroup
            {
                Name = "Settings",
            };
            settingsGroup.PropertyTypes.Add(new PropertyType(truefalse)
            {
                Alias       = "canEditOtherMembers",
                Name        = "Can Edit Other Members",
                SortOrder   = 0,
                Description = "Enable this and the user can edit other members posts, their profiles and ban members (Usually use in conjunction with moderate permissions)."
            });
            settingsGroup.PropertyTypes.Add(new PropertyType(truefalse)
            {
                Alias       = "disableEmailNotifications",
                Name        = "Disable Email Notifications",
                SortOrder   = 0,
                Description = ""
            });
            settingsGroup.PropertyTypes.Add(new PropertyType(truefalse)
            {
                Alias       = "disablePosting",
                Name        = "Disable Posting",
                SortOrder   = 0,
                Description = ""
            });
            settingsGroup.PropertyTypes.Add(new PropertyType(truefalse)
            {
                Alias       = "disablePrivateMessages",
                Name        = "Disable Private Messages",
                SortOrder   = 0,
                Description = ""
            });
            settingsGroup.PropertyTypes.Add(new PropertyType(truefalse)
            {
                Alias       = "disableFileUploads",
                Name        = "Disable File Uploads",
                SortOrder   = 0,
                Description = ""
            });
            settingsGroup.PropertyTypes.Add(new PropertyType(numeric)
            {
                Alias       = "postCount",
                Name        = "Post Count",
                SortOrder   = 0,
                Description = "The users post count. This is kept like this to help reduce SQL queries and improve performance of the forum"
            });
            memType.PropertyGroups.Add(settingsGroup);

            // Create the Settings group/tab
            var socialGroup = new PropertyGroup
            {
                Name = "Social Tokens",
            };
            socialGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Name        = "Facebook Access Token",
                Alias       = "facebookAccessToken",
                SortOrder   = 0,
                Description = ""
            });
            socialGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Name        = "Facebook Id",
                Alias       = "facebookId",
                SortOrder   = 0,
                Description = ""
            });
            socialGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Name        = "Google Access Token",
                Alias       = "googleAccessToken",
                SortOrder   = 0,
                Description = ""
            });
            socialGroup.PropertyTypes.Add(new PropertyType(textstring)
            {
                Name        = "Google Id",
                Alias       = "googleId",
                SortOrder   = 0,
                Description = ""
            });
            memType.PropertyGroups.Add(socialGroup);

            // Add Slug
            memType.AddPropertyType(new PropertyType(textstring)
            {
                Name        = "Slug",
                Alias       = "slug",
                SortOrder   = 0,
                Description = "This is what we use to look up the member in the front end"
            });

            _memberTypeService.Save(memType);

            return(memType);
        }
Пример #6
0
 /// <summary>
 /// Saves the specified content type.
 /// </summary>
 /// <param name="contentType">The content type.</param>
 protected override void SaveContentType(IMemberType contentType)
 {
     _memberTypeService.Save(contentType);
 }
Пример #7
0
        public void Get_Paged_Mixed_Entities_By_Ids()
        {
            // Create content
            IContentService     contentService     = GetRequiredService <IContentService>();
            IContentTypeService contentTypeService = GetRequiredService <IContentTypeService>();
            var         createdContent             = new List <IContent>();
            ContentType contentType = ContentTypeBuilder.CreateBasicContentType("blah");

            contentTypeService.Save(contentType);
            for (int i = 0; i < 10; i++)
            {
                Content c1 = ContentBuilder.CreateBasicContent(contentType);
                contentService.Save(c1);
                createdContent.Add(c1);
            }

            // Create media
            IMediaService     mediaService     = GetRequiredService <IMediaService>();
            IMediaTypeService mediaTypeService = GetRequiredService <IMediaTypeService>();
            var       createdMedia             = new List <IMedia>();
            MediaType imageType = MediaTypeBuilder.CreateImageMediaType("myImage");

            mediaTypeService.Save(imageType);
            for (int i = 0; i < 10; i++)
            {
                Media c1 = MediaBuilder.CreateMediaImage(imageType, -1);
                mediaService.Save(c1);
                createdMedia.Add(c1);
            }

            // Create members
            IMemberService     memberService     = GetRequiredService <IMemberService>();
            IMemberTypeService memberTypeService = GetRequiredService <IMemberTypeService>();
            MemberType         memberType        = MemberTypeBuilder.CreateSimpleMemberType("simple");

            memberTypeService.Save(memberType);
            var createdMembers = MemberBuilder.CreateMultipleSimpleMembers(memberType, 10).ToList();

            memberService.Save(createdMembers);

            IScopeProvider provider = ScopeProvider;

            using (provider.CreateScope())
            {
                EntityRepository repo = CreateRepository((IScopeAccessor)provider);

                IEnumerable <int> ids = createdContent.Select(x => x.Id).Concat(createdMedia.Select(x => x.Id)).Concat(createdMembers.Select(x => x.Id));

                System.Guid[] objectTypes = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, Constants.ObjectTypes.Member };

                IQuery <IUmbracoEntity> query = provider.CreateQuery <IUmbracoEntity>()
                                                .WhereIn(e => e.Id, ids);

                var entities = repo.GetPagedResultsByQuery(query, objectTypes, 0, 20, out long totalRecords, null, null).ToList();

                Assert.AreEqual(20, entities.Count);
                Assert.AreEqual(30, totalRecords);

                // add the next page
                entities.AddRange(repo.GetPagedResultsByQuery(query, objectTypes, 1, 20, out totalRecords, null, null));

                Assert.AreEqual(30, entities.Count);
                Assert.AreEqual(30, totalRecords);

                var contentEntities = entities.OfType <IDocumentEntitySlim>().ToList();
                var mediaEntities   = entities.OfType <IMediaEntitySlim>().ToList();
                var memberEntities  = entities.OfType <IMemberEntitySlim>().ToList();

                Assert.AreEqual(10, contentEntities.Count);
                Assert.AreEqual(10, mediaEntities.Count);
                Assert.AreEqual(10, memberEntities.Count);
            }
        }
Пример #8
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());
        }
Пример #9
0
 protected override void SaveContentType(IContentTypeBase contentType)
 {
     _service.Save((IMemberType)contentType);
 }