1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

log event when removing user from group/collection

This commit is contained in:
Kyle Spearrin 2018-07-09 23:07:04 -04:00
parent 90df2f21e5
commit 9fee09e204
8 changed files with 34 additions and 7 deletions

View File

@ -155,7 +155,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
await _collectionRepository.DeleteUserAsync(collection.Id, new Guid(orgUserId)); await _collectionService.DeleteUserAsync(collection, new Guid(orgUserId));
} }
} }
} }

View File

@ -8,7 +8,6 @@ using Bit.Core.Models.Api;
using Bit.Core.Exceptions; using Bit.Core.Exceptions;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core; using Bit.Core;
using System.Collections.Generic;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -98,7 +97,6 @@ namespace Bit.Api.Controllers
} }
[HttpPut("{id}")] [HttpPut("{id}")]
[HttpPost("{id}")]
public async Task<GroupResponseModel> Put(string orgId, string id, [FromBody]GroupRequestModel model) public async Task<GroupResponseModel> Put(string orgId, string id, [FromBody]GroupRequestModel model)
{ {
var group = await _groupRepository.GetByIdAsync(new Guid(id)); var group = await _groupRepository.GetByIdAsync(new Guid(id));
@ -112,7 +110,6 @@ namespace Bit.Api.Controllers
} }
[HttpDelete("{id}")] [HttpDelete("{id}")]
[HttpPost("{id}/delete")]
public async Task Delete(string orgId, string id) public async Task Delete(string orgId, string id)
{ {
var group = await _groupRepository.GetByIdAsync(new Guid(id)); var group = await _groupRepository.GetByIdAsync(new Guid(id));
@ -125,7 +122,6 @@ namespace Bit.Api.Controllers
} }
[HttpDelete("{id}/user/{orgUserId}")] [HttpDelete("{id}/user/{orgUserId}")]
[HttpPost("{id}/delete-user/{orgUserId}")]
public async Task Delete(string orgId, string id, string orgUserId) public async Task Delete(string orgId, string id, string orgUserId)
{ {
var group = await _groupRepository.GetByIdAsync(new Guid(id)); var group = await _groupRepository.GetByIdAsync(new Guid(id));
@ -134,7 +130,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
await _groupRepository.DeleteUserAsync(group.Id, new Guid(orgUserId)); await _groupService.DeleteUserAsync(group, new Guid(orgUserId));
} }
} }
} }

View File

@ -57,6 +57,7 @@ namespace Bit.Core.Models.Api
public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; } public IEnumerable<SelectionReadOnlyResponseModel> Collections { get; set; }
} }
public class OrganizationUserUserDetailsResponseModel : OrganizationUserResponseModel public class OrganizationUserUserDetailsResponseModel : OrganizationUserResponseModel
{ {
public OrganizationUserUserDetailsResponseModel(OrganizationUserUserDetails organizationUser, public OrganizationUserUserDetailsResponseModel(OrganizationUserUserDetails organizationUser,

View File

@ -2,6 +2,7 @@
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using System.Collections.Generic; using System.Collections.Generic;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using System;
namespace Bit.Core.Services namespace Bit.Core.Services
{ {
@ -9,5 +10,6 @@ namespace Bit.Core.Services
{ {
Task SaveAsync(Collection collection, IEnumerable<SelectionReadOnly> groups = null); Task SaveAsync(Collection collection, IEnumerable<SelectionReadOnly> groups = null);
Task DeleteAsync(Collection collection); Task DeleteAsync(Collection collection);
Task DeleteUserAsync(Collection collection, Guid organizationUserId);
} }
} }

View File

@ -2,6 +2,7 @@
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using System.Collections.Generic; using System.Collections.Generic;
using Bit.Core.Models.Data; using Bit.Core.Models.Data;
using System;
namespace Bit.Core.Services namespace Bit.Core.Services
{ {
@ -9,5 +10,6 @@ namespace Bit.Core.Services
{ {
Task SaveAsync(Group group, IEnumerable<SelectionReadOnly> collections = null); Task SaveAsync(Group group, IEnumerable<SelectionReadOnly> collections = null);
Task DeleteAsync(Group group); Task DeleteAsync(Group group);
Task DeleteUserAsync(Group group, Guid organizationUserId);
} }
} }

View File

@ -84,5 +84,16 @@ namespace Bit.Core.Services
await _collectionRepository.DeleteAsync(collection); await _collectionRepository.DeleteAsync(collection);
await _eventService.LogCollectionEventAsync(collection, Enums.EventType.Collection_Deleted); await _eventService.LogCollectionEventAsync(collection, Enums.EventType.Collection_Deleted);
} }
public async Task DeleteUserAsync(Collection collection, Guid organizationUserId)
{
var orgUser = await _organizationUserRepository.GetByIdAsync(organizationUserId);
if(orgUser == null || orgUser.OrganizationId != collection.OrganizationId)
{
throw new NotFoundException();
}
await _collectionRepository.DeleteUserAsync(collection.Id, organizationUserId);
await _eventService.LogOrganizationUserEventAsync(orgUser, Enums.EventType.OrganizationUser_Updated);
}
} }
} }

View File

@ -12,15 +12,18 @@ namespace Bit.Core.Services
{ {
private readonly IEventService _eventService; private readonly IEventService _eventService;
private readonly IOrganizationRepository _organizationRepository; private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IGroupRepository _groupRepository; private readonly IGroupRepository _groupRepository;
public GroupService( public GroupService(
IEventService eventService, IEventService eventService,
IOrganizationRepository organizationRepository, IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
IGroupRepository groupRepository) IGroupRepository groupRepository)
{ {
_eventService = eventService; _eventService = eventService;
_organizationRepository = organizationRepository; _organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_groupRepository = groupRepository; _groupRepository = groupRepository;
} }
@ -65,5 +68,16 @@ namespace Bit.Core.Services
await _groupRepository.DeleteAsync(group); await _groupRepository.DeleteAsync(group);
await _eventService.LogGroupEventAsync(group, Enums.EventType.Group_Deleted); await _eventService.LogGroupEventAsync(group, Enums.EventType.Group_Deleted);
} }
public async Task DeleteUserAsync(Group group, Guid organizationUserId)
{
var orgUser = await _organizationUserRepository.GetByIdAsync(organizationUserId);
if(orgUser == null || orgUser.OrganizationId != group.OrganizationId)
{
throw new NotFoundException();
}
await _groupRepository.DeleteUserAsync(group.Id, organizationUserId);
await _eventService.LogOrganizationUserEventAsync(orgUser, Enums.EventType.OrganizationUser_UpdatedGroups);
}
} }
} }

View File

@ -919,7 +919,7 @@ namespace Bit.Core.Services
organizationId, email, false); organizationId, email, false);
if(existingOrgUserCount > 0) if(existingOrgUserCount > 0)
{ {
throw new BadRequestException("User already invited."); continue;
} }
var orgUser = new OrganizationUser var orgUser = new OrganizationUser
@ -946,6 +946,7 @@ namespace Bit.Core.Services
} }
await SendInviteAsync(orgUser); await SendInviteAsync(orgUser);
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Invited);
orgUsers.Add(orgUser); orgUsers.Add(orgUser);
} }