-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
5,334 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Bit.Core.Utilities; | ||
|
||
namespace Bit.Core.Entities; | ||
|
||
public class AccessPolicy : ITableObject<Guid> | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
// Object to grant access from | ||
public Guid? OrganizationUserId { get; set; } | ||
public Guid? GroupId { get; set; } | ||
public Guid? ServiceAccountId { get; set; } | ||
|
||
// Object to grant access to | ||
public Guid? GrantedProjectId { get; set; } | ||
public Guid? GrantedServiceAccountId { get; set; } | ||
|
||
// Access | ||
public bool Read { get; set; } | ||
public bool Write { get; set; } | ||
|
||
public DateTime CreationDate { get; set; } | ||
public DateTime RevisionDate { get; set; } | ||
|
||
public void SetNewId() | ||
{ | ||
Id = CoreHelpers.GenerateComb(); | ||
} | ||
} | ||
|
||
public abstract class BaseAccessPolicy | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
// Access | ||
public bool Read { get; set; } | ||
public bool Write { get; set; } | ||
|
||
public DateTime CreationDate { get; set; } | ||
public DateTime RevisionDate { get; set; } | ||
|
||
public void SetNewId() | ||
{ | ||
Id = CoreHelpers.GenerateComb(); | ||
} | ||
} | ||
|
||
public class UserProjectAccessPolicy : BaseAccessPolicy | ||
{ | ||
public Guid? OrganizationUserId { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
} | ||
|
||
public class UserServiceAccountAccessPolicy : BaseAccessPolicy | ||
{ | ||
public Guid? OrganizationUserId { get; set; } | ||
public Guid? GrantedServiceAccountId { get; set; } | ||
} | ||
|
||
public class GroupProjectAccessPolicy : BaseAccessPolicy | ||
{ | ||
public Guid? GroupId { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
} | ||
|
||
public class GroupServiceAccountAccessPolicy : BaseAccessPolicy | ||
{ | ||
public Guid? GroupId { get; set; } | ||
public Guid? GrantedServiceAccountId { get; set; } | ||
} | ||
|
||
public class ServiceAccountProjectAccessPolicy : BaseAccessPolicy | ||
{ | ||
public Guid? ServiceAccountId { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Bit.Core.Entities; | ||
|
||
namespace Bit.Core.Repositories; | ||
|
||
public interface IAccessPolicyRepository : IRepository<AccessPolicy, Guid> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Infrastructure.EntityFramework/Configurations/AccessPolicyEntityTypeConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Bit.Infrastructure.EntityFramework.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Bit.Infrastructure.EntityFramework.Configurations; | ||
|
||
public class AccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<AccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<AccessPolicy> builder) | ||
{ | ||
builder | ||
.HasDiscriminator<string>("Discriminator") | ||
.HasValue<UserProjectAccessPolicy>("user_project") | ||
.HasValue<UserServiceAccountAccessPolicy>("user_service_account") | ||
.HasValue<GroupProjectAccessPolicy>("group_project") | ||
.HasValue<GroupServiceAccountAccessPolicy>("group_service_account") | ||
.HasValue<ServiceAccountProjectAccessPolicy>("service_account_project"); | ||
|
||
builder | ||
.Property(s => s.Id) | ||
.ValueGeneratedNever(); | ||
|
||
builder | ||
.HasKey(s => s.Id) | ||
.IsClustered(); | ||
|
||
builder.ToTable(nameof(AccessPolicy)); | ||
} | ||
} | ||
|
||
public class UserProjectAccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<UserProjectAccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<UserProjectAccessPolicy> builder) | ||
{ | ||
builder | ||
.Property(e => e.OrganizationUserId) | ||
.HasColumnName(nameof(UserProjectAccessPolicy.OrganizationUserId)); | ||
|
||
builder | ||
.Property(e => e.GrantedProjectId) | ||
.HasColumnName(nameof(UserProjectAccessPolicy.GrantedProjectId)); | ||
} | ||
} | ||
|
||
public class UserServiceAccountAccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<UserServiceAccountAccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<UserServiceAccountAccessPolicy> builder) | ||
{ | ||
builder | ||
.Property(e => e.OrganizationUserId) | ||
.HasColumnName(nameof(UserServiceAccountAccessPolicy.OrganizationUserId)); | ||
|
||
builder | ||
.Property(e => e.GrantedServiceAccountId) | ||
.HasColumnName(nameof(UserServiceAccountAccessPolicy.GrantedServiceAccountId)); | ||
} | ||
} | ||
|
||
public class GroupProjectAccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<GroupProjectAccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<GroupProjectAccessPolicy> builder) | ||
{ | ||
builder | ||
.Property(e => e.GroupId) | ||
.HasColumnName(nameof(GroupProjectAccessPolicy.GroupId)); | ||
|
||
builder | ||
.Property(e => e.GrantedProjectId) | ||
.HasColumnName(nameof(GroupProjectAccessPolicy.GrantedProjectId)); | ||
} | ||
} | ||
|
||
public class GroupServiceAccountAccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<GroupServiceAccountAccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<GroupServiceAccountAccessPolicy> builder) | ||
{ | ||
builder | ||
.Property(e => e.GroupId) | ||
.HasColumnName(nameof(GroupServiceAccountAccessPolicy.GroupId)); | ||
|
||
builder | ||
.Property(e => e.GrantedServiceAccountId) | ||
.HasColumnName(nameof(GroupServiceAccountAccessPolicy.GrantedServiceAccountId)); | ||
} | ||
} | ||
|
||
public class ServiceAccountProjectAccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<ServiceAccountProjectAccessPolicy> | ||
{ | ||
public void Configure(EntityTypeBuilder<ServiceAccountProjectAccessPolicy> builder) | ||
{ | ||
builder | ||
.Property(e => e.ServiceAccountId) | ||
.HasColumnName(nameof(ServiceAccountProjectAccessPolicy.ServiceAccountId)); | ||
|
||
builder | ||
.Property(e => e.GrantedProjectId) | ||
.HasColumnName(nameof(ServiceAccountProjectAccessPolicy.GrantedProjectId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using AutoMapper; | ||
|
||
namespace Bit.Infrastructure.EntityFramework.Models; | ||
|
||
public class BaseAccessPolicy : Core.Entities.BaseAccessPolicy | ||
{ | ||
public string Discriminator { get; set; } | ||
} | ||
|
||
public class AccessPolicyMapperProfile : Profile | ||
{ | ||
public AccessPolicyMapperProfile() | ||
{ | ||
CreateMap<Core.Entities.AccessPolicy, AccessPolicy>().ReverseMap(); | ||
} | ||
} | ||
|
||
public class AccessPolicy : BaseAccessPolicy | ||
{ | ||
} | ||
|
||
public class UserProjectAccessPolicy : AccessPolicy | ||
{ | ||
public Guid? OrganizationUserId { get; set; } | ||
public virtual OrganizationUser OrganizationUser { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
public virtual Project GrantedProject { get; set; } | ||
} | ||
|
||
public class UserServiceAccountAccessPolicy : AccessPolicy | ||
{ | ||
public Guid? OrganizationUserId { get; set; } | ||
public virtual OrganizationUser OrganizationUser { get; set; } | ||
public Guid? GrantedServiceAccountId { get; set; } | ||
public virtual ServiceAccount GrantedServiceAccount { get; set; } | ||
} | ||
|
||
public class GroupProjectAccessPolicy : AccessPolicy | ||
{ | ||
public Guid? GroupId { get; set; } | ||
public virtual Group Group { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
public virtual Project GrantedProject { get; set; } | ||
} | ||
|
||
public class GroupServiceAccountAccessPolicy : AccessPolicy | ||
{ | ||
public Guid? GroupId { get; set; } | ||
public virtual Group Group { get; set; } | ||
public Guid? GrantedServiceAccountId { get; set; } | ||
public virtual ServiceAccount GrantedServiceAccount { get; set; } | ||
} | ||
|
||
public class ServiceAccountProjectAccessPolicy : AccessPolicy | ||
{ | ||
public Guid? ServiceAccountId { get; set; } | ||
public virtual ServiceAccount ServiceAccount { get; set; } | ||
public Guid? GrantedProjectId { get; set; } | ||
public virtual Project GrantedProject { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Infrastructure.EntityFramework/Repositories/AccessPolicyRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using AutoMapper; | ||
using Bit.Core.Repositories; | ||
using Bit.Infrastructure.EntityFramework.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using CoreAccessPolicy = Bit.Core.Entities.AccessPolicy; | ||
|
||
namespace Bit.Infrastructure.EntityFramework.Repositories; | ||
|
||
public class AccessPolicyRepository : IAccessPolicyRepository | ||
{ | ||
public AccessPolicyRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) | ||
{ | ||
} | ||
|
||
protected Func<DatabaseContext, DbSet<AccessPolicy>> GetDbSet { get; private set; } | ||
|
||
public Task<CoreAccessPolicy> GetByIdAsync(Guid id) => throw new NotImplementedException(); | ||
|
||
public Task<CoreAccessPolicy> CreateAsync(CoreAccessPolicy obj) => throw new NotImplementedException(); | ||
|
||
public Task ReplaceAsync(CoreAccessPolicy obj) => throw new NotImplementedException(); | ||
|
||
public Task UpsertAsync(CoreAccessPolicy obj) => throw new NotImplementedException(); | ||
|
||
public Task DeleteAsync(CoreAccessPolicy obj) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.