1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

share service setup

This commit is contained in:
Kyle Spearrin 2017-02-25 23:38:24 -05:00
parent 0caea4ab8b
commit 48cf44f5b2
4 changed files with 34 additions and 6 deletions

View File

@ -16,13 +16,16 @@ namespace Bit.Api.Controllers
{
private readonly IShareRepository _shareRepository;
private readonly IUserService _userService;
private readonly ICipherService _cipherService;
public SharesController(
IShareRepository shareRepository,
IUserService userService)
IUserService userService,
ICipherService cipherService)
{
_shareRepository = shareRepository;
_userService = userService;
_cipherService = cipherService;
}
[HttpGet("{id}")]
@ -42,7 +45,7 @@ namespace Bit.Api.Controllers
public async Task<ShareResponseModel> Post([FromBody]ShareRequestModel model)
{
var share = model.ToShare(_userService.GetProperUserId(User).Value);
await _shareRepository.CreateAsync(share);
await _cipherService.ShareAsync(share, model.Email);
var response = new ShareResponseModel(share);
return response;

View File

@ -8,8 +8,7 @@ namespace Bit.Api.Models
public class ShareRequestModel
{
[Required]
[StringLength(36)]
public string UserId { get; set; }
public string Email { get; set; }
[Required]
[StringLength(36)]
public string CipherId { get; set; }
@ -25,7 +24,6 @@ namespace Bit.Api.Models
public Share ToShare(Share existingShare)
{
existingShare.UserId = new Guid(UserId);
existingShare.CipherId = new Guid(CipherId);
existingShare.Key = Key;

View File

@ -8,6 +8,8 @@ namespace Bit.Core.Services
{
Task SaveAsync(Cipher cipher);
Task DeleteAsync(Cipher cipher);
Task ImportCiphersAsync(List<Cipher> folders, List<Cipher> ciphers, IEnumerable<KeyValuePair<int, int>> folderRelationships);
Task ImportCiphersAsync(List<Cipher> folders, List<Cipher> ciphers,
IEnumerable<KeyValuePair<int, int>> folderRelationships);
Task ShareAsync(Share share, string email);
}
}

View File

@ -10,13 +10,19 @@ namespace Bit.Core.Services
public class CipherService : ICipherService
{
private readonly ICipherRepository _cipherRepository;
private readonly IShareRepository _shareRepository;
private readonly IUserRepository _userRepository;
private readonly IPushService _pushService;
public CipherService(
ICipherRepository cipherRepository,
IShareRepository shareRepository,
IUserRepository userRepository,
IPushService pushService)
{
_cipherRepository = cipherRepository;
_shareRepository = shareRepository;
_userRepository = userRepository;
_pushService = pushService;
}
@ -84,5 +90,24 @@ namespace Bit.Core.Services
await _pushService.PushSyncCiphersAsync(userId.Value);
}
}
public async Task ShareAsync(Share share, string email)
{
// TODO: Make sure share does not already exist between these two users.
var user = await _userRepository.GetByEmailAsync(email);
if(user == null)
{
return;
}
share.UserId = user.Id;
// TODO: Permissions and status
share.Permissions = null;
share.Status = Enums.ShareStatusType.Accepted;
await _shareRepository.CreateAsync(share);
}
}
}