mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
remove old share solution code
This commit is contained in:
@ -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]
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Domains;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ShareRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
[StringLength(36)]
|
||||
public string CipherId { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
public Share ToShare(Guid sharerUserId)
|
||||
{
|
||||
return ToShare(new Share
|
||||
{
|
||||
SharerUserId = sharerUserId
|
||||
});
|
||||
}
|
||||
|
||||
public Share ToShare(Share existingShare)
|
||||
{
|
||||
existingShare.CipherId = new Guid(CipherId);
|
||||
existingShare.Key = Key;
|
||||
|
||||
return existingShare;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
@ -19,7 +18,6 @@ namespace Bit.Api.Models
|
||||
Type = cipher.Type;
|
||||
Favorite = cipher.Favorite;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
Key = cipher.Key;
|
||||
|
||||
switch(cipher.Type)
|
||||
{
|
||||
@ -38,21 +36,7 @@ namespace Bit.Api.Models
|
||||
public string FolderId { get; set; }
|
||||
public Core.Enums.CipherType Type { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public string Key { get; set; }
|
||||
public dynamic Data { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
}
|
||||
|
||||
public class CipherShareResponseModel : CipherResponseModel
|
||||
{
|
||||
public CipherShareResponseModel(CipherShare cipherShare, Guid userId)
|
||||
: base(cipherShare, userId, "cipherShare")
|
||||
{
|
||||
ReadOnly = cipherShare.ReadOnly;
|
||||
Status = cipherShare.Status;
|
||||
}
|
||||
|
||||
public bool ReadOnly { get; set; }
|
||||
public Core.Enums.ShareStatusType? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class LoginResponseModel : ResponseModel
|
||||
{
|
||||
public LoginResponseModel(Cipher cipher, Guid userId, string obj = "login")
|
||||
: base("login")
|
||||
: base(obj)
|
||||
{
|
||||
if(cipher == null)
|
||||
{
|
||||
@ -30,7 +29,6 @@ namespace Bit.Api.Models
|
||||
Password = data.Password;
|
||||
Notes = data.Notes;
|
||||
RevisionDate = cipher.RevisionDate;
|
||||
Key = cipher.Key;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
@ -42,22 +40,8 @@ namespace Bit.Api.Models
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
// Expandables
|
||||
public FolderResponseModel Folder { get; set; }
|
||||
}
|
||||
|
||||
public class LoginShareResponseModel : LoginResponseModel
|
||||
{
|
||||
public LoginShareResponseModel(CipherShare cipherShare, Guid userId)
|
||||
: base(cipherShare, userId, "loginShare")
|
||||
{
|
||||
ReadOnly = cipherShare.ReadOnly;
|
||||
Status = cipherShare.Status;
|
||||
}
|
||||
|
||||
public bool ReadOnly { get; set; }
|
||||
public Core.Enums.ShareStatusType? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Bit.Core.Domains;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class ShareResponseModel : ResponseModel
|
||||
{
|
||||
public ShareResponseModel(Share share)
|
||||
: base("share")
|
||||
{
|
||||
if(share == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(share));
|
||||
}
|
||||
|
||||
Id = share.Id.ToString();
|
||||
UserId = share.UserId.ToString();
|
||||
SharerUserId = share.SharerUserId.ToString();
|
||||
CipherId = share.CipherId.ToString();
|
||||
Key = Key;
|
||||
ReadOnly = share.ReadOnly;
|
||||
Status = share.Status;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string SharerUserId { get; set; }
|
||||
public string CipherId { get; set; }
|
||||
public string Key { get; set; }
|
||||
public bool ReadOnly { get; set; }
|
||||
public Core.Enums.ShareStatusType? Status { get; set; }
|
||||
}
|
||||
}
|
@ -79,7 +79,6 @@ namespace Bit.Api
|
||||
services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>();
|
||||
services.AddSingleton<IDeviceRepository, SqlServerRepos.DeviceRepository>();
|
||||
services.AddSingleton<IGrantRepository, SqlServerRepos.GrantRepository>();
|
||||
services.AddSingleton<IShareRepository, SqlServerRepos.ShareRepository>();
|
||||
|
||||
// Context
|
||||
services.AddScoped<CurrentContext>();
|
||||
|
Reference in New Issue
Block a user