1
0
mirror of https://github.com/bitwarden/server synced 2025-12-25 04:33:26 +00: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

@@ -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;
}
}
}
}