mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -07:00
Small changes around the roles #865
This commit is contained in:
parent
3cc45b3022
commit
233c76813c
5 changed files with 28 additions and 6 deletions
|
@ -8,5 +8,6 @@
|
||||||
public const string PowerUser = nameof(PowerUser);
|
public const string PowerUser = nameof(PowerUser);
|
||||||
public const string RequestTv = nameof(RequestTv);
|
public const string RequestTv = nameof(RequestTv);
|
||||||
public const string RequestMovie = nameof(RequestMovie);
|
public const string RequestMovie = nameof(RequestMovie);
|
||||||
|
public const string Disabled = nameof(Disabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -185,7 +185,7 @@ namespace Ombi.Core.Senders
|
||||||
{
|
{
|
||||||
var sonarrSeason = sonarrEpisodes.Where(x => x.seasonNumber == season.SeasonNumber);
|
var sonarrSeason = sonarrEpisodes.Where(x => x.seasonNumber == season.SeasonNumber);
|
||||||
var sonarrEpCount = sonarrSeason.Count();
|
var sonarrEpCount = sonarrSeason.Count();
|
||||||
var ourRequestCount = season.Episodes.Count();
|
var ourRequestCount = season.Episodes.Count;
|
||||||
|
|
||||||
if (sonarrEpCount == ourRequestCount)
|
if (sonarrEpCount == ourRequestCount)
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,7 +81,6 @@ namespace Ombi.Store.Context
|
||||||
SaveChanges();
|
SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Check if templates exist
|
//Check if templates exist
|
||||||
var templates = NotificationTemplates.ToList();
|
var templates = NotificationTemplates.ToList();
|
||||||
//if (templates.Any())
|
//if (templates.Any())
|
||||||
|
|
|
@ -89,16 +89,32 @@ namespace Ombi.Controllers
|
||||||
var result = await UserManager.CreateAsync(userToCreate, user.Password);
|
var result = await UserManager.CreateAsync(userToCreate, user.Password);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
if (!await RoleManager.RoleExistsAsync(OmbiRoles.Admin))
|
await CreateRoles();
|
||||||
{
|
|
||||||
await RoleManager.CreateAsync(new IdentityRole(OmbiRoles.Admin));
|
|
||||||
}
|
|
||||||
await UserManager.AddToRoleAsync(userToCreate, OmbiRoles.Admin);
|
await UserManager.AddToRoleAsync(userToCreate, OmbiRoles.Admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task CreateRoles()
|
||||||
|
{
|
||||||
|
await CreateRole(OmbiRoles.AutoApproveMovie);
|
||||||
|
await CreateRole(OmbiRoles.Admin);
|
||||||
|
await CreateRole(OmbiRoles.AutoApproveTv);
|
||||||
|
await CreateRole(OmbiRoles.PowerUser);
|
||||||
|
await CreateRole(OmbiRoles.RequestMovie);
|
||||||
|
await CreateRole(OmbiRoles.RequestTv);
|
||||||
|
await CreateRole(OmbiRoles.Disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CreateRole(string role)
|
||||||
|
{
|
||||||
|
if (!await RoleManager.RoleExistsAsync(role))
|
||||||
|
{
|
||||||
|
await RoleManager.CreateAsync(new IdentityRole(role));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all users.
|
/// Gets all users.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Ombi.Core.Claims;
|
||||||
using Ombi.Models;
|
using Ombi.Models;
|
||||||
using Ombi.Models.Identity;
|
using Ombi.Models.Identity;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
|
@ -58,6 +59,11 @@ namespace Ombi.Controllers
|
||||||
{
|
{
|
||||||
var roles = await _userManager.GetRolesAsync(user);
|
var roles = await _userManager.GetRolesAsync(user);
|
||||||
|
|
||||||
|
if (roles.Contains(OmbiRoles.Disabled))
|
||||||
|
{
|
||||||
|
return new UnauthorizedResult();
|
||||||
|
}
|
||||||
|
|
||||||
var claims = new List<Claim>
|
var claims = new List<Claim>
|
||||||
{
|
{
|
||||||
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
|
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue