Skip to content

Commit c7887c6

Browse files
CecilyKCecily King'ori
andauthored
Fix Missing Metadata update on InMemoryGroupProvider.cs (#82)
* Using PredicateBuilder for querying Users and Groups * Update InMemoryUserProvider.cs * Fixing Typo in ProtocolExtensions.cs * fix missing metadata on groups provider Co-authored-by: Cecily King'ori <[email protected]>
1 parent 0c0ac68 commit c7887c6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public override Task<Resource> CreateAsync(Resource resource, string correlation
4444
{
4545
throw new HttpResponseException(HttpStatusCode.Conflict);
4646
}
47+
//Update Metadata
48+
DateTime created = DateTime.UtcNow;
49+
group.Metadata.Created = created;
50+
group.Metadata.LastModified = created;
4751

4852
string resourceIdentifier = Guid.NewGuid().ToString();
4953
resource.Identifier = resourceIdentifier;
@@ -154,10 +158,10 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
154158
throw new HttpResponseException(HttpStatusCode.BadRequest);
155159
}
156160

157-
IEnumerable<Core2Group> exisitingGroups = this.storage.Groups.Values;
161+
Core2Group exisitingGroups = resource as Core2Group;
158162
if
159163
(
160-
exisitingGroups.Any(
164+
this.storage.Groups.Values.Any(
161165
(Core2Group exisitingUser) =>
162166
string.Equals(exisitingUser.DisplayName, group.DisplayName, StringComparison.Ordinal) &&
163167
!string.Equals(exisitingUser.Identifier, group.Identifier, StringComparison.OrdinalIgnoreCase))
@@ -171,6 +175,10 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
171175
throw new HttpResponseException(HttpStatusCode.NotFound);
172176
}
173177

178+
// Update metadata
179+
group.Metadata.Created = exisitingGroups.Metadata.Created;
180+
group.Metadata.LastModified = DateTime.UtcNow;
181+
174182
this.storage.Groups[group.Identifier] = group;
175183
Resource result = group as Resource;
176184
return Task.FromResult(result);
@@ -241,6 +249,8 @@ public override Task UpdateAsync(IPatch patch, string correlationIdentifier)
241249
if (this.storage.Groups.TryGetValue(patch.ResourceIdentifier.Identifier, out Core2Group group))
242250
{
243251
group.Apply(patchRequest);
252+
// Update metadata
253+
group.Metadata.LastModified = DateTime.UtcNow;
244254
}
245255
else
246256
{

Microsoft.SystemForCrossDomainIdentityManagement/Protocol/ProtocolExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ internal static IEnumerable<Role> PatchRoles(IEnumerable<Role> roles, PatchOpera
11161116
if
11171117
(
11181118
!string.Equals(
1119-
Microsoft.SCIM.AttributeNames.PhoneNumbers,
1119+
Microsoft.SCIM.AttributeNames.Roles,
11201120
operation.Path.AttributePath,
11211121
StringComparison.OrdinalIgnoreCase)
11221122
)
@@ -1156,10 +1156,10 @@ internal static IEnumerable<Role> PatchRoles(IEnumerable<Role> roles, PatchOpera
11561156
}
11571157

11581158
Role role;
1159-
Role roleAddressExisting;
1159+
Role roleExisting;
11601160
if (roles != null)
11611161
{
1162-
roleAddressExisting =
1162+
roleExisting =
11631163
role =
11641164
roles
11651165
.SingleOrDefault(
@@ -1168,7 +1168,7 @@ internal static IEnumerable<Role> PatchRoles(IEnumerable<Role> roles, PatchOpera
11681168
}
11691169
else
11701170
{
1171-
roleAddressExisting = null;
1171+
roleExisting = null;
11721172
role =
11731173
new Role()
11741174
{
@@ -1191,7 +1191,7 @@ internal static IEnumerable<Role> PatchRoles(IEnumerable<Role> roles, PatchOpera
11911191
IEnumerable<Role> result;
11921192
if (string.IsNullOrWhiteSpace(role.Value))
11931193
{
1194-
if (roleAddressExisting != null)
1194+
if (roleExisting != null)
11951195
{
11961196
result =
11971197
roles
@@ -1207,7 +1207,7 @@ internal static IEnumerable<Role> PatchRoles(IEnumerable<Role> roles, PatchOpera
12071207
return result;
12081208
}
12091209

1210-
if (roleAddressExisting != null)
1210+
if (roleExisting != null)
12111211
{
12121212
return roles;
12131213
}

0 commit comments

Comments
 (0)