Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Wemekamp 73 posts 385 karma points
    Jul 21, 2016 @ 07:43
    Mark Wemekamp
    0

    Show umbracoMemberLockedOut as a checkbox instead of string?

    Hi all!

    I'm looking for a way to show the umbracoMemberLockedOut property of a member as a checkbox in the backend?

    The membertype looks like this:

    enter image description here

    While the property on the member itself is a readonly string

    enter image description here

    I would like to be able to set this property from the backend without introducing a new property, is this possible?

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Mar 09, 2021 @ 06:46
    Simon Dingley
    0

    Did you ever resolve this? I've just completed a v7 upgrade and have the same issue. I tried changing the property type to Umbraco.TrueFalse but still it just displays as Umbraco.NoEdit with no ability to unlock a member.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Mar 09, 2021 @ 09:41
    Simon Dingley
    0

    Whilst this isn't ideal it does seem to do the job for the moment. What I have done is hook into the EditorModelEventManager.SendingMemberModel event and change the view from readonlyvalue to boolean as follows:

    private void EditorModelEventManager_SendingMemberModel(System.Web.Http.Filters.HttpActionExecutedContext sender, EditorModelEventArgs<global::Umbraco.Web.Models.ContentEditing.MemberDisplay> e)
    {
        var currentUsersGroups = e.UmbracoContext.Security.CurrentUser.Groups.ToList();
        var isMembershipAdmin = currentUsersGroups.Exists(x =>
            x.Alias.Equals("membershipAdministrator", StringComparison.OrdinalIgnoreCase));
    
        foreach (var p in e.Model.Properties)
        {
            if (p.Alias.Equals("umbracoMemberLockedOut") && isMembershipAdmin)
            {
                p.View = "boolean";
            }
        }
    }
    

    To provide some further context, the reason this appears to be necessary is because the core is forcing the view to be readonlyvalue in the MemberModelMapper class:

    https://github.com/umbraco/Umbraco-CMS/blob/7447cc4b7eb2c66f2ba4ecba02d0dbdfbbab2d4f/src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs#L281

    {
        //it's a generic provider so update the locked out property based on our known constant alias
        var isLockedOutProperty = result.SelectMany(x => x.Properties).FirstOrDefault(x => x.Alias == Constants.Conventions.Member.IsLockedOut);
        if (isLockedOutProperty?.Value != null && isLockedOutProperty.Value.ToString() != "1")
        {
            isLockedOutProperty.View = "readonlyvalue";
            isLockedOutProperty.Value = _localizedTextService.Localize("general/no");
        }
    }
    else
    {
        var umbracoProvider = (IUmbracoMemberTypeMembershipProvider)provider;
    
        //This is kind of a hack because a developer is supposed to be allowed to set their property editor - would have been much easier
        // if we just had all of the membeship provider fields on the member table :(
        // TODO: But is there a way to map the IMember.IsLockedOut to the property ? i dunno.
        var isLockedOutProperty = result.SelectMany(x => x.Properties).FirstOrDefault(x => x.Alias == umbracoProvider.LockPropertyTypeAlias);
        if (isLockedOutProperty?.Value != null && isLockedOutProperty.Value.ToString() != "1")
        {
            isLockedOutProperty.View = "readonlyvalue";
            isLockedOutProperty.Value = _localizedTextService.Localize("general/no");
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft