Cleaning up code convention inconsistencies
This commit is contained in:
@@ -10,16 +10,15 @@ namespace Icarus.Authorization.Handlers
|
||||
{
|
||||
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
|
||||
{
|
||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
|
||||
HasScopeRequirement requirement)
|
||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
|
||||
{
|
||||
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var scopes = context.User.FindFirst(c => c.Type == "scope" &&
|
||||
c.Issuer == requirement.Issuer).Value.Split(' ');
|
||||
var scopes = context.User.FindFirst(c =>
|
||||
c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
|
||||
|
||||
if (scopes.Any(s => s == requirement.Scope))
|
||||
{
|
||||
|
||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
||||
{
|
||||
public DbSet<Album> Albums { get; set; }
|
||||
|
||||
public AlbumContext(DbContextOptions<AlbumContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
||||
{
|
||||
public DbSet<Artist> Artists { get; set; }
|
||||
|
||||
public ArtistContext(DbContextOptions<ArtistContext> options)
|
||||
: base (options)
|
||||
{ }
|
||||
public ArtistContext(DbContextOptions<ArtistContext> options) : base (options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
@@ -13,10 +13,7 @@ namespace Icarus.Database.Contexts
|
||||
public class GenreContext : DbContext
|
||||
{
|
||||
public DbSet<Genre> Genres { get; set; }
|
||||
|
||||
public GenreContext(DbContextOptions<GenreContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
||||
public DbSet<Song> Songs { get; set; }
|
||||
|
||||
|
||||
public SongContext(DbContextOptions<SongContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
public SongContext(DbContextOptions<SongContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
|
||||
public UserContext(DbContextOptions<UserContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
public UserContext(DbContextOptions<UserContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
||||
{
|
||||
public DbSet<Year> YearValues { get; set; }
|
||||
|
||||
public YearContext(DbContextOptions<YearContext> options)
|
||||
: base(options)
|
||||
{ }
|
||||
public YearContext(DbContextOptions<YearContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
+2
-3
@@ -35,14 +35,13 @@ namespace Icarus
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>()
|
||||
.UseUrls("http://localhost:5002")
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
|
||||
})
|
||||
.UseNLog() ;
|
||||
.UseNLog();
|
||||
}
|
||||
}
|
||||
|
||||
+19
-34
@@ -59,53 +59,43 @@ namespace Icarus
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("download:songs", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("download:songs", domain)));
|
||||
|
||||
options.AddPolicy("upload:songs", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("upload:songs", domain)));
|
||||
|
||||
options.AddPolicy("delete:songs", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("delete:songs", domain)));
|
||||
|
||||
options.AddPolicy("read:song_details", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("read:song_details", domain)));
|
||||
|
||||
options.AddPolicy("update:songs", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("update:songs", domain)));
|
||||
|
||||
options.AddPolicy("read:artists", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("read:artists", domain)));
|
||||
|
||||
options.AddPolicy("read:albums", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("read:albums", domain)));
|
||||
|
||||
options.AddPolicy("read:genre", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("read:genre", domain)));
|
||||
|
||||
options.AddPolicy("read:year", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("read:year", domain)));
|
||||
|
||||
options.AddPolicy("stream:songs", policy =>
|
||||
policy
|
||||
.Requirements
|
||||
policy.Requirements
|
||||
.Add(new HasScopeRequirement("stream:songs", domain)));
|
||||
});
|
||||
|
||||
@@ -115,28 +105,22 @@ namespace Icarus
|
||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
||||
new SongRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new SongRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
||||
new AlbumRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new AlbumRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
||||
new ArtistRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new ArtistRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
||||
new GenreRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new GenreRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
||||
new YearRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new YearRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
||||
new UserRepository(Configuration
|
||||
.GetConnectionString("DefaultConnection"))));
|
||||
new UserRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
|
||||
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
||||
@@ -146,7 +130,7 @@ namespace Icarus
|
||||
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
@@ -155,7 +139,8 @@ namespace Icarus
|
||||
}
|
||||
else
|
||||
{
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
// The default HSTS value is 30 days.
|
||||
// You may want to change this for production scenarios
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user