1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

remove old share solution code

This commit is contained in:
Kyle Spearrin
2017-02-28 22:51:29 -05:00
parent 321183c570
commit acb1fc0be5
17 changed files with 19 additions and 365 deletions

View File

@ -31,25 +31,25 @@ namespace Bit.Api.Controllers
}
[HttpGet("{id}")]
public async Task<CipherShareResponseModel> Get(string id)
public async Task<CipherResponseModel> Get(string id)
{
var userId = _userService.GetProperUserId(User).Value;
var cipher = await _cipherRepository.GetShareByIdAsync(new Guid(id), userId);
var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
if(cipher == null)
{
throw new NotFoundException();
}
return new CipherShareResponseModel(cipher, userId);
return new CipherResponseModel(cipher, userId);
}
[HttpGet("")]
public async Task<ListResponseModel<CipherShareResponseModel>> Get()
public async Task<ListResponseModel<CipherResponseModel>> Get()
{
var userId = _userService.GetProperUserId(User).Value;
var ciphers = await _cipherRepository.GetManyShareByUserIdAsync(userId);
var responses = ciphers.Select(c => new CipherShareResponseModel(c, userId));
return new ListResponseModel<CipherShareResponseModel>(responses);
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
var responses = ciphers.Select(c => new CipherResponseModel(c, userId));
return new ListResponseModel<CipherResponseModel>(responses);
}
[Obsolete]

View File

@ -33,29 +33,29 @@ namespace Bit.Api.Controllers
}
[HttpGet("{id}")]
public async Task<LoginShareResponseModel> Get(string id, string[] expand = null)
public async Task<LoginResponseModel> Get(string id, string[] expand = null)
{
var userId = _userService.GetProperUserId(User).Value;
var login = await _cipherRepository.GetShareByIdAsync(new Guid(id), userId);
var login = await _cipherRepository.GetByIdAsync(new Guid(id), userId);
if(login == null || login.Type != Core.Enums.CipherType.Login)
{
throw new NotFoundException();
}
var response = new LoginShareResponseModel(login, userId);
var response = new LoginResponseModel(login, userId);
await ExpandAsync(login, response, expand, null, userId);
return response;
}
[HttpGet("")]
public async Task<ListResponseModel<LoginShareResponseModel>> Get(string[] expand = null)
public async Task<ListResponseModel<LoginResponseModel>> Get(string[] expand = null)
{
var userId = _userService.GetProperUserId(User).Value;
var logins = await _cipherRepository.GetManyShareByTypeAndUserIdAsync(Core.Enums.CipherType.Login,
var logins = await _cipherRepository.GetManyByTypeAndUserIdAsync(Core.Enums.CipherType.Login,
userId);
var responses = logins.Select(s => new LoginShareResponseModel(s, userId)).ToList();
var responses = logins.Select(s => new LoginResponseModel(s, userId)).ToList();
await ExpandManyAsync(logins, responses, expand, null, userId);
return new ListResponseModel<LoginShareResponseModel>(responses);
return new ListResponseModel<LoginResponseModel>(responses);
}
[HttpPost("")]
@ -119,8 +119,8 @@ namespace Bit.Api.Controllers
}
}
private async Task ExpandManyAsync<TResponseModel>(IEnumerable<Cipher> logins, ICollection<TResponseModel> responses,
string[] expand, IEnumerable<Cipher> folders, Guid userId) where TResponseModel : LoginResponseModel
private async Task ExpandManyAsync(IEnumerable<Cipher> logins, ICollection<LoginResponseModel> responses,
string[] expand, IEnumerable<Cipher> folders, Guid userId)
{
if(expand == null || expand.Count() == 0)
{

View File

@ -1,83 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Bit.Core.Repositories;
using Microsoft.AspNetCore.Authorization;
using Bit.Api.Models;
using Bit.Core.Exceptions;
using Bit.Core.Services;
using System.Collections.Generic;
namespace Bit.Api.Controllers
{
[Route("shares")]
[Authorize("Application")]
public class SharesController : Controller
{
private readonly IShareRepository _shareRepository;
private readonly IUserService _userService;
private readonly ICipherService _cipherService;
public SharesController(
IShareRepository shareRepository,
IUserService userService,
ICipherService cipherService)
{
_shareRepository = shareRepository;
_userService = userService;
_cipherService = cipherService;
}
[HttpGet("{id}")]
public async Task<ShareResponseModel> Get(string id)
{
var userId = _userService.GetProperUserId(User).Value;
var share = await _shareRepository.GetByIdAsync(new Guid(id), userId);
if(share == null)
{
throw new NotFoundException();
}
return new ShareResponseModel(share);
}
//[HttpGet("cipher/{cipherId}")]
//public async Task<IEnumerable<ShareResponseModel>> GetCipher(string cipherId)
//{
// var userId = _userService.GetProperUserId(User).Value;
// var share = await _shareRepository.GetByIdAsync(new Guid(cipherId), userId);
// if(share == null)
// {
// throw new NotFoundException();
// }
// return new ShareResponseModel(share);
//}
[HttpPost("")]
public async Task<ShareResponseModel> Post([FromBody]ShareRequestModel model)
{
var share = model.ToShare(_userService.GetProperUserId(User).Value);
await _cipherService.ShareAsync(share, model.Email);
var response = new ShareResponseModel(share);
return response;
}
[HttpDelete("{id}")]
[HttpPost("{id}/delete")]
public async Task Delete(string id)
{
var share = await _shareRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);
if(share == null)
{
throw new NotFoundException();
}
// TODO: permission checks
await _shareRepository.DeleteAsync(share);
}
}
}