1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -05:00

CipherDetails Edit property

This commit is contained in:
Kyle Spearrin
2017-05-06 23:23:01 -04:00
parent 3018655d7e
commit b039461ff4
20 changed files with 96 additions and 150 deletions

View File

@ -60,6 +60,7 @@ namespace Bit.Core.Models.Api
{
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Edit = cipher.Edit;
}
[Obsolete]
@ -69,6 +70,7 @@ namespace Bit.Core.Models.Api
public string FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
}
public class CipherDetailsResponseModel : CipherResponseModel
@ -115,15 +117,4 @@ namespace Bit.Core.Models.Api
public IEnumerable<Guid> CollectionIds { get; set; }
}
public class CipherFullDetailsResponseModel : CipherDetailsResponseModel
{
public CipherFullDetailsResponseModel(CipherFullDetails cipher, IEnumerable<CollectionCipher> collectionCiphers)
: base(cipher, collectionCiphers, "cipherFullDetails")
{
Edit = cipher.Edit;
}
public bool Edit { get; set; }
}
}

View File

@ -36,12 +36,14 @@ namespace Bit.Core.Models.Api
{
FolderId = cipher.FolderId?.ToString();
Favorite = cipher.Favorite;
Edit = cipher.Edit;
}
public string Id { get; set; }
public string OrganizationId { get; set; }
public string FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
public string Name { get; set; }
public string Uri { get; set; }
public string Username { get; set; }
@ -52,15 +54,4 @@ namespace Bit.Core.Models.Api
[Obsolete]
public FolderResponseModel Folder { get; set; }
}
public class LoginDetailsResponseModel : LoginResponseModel
{
public LoginDetailsResponseModel(CipherFullDetails cipher)
: base(cipher, "loginDetails")
{
Edit = cipher.Edit;
}
public bool Edit { get; set; }
}
}

View File

@ -7,5 +7,6 @@ namespace Core.Models.Data
{
public Guid? FolderId { get; set; }
public bool Favorite { get; set; }
public bool Edit { get; set; }
}
}

View File

@ -1,7 +0,0 @@
namespace Core.Models.Data
{
public class CipherFullDetails : CipherDetails
{
public bool Edit { get; set; }
}
}

View File

@ -9,7 +9,7 @@ namespace Bit.Core.Repositories
public interface ICipherRepository : IRepository<Cipher, Guid>
{
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
Task<CipherFullDetails> GetFullDetailsByIdAsync(Guid id, Guid userId);
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId);
Task<ICollection<CipherDetails>> GetManyByUserIdHasCollectionsAsync(Guid userId);
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);

View File

@ -11,6 +11,5 @@ namespace Bit.Core.Repositories
Task<ICollection<CollectionUser>> GetManyByOrganizationUserIdAsync(Guid orgUserId);
Task<ICollection<CollectionUserCollectionDetails>> GetManyDetailsByUserIdAsync(Guid userId);
Task<ICollection<CollectionUserUserDetails>> GetManyDetailsByCollectionIdAsync(Guid organizationId, Guid collectionId);
Task<bool> GetCanEditByUserIdCipherIdAsync(Guid userId, Guid cipherId);
}
}

View File

@ -35,16 +35,16 @@ namespace Bit.Core.Repositories.SqlServer
}
}
public async Task<CipherFullDetails> GetFullDetailsByIdAsync(Guid id, Guid userId)
public async Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<CipherFullDetails>(
$"[{Schema}].[CipherFullDetails_ReadByIdUserId]",
new { Id = id, UserId = userId },
var result = await connection.QueryFirstOrDefaultAsync<bool>(
$"[{Schema}].[Cipher_ReadCanEditByIdUserId]",
new { UserId = userId, CipherId = cipherId },
commandType: CommandType.StoredProcedure);
return results.FirstOrDefault();
return result;
}
}
@ -57,8 +57,11 @@ namespace Bit.Core.Repositories.SqlServer
new { UserId = userId },
commandType: CommandType.StoredProcedure);
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
// Return distinct Id results. If at least one of the grouped results allows edit, that we return it.
return results
.GroupBy(c => c.Id)
.Select(g => g.OrderByDescending(og => og.Edit).First())
.ToList();
}
}
@ -71,8 +74,11 @@ namespace Bit.Core.Repositories.SqlServer
new { UserId = userId },
commandType: CommandType.StoredProcedure);
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
// Return distinct Id results. If at least one of the grouped results allows edit, that we return it.
return results
.GroupBy(c => c.Id)
.Select(g => g.OrderByDescending(og => og.Edit).First())
.ToList();
}
}
@ -102,8 +108,11 @@ namespace Bit.Core.Repositories.SqlServer
},
commandType: CommandType.StoredProcedure);
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
// Return distinct Id results. If at least one of the grouped results allows edit, that we return it.
return results
.GroupBy(c => c.Id)
.Select(g => g.OrderByDescending(og => og.Edit).First())
.ToList();
}
}

View File

@ -59,18 +59,5 @@ namespace Bit.Core.Repositories.SqlServer
return results.ToList();
}
}
public async Task<bool> GetCanEditByUserIdCipherIdAsync(Guid userId, Guid cipherId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var result = await connection.QueryFirstOrDefaultAsync<bool>(
$"[{Schema}].[CollectionUser_ReadCanEditByCipherIdUserId]",
new { UserId = userId, CipherId = cipherId },
commandType: CommandType.StoredProcedure);
return result;
}
}
}
}

View File

@ -16,7 +16,6 @@ namespace Bit.Core.Services
private readonly IUserRepository _userRepository;
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly ICollectionUserRepository _collectionUserRepository;
private readonly ICollectionCipherRepository _collectionCipherRepository;
private readonly IPushService _pushService;
@ -26,7 +25,6 @@ namespace Bit.Core.Services
IUserRepository userRepository,
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
ICollectionUserRepository collectionUserRepository,
ICollectionCipherRepository collectionCipherRepository,
IPushService pushService)
{
@ -35,7 +33,6 @@ namespace Bit.Core.Services
_userRepository = userRepository;
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_collectionUserRepository = collectionUserRepository;
_collectionCipherRepository = collectionCipherRepository;
_pushService = pushService;
}
@ -237,7 +234,7 @@ namespace Bit.Core.Services
return true;
}
return await _collectionUserRepository.GetCanEditByUserIdCipherIdAsync(userId, cipher.Id);
return await _cipherRepository.GetCanEditByIdAsync(userId, cipher.Id);
}
}
}