Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Refactored all Policy strings into their own constant file.

Joseph Milazzo793c13e1e63c
diff --git a/API/Constants/PolicyConstants.cs b/API/Constants/PolicyConstants.cs
new file mode 100644
index 000000000..d64a2bab6
--- /dev/null
+++ b/API/Constants/PolicyConstants.cs
@@ -0,0 +1,8 @@
+namespace API.Constants
+{
+ public static class PolicyConstants
+ {
+ public static readonly string AdminRole = "Admin";
+ public static readonly string PlebRole = "Pleb";
+ }
+}
\ No newline at end of file
diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs
index 6c8c74a5b..3610925e9 100644
--- a/API/Controllers/AccountController.cs
+++ b/API/Controllers/AccountController.cs
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
+using API.Constants;
using API.DTOs;
using API.Entities;
using API.Interfaces;
@@ -50,7 +51,7 @@ namespace API.Controllers
// TODO: Need a way to store Roles in enum and configure from there
- var role = registerDto.IsAdmin ? "Admin" : "Pleb";
+ var role = registerDto.IsAdmin ? PolicyConstants.AdminRole : PolicyConstants.PlebRole;
var roleResult = await _userManager.AddToRoleAsync(user, role);
if (!roleResult.Succeeded) return BadRequest(result.Errors);
diff --git a/API/Data/Seed.cs b/API/Data/Seed.cs
index 4bc4ebbc6..c03407e95 100644
--- a/API/Data/Seed.cs
+++ b/API/Data/Seed.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
+using API.Constants;
using API.Entities;
using Microsoft.AspNetCore.Identity;
@@ -11,8 +12,8 @@ namespace API.Data
{
var roles = new List<AppRole>
{
- new AppRole {Name = "Admin"},
- new AppRole {Name = "Pleb"}
+ new AppRole {Name = PolicyConstants.AdminRole},
+ new AppRole {Name = PolicyConstants.PlebRole}
};
foreach (var role in roles)
diff --git a/API/Extensions/IdentityServiceExtensions.cs b/API/Extensions/IdentityServiceExtensions.cs
index 9138ffbb8..2d2a235f5 100644
--- a/API/Extensions/IdentityServiceExtensions.cs
+++ b/API/Extensions/IdentityServiceExtensions.cs
@@ -1,4 +1,5 @@
using System.Text;
+using API.Constants;
using API.Data;
using API.Entities;
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -37,7 +38,7 @@ namespace API.Extensions
});
services.AddAuthorization(opt =>
{
- opt.AddPolicy("RequireAdminRole", policy => policy.RequireRole("Admin"));
+ opt.AddPolicy("RequireAdminRole", policy => policy.RequireRole(PolicyConstants.AdminRole));
});
return services;