Skip to content

Set patch value if the value comes from [value eq ] - #11

Closed
Ryanmeakins wants to merge 1 commit into
masterfrom
GroupMemebershipFixes
Closed

Ryanmeakins wants to merge 1 commit into
masterfrom
GroupMemebershipFixes

Conversation

@Ryanmeakins

Copy link
Copy Markdown
Contributor

No description provided.

{
if(this.values == null)
{
this.values = this.Path.SubAttributes.First()?.ComparisonValue;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this.Path could also be null. A better approach to do this would be during deserialization. You should parse the web-request while de-serializing the object into a PATCH object. That would be a place where you could de-serialize it correctly and do other validations on it.

{
if (!group.Members.Any(M => M.Value == member.Value))
{
group.Members = group.Members.Concat(new [] {member});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is highly non-performant. For every member that needs to be added to the group, this code scans all the other members, so the time complexity is O(n). This shall scale really poorly for the groups of a decent size.

{
if (!group.Members.Any(M => M.Value == member.Value))
{
group.Members = group.Members.Concat(new [] {member});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Avoid nested declarations for readability.


foreach(Member member in newMembers)
{
if (!group.Members.Any(M => M.Value == member.Value))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Format LINQ statements in the following way.
!group.Members.Any((member item) => string.Equals(item, member.Value, StringComparison.OrdinalIgnoreCase)

StringComparison instead of "==" because the SCIM client may or may not send the member id in the same case. If the SCIM server requires the string comparison to be case sensitive, then they may do so.

Another way would be to expose an Equals method on the Members and then compare the members for equality, where the Server decides how it wants to implement Equals.

@ankitC Ankit K Chheda (ankitC) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Link the issue in the pull request.
Squash the commits into a single commit.
Add examples and a verbose explanation to the pull request description.

@Ryanmeakins
Ryanmeakins force-pushed the GroupMemebershipFixes branch from 34f9cdb to b038ab0 Compare March 31, 2020 18:23
@Ryanmeakins Ryanmeakins linked an issue Mar 31, 2020 that may be closed by this pull request
Initalization update

Check for existing group membership before add. Used string equals with compariosn for string values, added new members to a list as they are found
@Ryanmeakins
Ryanmeakins force-pushed the GroupMemebershipFixes branch from b038ab0 to 4fcd080 Compare April 30, 2020 19:14
if (this.Path.SubAttributes.Any())
{
this.values = this.Path.SubAttributes.First().ComparisonValue;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should not be required given that the deserialization is working correctly.

private void OnDeserialized(StreamingContext context)
{
this.OnInitialized();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not required

{
//O(n) with the number of group members, so for large groups this is not optimal
if (!group.Members.Any((Member item) =>
string.Equals(item.Value, member.Value, StringComparison.OrdinalIgnoreCase)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Formatting.

if
(
group.Members.Any((Member item) =>
string.Equals(....)
)
{
//logic
}

{
writer = new StreamWriter(stream);
stream = null;
writer.Write(serialized);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All the logic in this file is the same as the base method. The logic to set the correct attributes with the correct values should be set in this method.

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

⌂ Proxy