From 59d3d47df7ba46ba92eef04a3bed27b9228eb118 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Sun, 16 Jun 2019 15:17:39 +0000 Subject: [PATCH] Fixed issue where Genre records were not being retrieved and added scope permissions for Genre and Year endpoints --- Controllers/v1/GenreController.cs | 2 ++ Controllers/v1/SongCompressedDataControllers.cs | 1 - Controllers/v1/YearController.cs | 2 ++ Database/Repositories/GenreRepository.cs | 10 ++-------- Startup.cs | 10 ++++++++++ 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Controllers/v1/GenreController.cs b/Controllers/v1/GenreController.cs index 25b604f..dd335d0 100644 --- a/Controllers/v1/GenreController.cs +++ b/Controllers/v1/GenreController.cs @@ -34,6 +34,7 @@ namespace Icarus.Controllers.V1 #region HTTP Routes [HttpGet] + [Authorize("read:genre")] public IActionResult Get() { var genres = new List(); @@ -55,6 +56,7 @@ namespace Icarus.Controllers.V1 } [HttpGet("{id}")] + [Authorize("read:genre")] public IActionResult Get(int id) { var genre = new Genre diff --git a/Controllers/v1/SongCompressedDataControllers.cs b/Controllers/v1/SongCompressedDataControllers.cs index f46b0ac..47e9e13 100644 --- a/Controllers/v1/SongCompressedDataControllers.cs +++ b/Controllers/v1/SongCompressedDataControllers.cs @@ -23,7 +23,6 @@ namespace Icarus.Controllers.V1 { #region Fields private IConfiguration _config; - private SongManager _songMgr; private string _songTempDir; private string _archiveDir; #endregion diff --git a/Controllers/v1/YearController.cs b/Controllers/v1/YearController.cs index 0592e5f..fe7ccc1 100644 --- a/Controllers/v1/YearController.cs +++ b/Controllers/v1/YearController.cs @@ -34,6 +34,7 @@ namespace Icarus.Controller.V1 #region HTTP Routes [HttpGet] + [Authorize("read:year")] public IActionResult Get() { var yearValues = new List(); @@ -55,6 +56,7 @@ namespace Icarus.Controller.V1 } [HttpGet("{id}")] + [Authorize("read:year")] public IActionResult Get(int id) { var year = new Year diff --git a/Database/Repositories/GenreRepository.cs b/Database/Repositories/GenreRepository.cs index db47810..d92aca0 100644 --- a/Database/Repositories/GenreRepository.cs +++ b/Database/Repositories/GenreRepository.cs @@ -78,7 +78,7 @@ namespace Icarus.Database.Repositories conn.Open(); var query = "SELECT gnr.*, COUNT(*) AS SongCount FROM Genre " + - "gnr LEFt JOIN Song sng ON gnr.GenreId=sng.GenreId " + + "gnr LEFT JOIN Song sng ON gnr.GenreId=sng.GenreId " + "GROUP BY gnr.GenreId"; using (var cmd = new MySqlCommand(query, conn)) @@ -449,13 +449,7 @@ namespace Icarus.Database.Repositories { using (var reader = cmd.ExecuteReader()) { - var genres = ParseData(reader); - - if (genres.Count > 0) - { - _logger.Info("Genres records"); - return true; - } + return reader.HasRows; } } } diff --git a/Startup.cs b/Startup.cs index d94ed58..787c341 100644 --- a/Startup.cs +++ b/Startup.cs @@ -93,6 +93,16 @@ namespace Icarus .Requirements .Add(new HasScopeRequirement("read:albums", domain))); + options.AddPolicy("read:genre", policy => + policy + .Requirements + .Add(new HasScopeRequirement("read:genre", domain))); + + options.AddPolicy("read:year", policy => + policy + .Requirements + .Add(new HasScopeRequirement("read:year", domain))); + options.AddPolicy("stream:songs", policy => policy .Requirements