mirror of
https://github.com/bitwarden/server
synced 2025-12-14 15:23:42 +00:00
[PM-14378] SecurityTask Authorization Handler (#5039)
* [PM-14378] Introduce GetCipherPermissionsForOrganization query for Dapper CipherRepository * [PM-14378] Introduce GetCipherPermissionsForOrganization method for Entity Framework * [PM-14378] Add integration tests for new repository method * [PM-14378] Introduce IGetCipherPermissionsForUserQuery CQRS query * [PM-14378] Introduce SecurityTaskOperationRequirement * [PM-14378] Introduce SecurityTaskAuthorizationHandler.cs * [PM-14378] Introduce SecurityTaskOrganizationAuthorizationHandler.cs * [PM-14378] Register new authorization handlers * [PM-14378] Formatting * [PM-14378] Add unit tests for GetCipherPermissionsForUserQuery * [PM-15378] Cleanup SecurityTaskAuthorizationHandler and add tests * [PM-14378] Add tests for SecurityTaskOrganizationAuthorizationHandler * [PM-14378] Formatting * [PM-14378] Update date in migration file * [PM-14378] Add missing awaits * [PM-14378] Bump migration script date * [PM-14378] Remove Unassigned property from OrganizationCipherPermission as it was making the query too complicated * [PM-14378] Update sproc to use Union All to improve query performance * [PM-14378] Bump migration script date
This commit is contained in:
@@ -302,6 +302,52 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<OrganizationCipherPermission>>
|
||||
GetCipherPermissionsForOrganizationAsync(Guid organizationId, Guid userId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new CipherOrganizationPermissionsQuery(organizationId, userId).Run(dbContext);
|
||||
|
||||
ICollection<OrganizationCipherPermission> permissions;
|
||||
|
||||
// SQLite does not support the GROUP BY clause
|
||||
if (dbContext.Database.IsSqlite())
|
||||
{
|
||||
permissions = (await query.ToListAsync())
|
||||
.GroupBy(c => new { c.Id, c.OrganizationId })
|
||||
.Select(g => new OrganizationCipherPermission
|
||||
{
|
||||
Id = g.Key.Id,
|
||||
OrganizationId = g.Key.OrganizationId,
|
||||
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
|
||||
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
|
||||
Edit = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
|
||||
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var groupByQuery = from p in query
|
||||
group p by new { p.Id, p.OrganizationId }
|
||||
into g
|
||||
select new OrganizationCipherPermission
|
||||
{
|
||||
Id = g.Key.Id,
|
||||
OrganizationId = g.Key.OrganizationId,
|
||||
Read = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Read))),
|
||||
ViewPassword = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.ViewPassword))),
|
||||
Edit = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Edit))),
|
||||
Manage = Convert.ToBoolean(g.Max(c => Convert.ToInt32(c.Manage))),
|
||||
};
|
||||
permissions = await groupByQuery.ToListAsync();
|
||||
}
|
||||
|
||||
return permissions;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CipherDetails> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
|
||||
Reference in New Issue
Block a user