mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
remove user from group apis
This commit is contained in:
parent
7a4d20ac1f
commit
540773eb36
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,5 +14,6 @@ namespace Bit.Core.Repositories
|
||||
Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId);
|
||||
Task CreateAsync(Group obj, IEnumerable<Guid> collectionIds);
|
||||
Task ReplaceAsync(Group obj, IEnumerable<Guid> collectionIds);
|
||||
Task DeleteUserAsync(Guid groupId, Guid organizationUserId);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -194,6 +194,7 @@
|
||||
<Build Include="dbo\Stored Procedures\GroupUserUserDetails_ReadByGroupId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUser_ReadGroupIdsByOrganizationUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUser_UpdateGroups.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUser_Delete.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<RefactorLog Include="Sql.refactorlog" />
|
||||
|
@ -37,4 +37,6 @@ BEGIN
|
||||
AND [Target].[CollectionId] = @Id THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
-- TODO: Update user revision date times that this affects
|
||||
END
|
16
src/Sql/dbo/Stored Procedures/GroupUser_Delete.sql
Normal file
16
src/Sql/dbo/Stored Procedures/GroupUser_Delete.sql
Normal file
@ -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
|
@ -41,4 +41,6 @@ BEGIN
|
||||
AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
|
||||
END
|
@ -37,4 +37,6 @@ BEGIN
|
||||
AND [Target].[GroupId] = @Id THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
-- TODO: Update user revision date times that this affects
|
||||
END
|
Loading…
Reference in New Issue
Block a user