1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-23 12:25:16 +01:00

remove user from group apis

This commit is contained in:
Kyle Spearrin 2017-05-09 19:24:03 -04:00
parent 7a4d20ac1f
commit 540773eb36
8 changed files with 48 additions and 0 deletions

View File

@ -123,5 +123,18 @@ namespace Bit.Api.Controllers
await _groupRepository.DeleteAsync(group); 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));
}
} }
} }

View File

@ -14,5 +14,6 @@ namespace Bit.Core.Repositories
Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId); Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId);
Task CreateAsync(Group obj, IEnumerable<Guid> collectionIds); Task CreateAsync(Group obj, IEnumerable<Guid> collectionIds);
Task ReplaceAsync(Group obj, IEnumerable<Guid> collectionIds); Task ReplaceAsync(Group obj, IEnumerable<Guid> collectionIds);
Task DeleteUserAsync(Guid groupId, Guid organizationUserId);
} }
} }

View File

@ -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 class GroupWithCollections : Group
{ {
public DataTable CollectionIds { get; set; } public DataTable CollectionIds { get; set; }

View File

@ -194,6 +194,7 @@
<Build Include="dbo\Stored Procedures\GroupUserUserDetails_ReadByGroupId.sql" /> <Build Include="dbo\Stored Procedures\GroupUserUserDetails_ReadByGroupId.sql" />
<Build Include="dbo\Stored Procedures\GroupUser_ReadGroupIdsByOrganizationUserId.sql" /> <Build Include="dbo\Stored Procedures\GroupUser_ReadGroupIdsByOrganizationUserId.sql" />
<Build Include="dbo\Stored Procedures\GroupUser_UpdateGroups.sql" /> <Build Include="dbo\Stored Procedures\GroupUser_UpdateGroups.sql" />
<Build Include="dbo\Stored Procedures\GroupUser_Delete.sql" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<RefactorLog Include="Sql.refactorlog" /> <RefactorLog Include="Sql.refactorlog" />

View File

@ -37,4 +37,6 @@ BEGIN
AND [Target].[CollectionId] = @Id THEN AND [Target].[CollectionId] = @Id THEN
DELETE DELETE
; ;
-- TODO: Update user revision date times that this affects
END END

View 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

View File

@ -41,4 +41,6 @@ BEGIN
AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
DELETE DELETE
; ;
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
END END

View File

@ -37,4 +37,6 @@ BEGIN
AND [Target].[GroupId] = @Id THEN AND [Target].[GroupId] = @Id THEN
DELETE DELETE
; ;
-- TODO: Update user revision date times that this affects
END END