Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EC-449] Event log user for SCIM events #2306

Merged
merged 56 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1c1e193
[EC-449] Added new Enum EventSystemUser
r-tome Sep 27, 2022
df5db9f
[EC-449] Added SystemUser property to Event model
r-tome Sep 27, 2022
1fa9405
[EC-449] Added SQL migration to add new column 'SystemUserType' to Event
r-tome Sep 27, 2022
2fc8544
[EC-449] EF migrations
r-tome Sep 27, 2022
2870069
[EC-449] Added EventSystemUser to EventResponseModel
r-tome Sep 27, 2022
043ebb3
[EC-449] Saving EventSystemUser.SCIM on SCIM controller actions
r-tome Sep 27, 2022
3f6b2a9
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Sep 28, 2022
b6f09de
[EC-449] Updated Event_Create stored procedure on Sql project
r-tome Sep 28, 2022
5e526ed
Merge branch 'EC-449-event-log-user-for-scim-events' of https://githu…
r-tome Sep 28, 2022
e1a1c8c
[EC-449] Fixed SystemUser column name on Event table
r-tome Sep 28, 2022
52d22d0
[EC-507] SCIM CQRS Refactor - Groups/Put (#2269)
r-tome Oct 17, 2022
94ff4f8
[EC-507] SCIM CQRS Refactor - Groups/GetList (#2272)
r-tome Oct 17, 2022
7f181e2
[EC-507] SCIM CQRS Refactor - Groups/Get (#2271)
r-tome Oct 17, 2022
0605a31
[EC-507] SCIM CQRS Refactor - Groups/Patch (#2268)
r-tome Oct 17, 2022
520b2ab
[EC-508] SCIM CQRS Refactor - Users/Delete (#2261)
r-tome Oct 17, 2022
f56e425
[EC-508] SCIM CQRS Refactor - Users/Post (#2264)
r-tome Oct 17, 2022
a6013c7
[EC-508] SCIM CQRS Refactor - Users/Patch (#2262)
r-tome Oct 18, 2022
4f10d81
[EC-507] SCIM CQRS Refactor - Groups/Post (#2270)
r-tome Oct 18, 2022
0a0a8eb
[EC-508] SCIM CQRS Refactor - Users/GetList (#2265)
r-tome Oct 18, 2022
2fa17f4
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Oct 18, 2022
48cc8be
[EC-507] SCIM CQRS Refactor - Groups/Delete (#2267)
r-tome Oct 18, 2022
e0ff808
[EC-449] Add overloads for EventService and GroupService methods that…
r-tome Oct 18, 2022
659feb5
Merge branch 'master' into feature/scim-cqrs
r-tome Oct 18, 2022
4936012
[EC-507] Move IDeleteGroupCommand to Groups folder
r-tome Oct 19, 2022
8f37a51
Merge branch 'master' into feature/scim-cqrs
r-tome Oct 19, 2022
2e6bf33
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Oct 19, 2022
03e88c5
[EC-449] Add method overloads in IOrganizationService without EventSy…
r-tome Oct 19, 2022
e118bbb
[EC-449] Add RevokeUserAsync overload without EventSystemUser
r-tome Oct 19, 2022
cf01034
[EC-449] Reverted OrganizationUsersController to not pass EventSystem…
r-tome Oct 19, 2022
f582c7a
[EC-449] Uncomment assertion in GroupServiceTests
r-tome Oct 19, 2022
fec3441
[EC-449] Update method overloads to not have nullable EventSystemUser
r-tome Oct 21, 2022
1fe4e69
[EC-449] Add unit tests around events that can store EventSystemUser
r-tome Oct 21, 2022
4ce7623
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Oct 28, 2022
4109099
[EC-449] Deleted private method GroupService.GroupRepositoryDeleteAsync
r-tome Oct 28, 2022
efdd4e7
[EC-449] Move Event log call to public DeleteUserAsync methods
r-tome Oct 28, 2022
1f81565
[EC-449] Move call to EventService log to public OrganizationService.…
r-tome Oct 28, 2022
572ae0d
[EC-449] Move EventService call to public OrganizationService.DeleteU…
r-tome Oct 28, 2022
7af2c4d
[EC-449] Move EventService call to OrganizationService.RevokeUserAsyn…
r-tome Oct 28, 2022
4329048
[EC-449] Move EventService call to OrganizationService.RestoreUserAsy…
r-tome Oct 28, 2022
313f1b9
[EC-449] Add missing comma in SQL script for new SystemUser column on…
r-tome Oct 28, 2022
07682de
[EC-449] Remove Autofixture hack from OrganizationServiceTests
r-tome Oct 28, 2022
cd6f7c0
[EC-449] Remove invitingUser param when methods expect an EventSystem…
r-tome Oct 28, 2022
d3c6999
Merge branch 'feature/scim-cqrs' into EC-449-event-log-user-for-scim-…
r-tome Oct 28, 2022
fc6adb7
Merge remote-tracking branch 'origin/master' into feature/scim-cqrs
eliykat Oct 30, 2022
0107416
Merge branch 'feature/scim-cqrs' into EC-449-event-log-user-for-scim-…
eliykat Oct 30, 2022
c69bfbd
[EC-449] Move DeleteUserAsync validation to private method
r-tome Oct 31, 2022
7f8db4b
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Oct 31, 2022
caeb333
[EC-449] Move revokingUserId from RevokeUserAsync private method
r-tome Oct 31, 2022
bac325c
[EC-449] Move restoringUserId to RestoreUserAsync public method
r-tome Oct 31, 2022
c66e305
[EC-449] Set up OrganizationServiceTest Restore and Revoke tests on a…
r-tome Oct 31, 2022
aad961b
[EC-449] SaveUsersSendInvitesAsync to return both OrganizationUsers a…
r-tome Oct 31, 2022
a3a5092
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Oct 31, 2022
0dc6ffb
[EC-449] Undo unintended change on CipherRepository
r-tome Nov 1, 2022
9760044
[EC-449] Add SystemUser value to EventTableEntity
r-tome Nov 2, 2022
93ac9d4
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Nov 2, 2022
f4ab101
Merge branch 'master' into EC-449-event-log-user-for-scim-events
r-tome Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bitwarden_license/src/Scim/Controllers/v2/GroupsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Exceptions;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.OrganizationFeatures.Groups.Interfaces;
using Bit.Core.Repositories;
using Bit.Scim.Groups.Interfaces;
Expand Down Expand Up @@ -96,7 +97,7 @@ public async Task<IActionResult> Patch(Guid organizationId, Guid id, [FromBody]
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(Guid organizationId, Guid id)
{
await _deleteGroupCommand.DeleteGroupAsync(organizationId, id);
await _deleteGroupCommand.DeleteGroupAsync(organizationId, id, EventSystemUser.SCIM);
return new NoContentResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<IActionResult> Patch(Guid organizationId, Guid id, [FromBody]
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(Guid organizationId, Guid id)
{
await _deleteOrganizationUserCommand.DeleteUserAsync(organizationId, id, null);
await _deleteOrganizationUserCommand.DeleteUserAsync(organizationId, id, EventSystemUser.SCIM);
return new NoContentResult();
}
}
7 changes: 4 additions & 3 deletions bitwarden_license/src/Scim/Groups/PatchGroupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -48,15 +49,15 @@ public async Task PatchGroupAsync(Guid organizationId, Guid id, ScimPatchModel m
else if (operation.Path?.ToLowerInvariant() == "displayname")
{
group.Name = operation.Value.GetString();
await _groupService.SaveAsync(group);
await _groupService.SaveAsync(group, EventSystemUser.SCIM);
operationHandled = true;
}
// Replace group name from value object
else if (string.IsNullOrWhiteSpace(operation.Path) &&
operation.Value.TryGetProperty("displayName", out var displayNameProperty))
{
group.Name = displayNameProperty.GetString();
await _groupService.SaveAsync(group);
await _groupService.SaveAsync(group, EventSystemUser.SCIM);
operationHandled = true;
}
}
Expand Down Expand Up @@ -94,7 +95,7 @@ public async Task PatchGroupAsync(Guid organizationId, Guid id, ScimPatchModel m
var removeId = GetOperationPathId(operation.Path);
if (removeId.HasValue)
{
await _groupService.DeleteUserAsync(group, removeId.Value);
await _groupService.DeleteUserAsync(group, removeId.Value, EventSystemUser.SCIM);
operationHandled = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion bitwarden_license/src/Scim/Groups/PostGroupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -38,7 +39,7 @@ public async Task<Group> PostGroupAsync(Guid organizationId, ScimGroupRequestMod
}

var group = model.ToGroup(organizationId);
await _groupService.SaveAsync(group, null);
await _groupService.SaveAsync(group, EventSystemUser.SCIM, null);
await UpdateGroupMembersAsync(group, model);

return group;
Expand Down
3 changes: 2 additions & 1 deletion bitwarden_license/src/Scim/Groups/PutGroupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -33,7 +34,7 @@ public async Task<Group> PutGroupAsync(Guid organizationId, Guid id, ScimGroupRe
}

group.Name = model.DisplayName;
await _groupService.SaveAsync(group);
await _groupService.SaveAsync(group, EventSystemUser.SCIM);
await UpdateGroupMembersAsync(group, model);

return group;
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/src/Scim/Users/PatchUserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ private async Task<bool> HandleActiveOperationAsync(Core.Entities.OrganizationUs
{
if (active && orgUser.Status == OrganizationUserStatusType.Revoked)
{
await _organizationService.RestoreUserAsync(orgUser, null, _userService);
await _organizationService.RestoreUserAsync(orgUser, EventSystemUser.SCIM, _userService);
return true;
}
else if (!active && orgUser.Status != OrganizationUserStatusType.Revoked)
{
await _organizationService.RevokeUserAsync(orgUser, null);
await _organizationService.RevokeUserAsync(orgUser, EventSystemUser.SCIM);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion bitwarden_license/src/Scim/Users/PostUserCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<OrganizationUserUserDetails> PostUserAsync(Guid organizationId
throw new ConflictException();
}

var invitedOrgUser = await _organizationService.InviteUserAsync(organizationId, null, email,
var invitedOrgUser = await _organizationService.InviteUserAsync(organizationId, EventSystemUser.SCIM, email,
OrganizationUserType.User, false, externalId, new List<SelectionReadOnly>());
var orgUser = await _organizationUserRepository.GetDetailsByIdAsync(invitedOrgUser.Id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -67,7 +68,7 @@ public async Task PatchGroup_ReplaceDisplayNameFromPath_Success(SutProvider<Patc

await sutProvider.Sut.PatchGroupAsync(group.OrganizationId, group.Id, scimPatchModel);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM);
Assert.Equal(displayName, group.Name);
}

Expand All @@ -94,7 +95,7 @@ public async Task PatchGroup_ReplaceDisplayNameFromValueObject_Success(SutProvid

await sutProvider.Sut.PatchGroupAsync(group.OrganizationId, group.Id, scimPatchModel);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM);
Assert.Equal(displayName, group.Name);
}

Expand Down Expand Up @@ -182,7 +183,7 @@ public async Task PatchGroup_RemoveSingleMember_Success(SutProvider<PatchGroupCo

await sutProvider.Sut.PatchGroupAsync(group.OrganizationId, group.Id, scimPatchModel);

await sutProvider.GetDependency<IGroupService>().Received(1).DeleteUserAsync(group, userId);
await sutProvider.GetDependency<IGroupService>().Received(1).DeleteUserAsync(group, userId, EventSystemUser.SCIM);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task PostGroup_Success(SutProvider<PostGroupCommand> sutProvider, s

var group = await sutProvider.Sut.PostGroupAsync(organizationId, scimGroupRequestModel);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, null);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM, null);
await sutProvider.GetDependency<IGroupRepository>().Received(0).UpdateUsersAsync(Arg.Any<Guid>(), Arg.Any<IEnumerable<Guid>>());

AssertHelper.AssertPropertyEqual(expectedResult, group, "Id", "CreationDate", "RevisionDate");
Expand Down Expand Up @@ -77,7 +78,7 @@ public async Task PostGroup_WithMembers_Success(SutProvider<PostGroupCommand> su

var group = await sutProvider.Sut.PostGroupAsync(organizationId, scimGroupRequestModel);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, null);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM, null);
await sutProvider.GetDependency<IGroupRepository>().Received(1).UpdateUsersAsync(Arg.Any<Guid>(), Arg.Is<IEnumerable<Guid>>(arg => arg.All(id => membersUserIds.Contains(id))));

AssertHelper.AssertPropertyEqual(expectedResult, group, "Id", "CreationDate", "RevisionDate");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -45,7 +46,7 @@ public async Task PutGroup_Success(SutProvider<PutGroupCommand> sutProvider, Gro
AssertHelper.AssertPropertyEqual(expectedResult, result, "CreationDate", "RevisionDate");
Assert.Equal(displayName, group.Name);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM);
await sutProvider.GetDependency<IGroupRepository>().Received(0).UpdateUsersAsync(group.Id, Arg.Any<IEnumerable<Guid>>());
}

Expand Down Expand Up @@ -82,7 +83,7 @@ public async Task PutGroup_ChangeMembers_Success(SutProvider<PutGroupCommand> su
AssertHelper.AssertPropertyEqual(expectedResult, result, "CreationDate", "RevisionDate");
Assert.Equal(displayName, group.Name);

await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group);
await sutProvider.GetDependency<IGroupService>().Received(1).SaveAsync(group, EventSystemUser.SCIM);
await sutProvider.GetDependency<IGroupRepository>().Received(1).UpdateUsersAsync(group.Id, Arg.Is<IEnumerable<Guid>>(arg => arg.All(id => membersUserIds.Contains(id))));
}

Expand Down
13 changes: 7 additions & 6 deletions bitwarden_license/test/Scim.Test/Users/PatchUserCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task PatchUser_RestorePath_Success(SutProvider<PatchUserCommand> su

await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);

await sutProvider.GetDependency<IOrganizationService>().Received(1).RestoreUserAsync(organizationUser, null, Arg.Any<IUserService>());
await sutProvider.GetDependency<IOrganizationService>().Received(1).RestoreUserAsync(organizationUser, EventSystemUser.SCIM, Arg.Any<IUserService>());
}

[Theory]
Expand Down Expand Up @@ -70,7 +71,7 @@ public async Task PatchUser_RestoreValue_Success(SutProvider<PatchUserCommand> s

await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);

await sutProvider.GetDependency<IOrganizationService>().Received(1).RestoreUserAsync(organizationUser, null, Arg.Any<IUserService>());
await sutProvider.GetDependency<IOrganizationService>().Received(1).RestoreUserAsync(organizationUser, EventSystemUser.SCIM, Arg.Any<IUserService>());
}

[Theory]
Expand Down Expand Up @@ -99,7 +100,7 @@ public async Task PatchUser_RevokePath_Success(SutProvider<PatchUserCommand> sut

await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);

await sutProvider.GetDependency<IOrganizationService>().Received(1).RevokeUserAsync(organizationUser, null);
await sutProvider.GetDependency<IOrganizationService>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
}

[Theory]
Expand Down Expand Up @@ -127,7 +128,7 @@ public async Task PatchUser_RevokeValue_Success(SutProvider<PatchUserCommand> su

await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);

await sutProvider.GetDependency<IOrganizationService>().Received(1).RevokeUserAsync(organizationUser, null);
await sutProvider.GetDependency<IOrganizationService>().Received(1).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
}

[Theory]
Expand All @@ -146,8 +147,8 @@ public async Task PatchUser_NoAction_Success(SutProvider<PatchUserCommand> sutPr

await sutProvider.Sut.PatchUserAsync(organizationUser.OrganizationId, organizationUser.Id, scimPatchModel);

await sutProvider.GetDependency<IOrganizationService>().Received(0).RestoreUserAsync(organizationUser, null, Arg.Any<IUserService>());
await sutProvider.GetDependency<IOrganizationService>().Received(0).RevokeUserAsync(organizationUser, null);
await sutProvider.GetDependency<IOrganizationService>().Received(0).RestoreUserAsync(organizationUser, EventSystemUser.SCIM, Arg.Any<IUserService>());
await sutProvider.GetDependency<IOrganizationService>().Received(0).RevokeUserAsync(organizationUser, EventSystemUser.SCIM);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public async Task PostUser_Success(SutProvider<PostUserCommand> sutProvider, str
.Returns(organizationUsers);

sutProvider.GetDependency<IOrganizationService>()
.InviteUserAsync(organizationId, null, scimUserRequestModel.PrimaryEmail.ToLowerInvariant(), OrganizationUserType.User, false, externalId, Arg.Any<List<SelectionReadOnly>>())
.InviteUserAsync(organizationId, EventSystemUser.SCIM, scimUserRequestModel.PrimaryEmail.ToLowerInvariant(), OrganizationUserType.User, false, externalId, Arg.Any<List<SelectionReadOnly>>())
.Returns(newUser);

var user = await sutProvider.Sut.PostUserAsync(organizationId, scimUserRequestModel);

await sutProvider.GetDependency<IOrganizationService>().Received(1).InviteUserAsync(organizationId, null, scimUserRequestModel.PrimaryEmail.ToLowerInvariant(),
await sutProvider.GetDependency<IOrganizationService>().Received(1).InviteUserAsync(organizationId, EventSystemUser.SCIM, scimUserRequestModel.PrimaryEmail.ToLowerInvariant(),
OrganizationUserType.User, false, scimUserRequestModel.ExternalId, Arg.Any<List<SelectionReadOnly>>());
await sutProvider.GetDependency<IOrganizationUserRepository>().Received(1).GetDetailsByIdAsync(newUser.Id);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Api/Models/Response/EventResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public EventResponseModel(IEvent ev)
DeviceType = ev.DeviceType;
IpAddress = ev.IpAddress;
InstallationId = ev.InstallationId;
SystemUser = ev.SystemUser;
}

public EventType Type { get; set; }
Expand All @@ -48,4 +49,5 @@ public EventResponseModel(IEvent ev)
public DateTime Date { get; set; }
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public EventSystemUser? SystemUser { get; set; }
}
2 changes: 2 additions & 0 deletions src/Core/Entities/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Event(IEvent e)
DeviceType = e.DeviceType;
IpAddress = e.IpAddress;
ActingUserId = e.ActingUserId;
SystemUser = e.SystemUser;
}

public Guid Id { get; set; }
Expand All @@ -47,6 +48,7 @@ public Event(IEvent e)
[MaxLength(50)]
public string IpAddress { get; set; }
public Guid? ActingUserId { get; set; }
public EventSystemUser? SystemUser { get; set; }

public void SetNewId()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Enums/EventSystemUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Bit.Core.Enums;

public enum EventSystemUser : byte
{
SCIM = 1
}
1 change: 1 addition & 0 deletions src/Core/Models/Data/EventMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public EventMessage(ICurrentContext currentContext)
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? IdempotencyId { get; private set; } = Guid.NewGuid();
public EventSystemUser? SystemUser { get; set; }
}
18 changes: 18 additions & 0 deletions src/Core/Models/Data/EventTableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private EventTableEntity(IEvent e)
DeviceType = e.DeviceType;
IpAddress = e.IpAddress;
ActingUserId = e.ActingUserId;
SystemUser = e.SystemUser;
}

public DateTime Date { get; set; }
Expand All @@ -44,6 +45,7 @@ private EventTableEntity(IEvent e)
public DeviceType? DeviceType { get; set; }
public string IpAddress { get; set; }
public Guid? ActingUserId { get; set; }
public EventSystemUser? SystemUser { get; set; }

public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
Expand All @@ -69,6 +71,16 @@ public override IDictionary<string, EntityProperty> WriteEntity(OperationContext
result.Add(deviceTypeName, new EntityProperty((int?)DeviceType));
}

var systemUserTypeName = nameof(SystemUser);
if (result.ContainsKey(systemUserTypeName))
{
result[systemUserTypeName] = new EntityProperty((int?)SystemUser);
}
else
{
result.Add(systemUserTypeName, new EntityProperty((int?)SystemUser));
}

return result;
}

Expand All @@ -88,6 +100,12 @@ public override void ReadEntity(IDictionary<string, EntityProperty> properties,
{
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
}

var systemUserTypeName = nameof(SystemUser);
if (properties.ContainsKey(systemUserTypeName) && properties[systemUserTypeName].Int32Value.HasValue)
{
SystemUser = (EventSystemUser)properties[systemUserTypeName].Int32Value.Value;
}
}

public static List<EventTableEntity> IndexEvent(EventMessage e)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Models/Data/IEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public interface IEvent
DeviceType? DeviceType { get; set; }
string IpAddress { get; set; }
DateTime Date { get; set; }
EventSystemUser? SystemUser { get; set; }
}
19 changes: 17 additions & 2 deletions src/Core/OrganizationFeatures/Groups/DeleteGroupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Bit.Core.Exceptions;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.OrganizationFeatures.Groups.Interfaces;
using Bit.Core.Repositories;
using Bit.Core.Services;
Expand All @@ -17,6 +19,18 @@ public DeleteGroupCommand(IEventService eventService, IGroupRepository groupRepo
}

public async Task DeleteGroupAsync(Guid organizationId, Guid id)
{
var group = await GroupRepositoryDeleteGroupAsync(organizationId, id);
await _eventService.LogGroupEventAsync(group, Core.Enums.EventType.Group_Deleted);
}

public async Task DeleteGroupAsync(Guid organizationId, Guid id, EventSystemUser eventSystemUser)
{
var group = await GroupRepositoryDeleteGroupAsync(organizationId, id);
await _eventService.LogGroupEventAsync(group, Core.Enums.EventType.Group_Deleted, eventSystemUser);
}

private async Task<Group> GroupRepositoryDeleteGroupAsync(Guid organizationId, Guid id)
{
var group = await _groupRepository.GetByIdAsync(id);
if (group == null || group.OrganizationId != organizationId)
Expand All @@ -25,6 +39,7 @@ public async Task DeleteGroupAsync(Guid organizationId, Guid id)
}

await _groupRepository.DeleteAsync(group);
await _eventService.LogGroupEventAsync(group, Core.Enums.EventType.Group_Deleted);

return group;
}
}
Loading