diff --git a/src/Api/Controllers/GroupsController.cs b/src/Api/Controllers/GroupsController.cs index c8514c35f..8a8feffca 100644 --- a/src/Api/Controllers/GroupsController.cs +++ b/src/Api/Controllers/GroupsController.cs @@ -123,5 +123,18 @@ namespace Bit.Api.Controllers await _groupRepository.DeleteAsync(group); } + + [HttpDelete("{id}/user/{orgUserId}")] + [HttpPost("{id}/delete-user/{orgUserId}")] + public async Task Delete(string orgId, string id, string orgUserId) + { + var group = await _groupRepository.GetByIdAsync(new Guid(id)); + if(group == null || !_currentContext.OrganizationAdmin(group.OrganizationId)) + { + throw new NotFoundException(); + } + + await _groupRepository.DeleteUserAsync(group.Id, new Guid(orgUserId)); + } } } diff --git a/src/Core/Repositories/IGroupRepository.cs b/src/Core/Repositories/IGroupRepository.cs index 0283b7e01..53627cb3f 100644 --- a/src/Core/Repositories/IGroupRepository.cs +++ b/src/Core/Repositories/IGroupRepository.cs @@ -14,5 +14,6 @@ namespace Bit.Core.Repositories Task> GetManyIdsByUserIdAsync(Guid organizationUserId); Task CreateAsync(Group obj, IEnumerable collectionIds); Task ReplaceAsync(Group obj, IEnumerable collectionIds); + Task DeleteUserAsync(Guid groupId, Guid organizationUserId); } } diff --git a/src/Core/Repositories/SqlServer/GroupRepository.cs b/src/Core/Repositories/SqlServer/GroupRepository.cs index 13bc6842d..f2013c02c 100644 --- a/src/Core/Repositories/SqlServer/GroupRepository.cs +++ b/src/Core/Repositories/SqlServer/GroupRepository.cs @@ -106,6 +106,17 @@ namespace Bit.Core.Repositories.SqlServer } } + public async Task DeleteUserAsync(Guid groupId, Guid organizationUserId) + { + using(var connection = new SqlConnection(ConnectionString)) + { + var results = await connection.ExecuteAsync( + $"[{Schema}].[GroupUser_Delete]", + new { GroupId = groupId, OrganizationUserId = organizationUserId }, + commandType: CommandType.StoredProcedure); + } + } + public class GroupWithCollections : Group { public DataTable CollectionIds { get; set; } diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index daa2facd4..6e954f56d 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -194,6 +194,7 @@ + diff --git a/src/Sql/dbo/Stored Procedures/Collection_UpdateWithGroups.sql b/src/Sql/dbo/Stored Procedures/Collection_UpdateWithGroups.sql index e1cce487f..abd68f1ee 100644 --- a/src/Sql/dbo/Stored Procedures/Collection_UpdateWithGroups.sql +++ b/src/Sql/dbo/Stored Procedures/Collection_UpdateWithGroups.sql @@ -37,4 +37,6 @@ BEGIN AND [Target].[CollectionId] = @Id THEN DELETE ; + + -- TODO: Update user revision date times that this affects END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/GroupUser_Delete.sql b/src/Sql/dbo/Stored Procedures/GroupUser_Delete.sql new file mode 100644 index 000000000..bb8ae1da7 --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/GroupUser_Delete.sql @@ -0,0 +1,16 @@ +CREATE PROCEDURE [dbo].[GroupUser_Delete] + @GroupId UNIQUEIDENTIFIER, + @OrganizationUserId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + DELETE + FROM + [dbo].[GroupUser] + WHERE + [GroupId] = @GroupId + AND [OrganizationUserId] = @OrganizationUserId + + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId +END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql index 49479b3ed..c97770846 100644 --- a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql +++ b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql @@ -41,4 +41,6 @@ BEGIN AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN DELETE ; + + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Group_UpdateWithCollections.sql b/src/Sql/dbo/Stored Procedures/Group_UpdateWithCollections.sql index c8c8a6774..0c2324767 100644 --- a/src/Sql/dbo/Stored Procedures/Group_UpdateWithCollections.sql +++ b/src/Sql/dbo/Stored Procedures/Group_UpdateWithCollections.sql @@ -37,4 +37,6 @@ BEGIN AND [Target].[GroupId] = @Id THEN DELETE ; + + -- TODO: Update user revision date times that this affects END \ No newline at end of file