Skip to content

Fix patch issues with group members#14

Closed
steverash wants to merge 1 commit intoAzureAD:masterfrom
steverash:GroupPatchFixes
Closed

Fix patch issues with group members#14
steverash wants to merge 1 commit intoAzureAD:masterfrom
steverash:GroupPatchFixes

Conversation

@steverash
Copy link

@steverash steverash commented Apr 14, 2020

Fixes #10

As an alternative fix for the patch members, I've created a PR based on refactoring the existing extension method.

The problem was that patch does not currently cope with requests to remove users by path.

The common request made is in this format

{
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:PatchOp"
    ],
    "Operations": [
        {
            "op": "remove",
            "path": "members[value eq \"{{id4}}\"]"
        }
    ]
}

Currently this will cause the code to reset the whole members to an empty array, as if you have done

{
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:PatchOp"
    ],
    "Operations": [
        {
            "op": "remove",
            "path": "members"
        }
    ]
}

The PR also refactors into a number of simpler methods to make reading the code (hopefully) a bit simpler.

It has been tested with the Postman collection and seems to work. I've also used it in our own project with a series of mocked test requests.

{
group.DisplayName = value.Value;
}
group.DisplayNamePatchOperation(operation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method names should be actions, so it's recommended that you call the methods PatchDisplayName and PatchMembers


private static void DisplayNamePatchOperation(this Core2Group group, PatchOperation2 operation)
{
var value = operation.Value.SingleOrDefault();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strongly typed named wherever possible instead of vars.

string value = operation?.Value?.SingleOrDefault();


//patch is asking to remove members completely.
if (operation.Value?.FirstOrDefault()?.Value == null &&
(operation.Path?.SubAttributes == null || operation.Path?.SubAttributes.Count == 0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the extensive logic here, the deserialization of the incoming request into PatchOperation2 object needs to be changed so that it can handle the singled valued removal that you mentioned in the description of this pull request. We'll make changes to handle that soon.

{
var subAttr = operation.Path.SubAttributes.Single();

if (!subAttr.AttributePath.Equals("value", StringComparison.Ordinal))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic strings. There is a variable that should have it's value as "value" (AttributeNames.Value).

{
public bool Equals([AllowNull] Member x, [AllowNull] Member y)
{
var xVal = x.Value ?? "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic constants, should instead be string.Empty

}
}

private static void MemberPatchOperation(this Core2Group group, PatchOperation2 operation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods in the repo, in general, are arranged alphabetically. It's encouraged to follow the same pattern.

@ArvindHarinder1
Copy link
Contributor

@steverash closing this PR since the issue should be resolved by this PR - #25

Please reopen if anything is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with Patch operation on group members

3 participants