Skip to content

UserManager.AddToRolesAsync() and RemoveFromRolesAsync() fail on any conflict #64

@CollectorOfBolts

Description

@CollectorOfBolts

When adding multiple roles or generally updating a user's roles, I'd like to be able to just give UserManager.AddToRolesAsync() the full list of roles that the user should have and have it add any new roles. As it currently is, if the user already has even 1 of the roles being assigned, the operation reports as a failure, at best having added any new roles in the list prior to the role that the user already has.

Similarly, when removing roles, UserManager.RemoveFromRolesAsync() will fail if the user does not have any of the given roles when, in my opinion, it should ignore those and continue with removing any that the user does have.

Looking at the code, it appears that it could be as simple as changing return new IdentityResult(Resources.UserAlreadyInRole); to continue; in UserManager.AddToRolesAsync() and changing return new IdentityResult(Resources.UserNotInRole); to continue; in UserManager.RemoveFromRolesAsync().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions