2

We have some custom code to send emails out when submitting an item from one workflow state to another and it seems to be sending items to users who have been disabled. I've been trying to find a way to check on the enabled/disabled status of a user, but haven't had much luck. Here is the code:

public class UserFunctions
{
    public static List<User> ContentAdminsFor(Item i)
    {
        if (i == null) return null;

        var users = new List<User>();

        var contentAdmins = RolesInRolesManager.GetUsersInRole(Role.FromName(@"org\Workflow Admin"), true);

        var orgRoot = Utils.GetRoot(i);

        foreach(var user in contentAdmins)
        {
            using (new UserSwitcher(user))
            {
                if (orgRoot.Access.CanWrite())
                {
                    users.Add(user);
                }
            }
        }

        return users;
    }
}

2 Answers 2

7

You can get this info the other way around. Check the !user.IsApproved property. But first you need to get the user through the membership provider like this:

var provider = System.Web.Security.Membership.Provider;
var user = provider.GetUser(username, false);
if (!user.IsApproved)
{...}
2
  • That isn't showing up as an option - only user.isAdministrator, isAuthenticated, and isInRole. Aug 9, 2019 at 15:30
  • 1
    @LeviWallach I updated my answer, you need to use the membership provider to get the membership user. Aug 9, 2019 at 15:33
5

I think Sitecore PowerShell Extensions could help address both the workflow action feature, as well as finding the users.

The following query would provide enabled users in a given domain:

Get-User -Filter "training\*" | Where-Object { $_.IsEnabled }

enter image description here

The following query provides enabled users in a given role:

Get-RoleMember -Identity "training\editor" | Where-Object { $_.IsEnabled }

enter image description here

1
  • Thanks, but I'm currently dealing with an issue on our development server where changes to things made my PSE Scripts work initially but then revert, so for now I think I'll be going with a code solution... Aug 9, 2019 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.