Browse Source

Make permission module multitenant.

pull/216/head
Halil İbrahim Kalkan 9 years ago
parent
commit
d2997f98f5
  1. 113
      src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20180218143334_Made_Permission_Entity_MultiTenant.Designer.cs
  2. 24
      src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20180218143334_Made_Permission_Entity_MultiTenant.cs
  3. 2
      src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs
  4. 7
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/RolePermissionManagementProvider.cs
  5. 7
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserPermissionManagementProvider.cs
  6. 9
      src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/PermissionGrant.cs
  7. 10
      src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/PermissionManagementProvider.cs
  8. 52
      src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/20180218143233_Made_Permission_Entity_MultiTenant.Designer.cs
  9. 38
      src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/20180218143233_Made_Permission_Entity_MultiTenant.cs
  10. 51
      src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/AbpPermissionsDbContextModelSnapshot.cs
  11. 4
      src/Volo.Abp.Permissions.EntityFrameworkCore/Volo.Abp.Permissions.EntityFrameworkCore.csproj
  12. 18
      src/Volo.Abp.Permissions.EntityFrameworkCore/Volo/Abp/Permissions/EntityFrameworkCore/AbpPermissionsDbContextFactory.cs

113
src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20180218143334_Made_Permission_Entity_MultiTenant.Designer.cs

@ -0,0 +1,113 @@
// <auto-generated />
using AbpDesk.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using System;
namespace AbpDesk.EntityFrameworkCore.Migrations
{
[DbContext(typeof(AbpDeskDbContext))]
[Migration("20180218143334_Made_Permission_Entity_MultiTenant")]
partial class Made_Permission_Entity_MultiTenant
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.0.1-rtm-125")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("AbpDesk.Tickets.Ticket", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Body")
.HasMaxLength(65536);
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(256);
b.HasKey("Id");
b.ToTable("DskTickets");
});
modelBuilder.Entity("Volo.Abp.MultiTenancy.Tenant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64);
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("MtTenants");
});
modelBuilder.Entity("Volo.Abp.MultiTenancy.TenantConnectionString", b =>
{
b.Property<Guid>("TenantId");
b.Property<string>("Name")
.HasMaxLength(128);
b.Property<string>("Value")
.IsRequired()
.HasMaxLength(1024);
b.HasKey("TenantId", "Name");
b.ToTable("MtTenantConnectionStrings");
});
modelBuilder.Entity("Volo.Abp.Permissions.PermissionGrant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128);
b.Property<string>("ProviderKey")
.IsRequired()
.HasMaxLength(64);
b.Property<string>("ProviderName")
.IsRequired()
.HasMaxLength(64);
b.Property<Guid?>("TenantId");
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");
b.ToTable("AbpPermissionGrants");
});
modelBuilder.Entity("Volo.Abp.MultiTenancy.TenantConnectionString", b =>
{
b.HasOne("Volo.Abp.MultiTenancy.Tenant")
.WithMany("ConnectionStrings")
.HasForeignKey("TenantId")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}

24
src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/20180218143334_Made_Permission_Entity_MultiTenant.cs

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace AbpDesk.EntityFrameworkCore.Migrations
{
public partial class Made_Permission_Entity_MultiTenant : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "AbpPermissionGrants",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TenantId",
table: "AbpPermissionGrants");
}
}
}

2
src/AbpDesk/AbpDesk.EntityFrameworkCore/Migrations/AbpDeskDbContextModelSnapshot.cs

@ -90,6 +90,8 @@ namespace AbpDesk.EntityFrameworkCore.Migrations
.IsRequired()
.HasMaxLength(64);
b.Property<Guid?>("TenantId");
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");

7
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/RolePermissionManagementProvider.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Permissions;
namespace Volo.Abp.Identity
@ -17,10 +18,12 @@ namespace Volo.Abp.Identity
public RolePermissionManagementProvider(
IPermissionGrantRepository permissionGrantRepository,
IGuidGenerator guidGenerator,
IIdentityUserRepository identityUserRepository)
IIdentityUserRepository identityUserRepository,
ICurrentTenant currentTenant)
: base(
permissionGrantRepository,
guidGenerator)
guidGenerator,
currentTenant)
{
_identityUserRepository = identityUserRepository;
}

7
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserPermissionManagementProvider.cs

@ -1,4 +1,5 @@
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Permissions;
namespace Volo.Abp.Identity
@ -11,10 +12,12 @@ namespace Volo.Abp.Identity
public UserPermissionManagementProvider(IPermissionGrantRepository
permissionGrantRepository,
IGuidGenerator guidGenerator)
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant)
: base(
permissionGrantRepository,
guidGenerator)
guidGenerator,
currentTenant)
{
}

9
src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/PermissionGrant.cs

@ -1,11 +1,14 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Permissions
{
public class PermissionGrant : Entity<Guid>
public class PermissionGrant : Entity<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
[NotNull]
public virtual string Name { get; protected set; }
@ -24,7 +27,8 @@ namespace Volo.Abp.Permissions
Guid id,
[NotNull] string name,
[NotNull] string providerName ,
[NotNull] string providerKey)
[NotNull] string providerKey,
Guid? tenantId = null)
{
Check.NotNull(name, nameof(name));
@ -32,6 +36,7 @@ namespace Volo.Abp.Permissions
Name = name;
ProviderName = providerName;
ProviderKey = providerKey;
TenantId = tenantId;
}
}
}

10
src/Volo.Abp.Permissions.Domain/Volo/Abp/Permissions/PermissionManagementProvider.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Permissions
{
@ -12,12 +13,16 @@ namespace Volo.Abp.Permissions
protected IGuidGenerator GuidGenerator { get; }
protected ICurrentTenant CurrentTenant { get; }
protected PermissionManagementProvider(
IPermissionGrantRepository permissionGrantRepository,
IGuidGenerator guidGenerator)
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant)
{
PermissionGrantRepository = permissionGrantRepository;
GuidGenerator = guidGenerator;
CurrentTenant = currentTenant;
}
@ -47,7 +52,8 @@ namespace Volo.Abp.Permissions
GuidGenerator.Create(),
name,
Name,
providerKey
providerKey,
CurrentTenant.Id
)
);
}

52
src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/20180218143233_Made_Permission_Entity_MultiTenant.Designer.cs

@ -0,0 +1,52 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using System;
using Volo.Abp.Permissions.EntityFrameworkCore;
namespace Volo.Abp.Permissions.EntityFrameworkCore.Migrations
{
[DbContext(typeof(AbpPermissionsDbContext))]
[Migration("20180218143233_Made_Permission_Entity_MultiTenant")]
partial class Made_Permission_Entity_MultiTenant
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.0.1-rtm-125")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Volo.Abp.Permissions.PermissionGrant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128);
b.Property<string>("ProviderKey")
.IsRequired()
.HasMaxLength(64);
b.Property<string>("ProviderName")
.IsRequired()
.HasMaxLength(64);
b.Property<Guid?>("TenantId");
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");
b.ToTable("AbpPermissionGrants");
});
#pragma warning restore 612, 618
}
}
}

38
src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/20180218143233_Made_Permission_Entity_MultiTenant.cs

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace Volo.Abp.Permissions.EntityFrameworkCore.Migrations
{
public partial class Made_Permission_Entity_MultiTenant : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AbpPermissionGrants",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
Name = table.Column<string>(maxLength: 128, nullable: false),
ProviderKey = table.Column<string>(maxLength: 64, nullable: false),
ProviderName = table.Column<string>(maxLength: 64, nullable: false),
TenantId = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpPermissionGrants", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AbpPermissionGrants_Name_ProviderName_ProviderKey",
table: "AbpPermissionGrants",
columns: new[] { "Name", "ProviderName", "ProviderKey" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AbpPermissionGrants");
}
}
}

51
src/Volo.Abp.Permissions.EntityFrameworkCore/Migrations/AbpPermissionsDbContextModelSnapshot.cs

@ -0,0 +1,51 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using System;
using Volo.Abp.Permissions.EntityFrameworkCore;
namespace Volo.Abp.Permissions.EntityFrameworkCore.Migrations
{
[DbContext(typeof(AbpPermissionsDbContext))]
partial class AbpPermissionsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.0.1-rtm-125")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Volo.Abp.Permissions.PermissionGrant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128);
b.Property<string>("ProviderKey")
.IsRequired()
.HasMaxLength(64);
b.Property<string>("ProviderName")
.IsRequired()
.HasMaxLength(64);
b.Property<Guid?>("TenantId");
b.HasKey("Id");
b.HasIndex("Name", "ProviderName", "ProviderKey");
b.ToTable("AbpPermissionGrants");
});
#pragma warning restore 612, 618
}
}
}

4
src/Volo.Abp.Permissions.EntityFrameworkCore/Volo.Abp.Permissions.EntityFrameworkCore.csproj

@ -18,4 +18,8 @@
<ProjectReference Include="..\Volo.Abp.Permissions.Domain\Volo.Abp.Permissions.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
</ItemGroup>
</Project>

18
src/Volo.Abp.Permissions.EntityFrameworkCore/Volo/Abp/Permissions/EntityFrameworkCore/AbpPermissionsDbContextFactory.cs

@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace Volo.Abp.Permissions.EntityFrameworkCore
{
/* This class is needed for EF Core command line tooling */
public class AbpPermissionsDbContextFactory : IDesignTimeDbContextFactory<AbpPermissionsDbContext>
{
public AbpPermissionsDbContext CreateDbContext(string[] args)
{
//TODO: Remove all SqlServer references from EFCore packages and find a way of creating factory inside this.
var builder = new DbContextOptionsBuilder<AbpPermissionsDbContext>();
builder.UseSqlServer("Server=localhost;Database=AbpDesk;Trusted_Connection=True;");
return new AbpPermissionsDbContext(builder.Options);
}
}
}
Loading…
Cancel
Save