1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-13 21:57:30 -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

@ -10,7 +10,6 @@ namespace Bit.Core.Domains
public Guid? FolderId { get; set; }
public Enums.CipherType Type { get; set; }
public bool Favorite { get; set; }
public string Key { get; set; }
public string Data { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;

View File

@ -1,23 +0,0 @@
using System;
using Bit.Core.Utilities;
namespace Bit.Core.Domains
{
public class Share : IDataObject<Guid>
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public Guid SharerUserId { get; set; }
public Guid CipherId { get; set; }
public string Key { get; set; }
public bool ReadOnly { get; set; }
public Enums.ShareStatusType Status { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
public void SetNewId()
{
Id = CoreHelpers.GenerateComb();
}
}
}

View File

@ -1,10 +0,0 @@
using Bit.Core.Domains;
namespace Bit.Core.Models.Data
{
public class CipherShare : Cipher
{
public bool ReadOnly { get; internal set; }
public Enums.ShareStatusType? Status { get; internal set; }
}
}

View File

@ -2,20 +2,16 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.Core.Domains;
using Bit.Core.Models.Data;
namespace Bit.Core.Repositories
{
public interface ICipherRepository : IRepository<Cipher, Guid>
{
Task<Cipher> GetByIdAsync(Guid id, Guid userId);
Task<CipherShare> GetShareByIdAsync(Guid id, Guid userId);
Task<ICollection<Cipher>> GetManyByUserIdAsync(Guid userId);
Task<ICollection<CipherShare>> GetManyShareByUserIdAsync(Guid userId);
Task<ICollection<Cipher>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
Task<ICollection<CipherShare>> GetManyShareByTypeAndUserIdAsync(Enums.CipherType type, Guid userId);
Task<Tuple<ICollection<Cipher>, ICollection<Guid>>>
GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(DateTime sinceRevisionDate, Guid userId);
Task<Tuple<ICollection<Cipher>, ICollection<Guid>>> GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(
DateTime sinceRevisionDate, Guid userId);
Task UpdateUserEmailPasswordAndCiphersAsync(User user, IEnumerable<Cipher> ciphers);
Task CreateAsync(IEnumerable<Cipher> ciphers);
}

View File

@ -1,13 +0,0 @@
using System;
using Bit.Core.Domains;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Bit.Core.Repositories
{
public interface IShareRepository : IRepository<Share, Guid>
{
Task<Share> GetByIdAsync(Guid id, Guid userId);
Task<ICollection<Share>> GetManyByCipherId(Guid id);
}
}

View File

@ -7,7 +7,6 @@ using DataTableProxy;
using Bit.Core.Domains;
using System.Data;
using Dapper;
using Bit.Core.Models.Data;
namespace Bit.Core.Repositories.SqlServer
{
@ -32,19 +31,6 @@ namespace Bit.Core.Repositories.SqlServer
return cipher;
}
public async Task<CipherShare> GetShareByIdAsync(Guid id, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherShare>(
$"[{Schema}].[CipherShare_ReadById]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault(c => c.UserId == userId);
}
}
public async Task<ICollection<Cipher>> GetManyByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
@ -58,19 +44,6 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<ICollection<CipherShare>> GetManyShareByUserIdAsync(Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherShare>(
$"[{Schema}].[CipherShare_ReadByUserId]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
public async Task<ICollection<Cipher>> GetManyByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
@ -88,23 +61,6 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<ICollection<CipherShare>> GetManyShareByTypeAndUserIdAsync(Enums.CipherType type, Guid userId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherShare>(
$"[{Schema}].[CipherShare_ReadByTypeUserId]",
new
{
Type = type,
UserId = userId
},
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
public async Task<Tuple<ICollection<Cipher>, ICollection<Guid>>>
GetManySinceRevisionDateAndUserIdWithDeleteHistoryAsync(DateTime sinceRevisionDate, Guid userId)
{

View File

@ -1,46 +0,0 @@
using System;
using Bit.Core.Domains;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Data.SqlClient;
using Dapper;
using System.Data;
using System.Linq;
namespace Bit.Core.Repositories.SqlServer
{
public class ShareRepository : Repository<Share, Guid>, IShareRepository
{
public ShareRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString)
{ }
public ShareRepository(string connectionString)
: base(connectionString)
{ }
public async Task<Share> GetByIdAsync(Guid id, Guid userId)
{
var share = await GetByIdAsync(id);
if(share == null || (share.UserId != userId && share.SharerUserId != userId))
{
return null;
}
return share;
}
public async Task<ICollection<Share>> GetManyByCipherId(Guid cipherId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Share>(
$"[{Schema}].[Share_ReadByCipherId]",
new { CipherId = cipherId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
}
}

View File

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

View File

@ -10,18 +10,15 @@ 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;
}
@ -90,24 +87,5 @@ 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.ReadOnly = false;
share.Status = Enums.ShareStatusType.Accepted;
await _shareRepository.CreateAsync(share);
}
}
}