Browse Source
* Return collection with highest permission levels
* Revert "Return collection with highest permission levels"
This reverts commit 06e0f3b73e.
* Combine duplicate collectionDetails
* Update EF to combine duplicate CollectionDetails
* Delete unneeded using statements
pull/1490/head
7 changed files with 161 additions and 17 deletions
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
using System.Linq; |
||||
using System; |
||||
using Bit.Core.Models.Data; |
||||
|
||||
namespace Bit.Core.Repositories.EntityFramework.Queries |
||||
{ |
||||
public class CollectionReadByIdUserId : CollectionReadByUserId |
||||
{ |
||||
private readonly Guid _id; |
||||
|
||||
public CollectionReadByIdUserId(Guid id, Guid userId) : base(userId) |
||||
{ |
||||
_id = id; |
||||
} |
||||
|
||||
public override IQueryable<CollectionDetails> Run(DatabaseContext dbContext) |
||||
{ |
||||
var query = base.Run(dbContext); |
||||
return query.Where(c => c.Id == _id); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
using System.Linq; |
||||
using System; |
||||
using Bit.Core.Models.Data; |
||||
|
||||
namespace Bit.Core.Repositories.EntityFramework.Queries |
||||
{ |
||||
public class CollectionReadByUserId : UserCollectionDetailsQuery |
||||
{ |
||||
private readonly Guid _userId; |
||||
|
||||
public CollectionReadByUserId(Guid userId) : base(userId) |
||||
{ |
||||
_userId = userId; |
||||
} |
||||
|
||||
public override IQueryable<CollectionDetails> Run(DatabaseContext dbContext) |
||||
{ |
||||
var query = base.Run(dbContext); |
||||
return query |
||||
.GroupBy(c => c.Id) |
||||
.Select(g => new CollectionDetails |
||||
{ |
||||
Id = g.Key, |
||||
OrganizationId = g.FirstOrDefault().OrganizationId, |
||||
Name = g.FirstOrDefault().Name, |
||||
ExternalId = g.FirstOrDefault().ExternalId, |
||||
CreationDate = g.FirstOrDefault().CreationDate, |
||||
RevisionDate = g.FirstOrDefault().RevisionDate, |
||||
ReadOnly = g.Min(c => c.ReadOnly), |
||||
HidePasswords = g.Min(c => c.HidePasswords) |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
IF OBJECT_ID('[dbo].[Collection_ReadByUserId]') IS NOT NULL |
||||
BEGIN |
||||
DROP PROCEDURE [dbo].[Collection_ReadByUserId] |
||||
END |
||||
GO |
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_ReadByUserId] |
||||
@UserId UNIQUEIDENTIFIER |
||||
AS |
||||
BEGIN |
||||
SET NOCOUNT ON |
||||
|
||||
SELECT |
||||
Id, |
||||
OrganizationId, |
||||
[Name], |
||||
CreationDate, |
||||
RevisionDate, |
||||
ExternalId, |
||||
MIN([ReadOnly]) AS [ReadOnly], |
||||
MIN([HidePasswords]) AS [HidePasswords] |
||||
FROM |
||||
[dbo].[UserCollectionDetails](@UserId) |
||||
GROUP BY |
||||
Id, |
||||
OrganizationId, |
||||
[Name], |
||||
CreationDate, |
||||
RevisionDate, |
||||
ExternalId |
||||
END |
||||
GO |
||||
|
||||
IF OBJECT_ID('[dbo].[Collection_ReadByIdUserId]') IS NOT NULL |
||||
BEGIN |
||||
DROP PROCEDURE [dbo].[Collection_ReadByIdUserId] |
||||
END |
||||
GO |
||||
|
||||
CREATE PROCEDURE [dbo].[Collection_ReadByIdUserId] |
||||
@Id UNIQUEIDENTIFIER, |
||||
@UserId UNIQUEIDENTIFIER |
||||
AS |
||||
BEGIN |
||||
SET NOCOUNT ON |
||||
SELECT |
||||
Id, |
||||
OrganizationId, |
||||
[Name], |
||||
CreationDate, |
||||
RevisionDate, |
||||
ExternalId, |
||||
MIN([ReadOnly]) AS [ReadOnly], |
||||
MIN([HidePasswords]) AS [HidePasswords] |
||||
FROM |
||||
[dbo].[UserCollectionDetails](@UserId) |
||||
WHERE |
||||
[Id] = @Id |
||||
GROUP BY |
||||
Id, |
||||
OrganizationId, |
||||
[Name], |
||||
CreationDate, |
||||
RevisionDate, |
||||
ExternalId |
||||
END |
||||
Loading…
Reference in new issue