This commit is contained in:
TidusJar 2019-01-23 16:30:15 +00:00
commit c2c8a772dd
10 changed files with 93 additions and 55 deletions

View file

@ -15,5 +15,6 @@
public const string Disabled = nameof(Disabled); public const string Disabled = nameof(Disabled);
public const string ReceivesNewsletter = nameof(ReceivesNewsletter); public const string ReceivesNewsletter = nameof(ReceivesNewsletter);
public const string ManageOwnRequests = nameof(ManageOwnRequests); public const string ManageOwnRequests = nameof(ManageOwnRequests);
public const string EditCustomPage = nameof(EditCustomPage);
} }
} }

View file

@ -39,7 +39,7 @@ import { ImageService } from "./services";
import { LandingPageService } from "./services"; import { LandingPageService } from "./services";
import { NotificationService } from "./services"; import { NotificationService } from "./services";
import { SettingsService } from "./services"; import { SettingsService } from "./services";
import { IssuesService, JobService, PlexTvService, StatusService } from "./services"; import { CustomPageService, IssuesService, JobService, PlexTvService, StatusService } from "./services";
const routes: Routes = [ const routes: Routes = [
{ path: "*", component: PageNotFoundComponent }, { path: "*", component: PageNotFoundComponent },
@ -144,6 +144,7 @@ export function JwtTokenGetter() {
JobService, JobService,
IssuesService, IssuesService,
PlexTvService, PlexTvService,
CustomPageService,
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
}) })

View file

@ -2,7 +2,7 @@
import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { DomSanitizer } from "@angular/platform-browser"; import { DomSanitizer } from "@angular/platform-browser";
import { AuthService } from "../auth/auth.service"; import { AuthService } from "../auth/auth.service";
import { NotificationService, SettingsService } from "../services"; import { CustomPageService, NotificationService } from "../services";
@Component({ @Component({
templateUrl: "./custompage.component.html", templateUrl: "./custompage.component.html",
@ -14,7 +14,7 @@ export class CustomPageComponent implements OnInit {
public isEditing: boolean; public isEditing: boolean;
public isAdmin: boolean; public isAdmin: boolean;
constructor(private auth: AuthService, private settings: SettingsService, private fb: FormBuilder, constructor(private auth: AuthService, private settings: CustomPageService, private fb: FormBuilder,
private notificationService: NotificationService, private notificationService: NotificationService,
private sanitizer: DomSanitizer) { private sanitizer: DomSanitizer) {
} }
@ -29,7 +29,7 @@ export class CustomPageComponent implements OnInit {
fontAwesomeIcon: [x.fontAwesomeIcon, [Validators.required]], fontAwesomeIcon: [x.fontAwesomeIcon, [Validators.required]],
}); });
}); });
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser"); this.isAdmin = this.auth.hasRole("EditCustomPage");
} }
public onSubmit() { public onSubmit() {

View file

@ -0,0 +1,25 @@
import { PlatformLocation } from "@angular/common";
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import {
ICustomPage,
} from "../interfaces";
import { ServiceHelpers } from "./service.helpers";
@Injectable()
export class CustomPageService extends ServiceHelpers {
constructor(public http: HttpClient, public platformLocation: PlatformLocation) {
super(http, "/api/v1/CustomPage", platformLocation);
}
public getCustomPage(): Observable<ICustomPage> {
return this.http.get<ICustomPage>(this.url, {headers: this.headers});
}
public saveCustomPage(model: ICustomPage): Observable<boolean> {
return this.http.post<boolean>(this.url, model, {headers: this.headers});
}
}

View file

@ -16,3 +16,4 @@ export * from "./notificationMessage.service";
export * from "./recentlyAdded.service"; export * from "./recentlyAdded.service";
export * from "./vote.service"; export * from "./vote.service";
export * from "./requestretry.service"; export * from "./requestretry.service";
export * from "./custompage.service";

View file

@ -75,7 +75,7 @@
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
<input type="checkbox" id="useCustomPage" name="useCustomPage" [(ngModel)]="settings.useCustomPage"> <input type="checkbox" id="useCustomPage" name="useCustomPage" [(ngModel)]="settings.useCustomPage">
<label for="useCustomPage" tooltipPosition="top" pTooltip="Enabled a custom page where you can fully edit">Use <label for="useCustomPage" tooltipPosition="top" pTooltip="Enabled a custom page where you can fully edit. You will need the Edit Custom Page role.">Use
Custom Page</label> Custom Page</label>
</div> </div>

View file

@ -0,0 +1,53 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
namespace Ombi.Controllers
{
[ApiV1]
[Produces("application/json")]
[ApiController]
public class CustomPageController : ControllerBase
{
public CustomPageController(ISettingsService<CustomPageSettings> settings)
{
_settings = settings;
}
private readonly ISettingsService<CustomPageSettings> _settings;
/// <summary>
/// Gets the Custom Page Settings.
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<CustomPageSettings> CustomPageSettings()
{
return await Get();
}
/// <summary>
/// Saves the Custom Page Settings.
/// </summary>
/// <returns></returns>
[HttpPost]
[Authorize(OmbiRoles.EditCustomPage)]
public async Task<bool> CustomPageSettings([FromBody] CustomPageSettings page)
{
return await Save(page);
}
private async Task<CustomPageSettings> Get()
{
return await _settings.GetSettingsAsync();
}
private async Task<bool> Save(CustomPageSettings settingsModel)
{
return await _settings.SaveSettingsAsync(settingsModel);
}
}
}

View file

@ -239,6 +239,7 @@ namespace Ombi.Controllers
await CreateRole(OmbiRoles.Disabled); await CreateRole(OmbiRoles.Disabled);
await CreateRole(OmbiRoles.ReceivesNewsletter); await CreateRole(OmbiRoles.ReceivesNewsletter);
await CreateRole(OmbiRoles.ManageOwnRequests); await CreateRole(OmbiRoles.ManageOwnRequests);
await CreateRole(OmbiRoles.EditCustomPage);
} }
private async Task CreateRole(string role) private async Task CreateRole(string role)

View file

@ -707,27 +707,6 @@ namespace Ombi.Controllers
return emailSettings.Enabled; return emailSettings.Enabled;
} }
/// <summary>
/// Gets the Custom Page Settings.
/// </summary>
/// <returns></returns>
[HttpGet("CustomPage")]
[AllowAnonymous]
public async Task<CustomPageSettings> CustomPageSettings()
{
return await Get<CustomPageSettings>();
}
/// <summary>
/// Saves the Custom Page Settings.
/// </summary>
/// <returns></returns>
[HttpPost("CustomPage")]
public async Task<bool> CustomPageSettings([FromBody] CustomPageSettings page)
{
return await Save(page);
}
/// <summary> /// <summary>
/// Saves the discord notification settings. /// Saves the discord notification settings.
/// </summary> /// </summary>

View file

@ -26,6 +26,7 @@ using Ombi.Store.Context;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Serilog; using Serilog;
using ILogger = Serilog.ILogger;
namespace Ombi namespace Ombi
{ {
@ -42,35 +43,12 @@ namespace Ombi
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
//if (env.IsDevelopment()) ILogger config = new LoggerConfiguration()
//{ .MinimumLevel.Debug()
Serilog.ILogger config; .WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? env.ContentRootPath : StoragePath.StoragePath, "Logs", "log-{Date}.txt"))
if (string.IsNullOrEmpty(StoragePath.StoragePath)) .CreateLogger();
{
config = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt"))
.CreateLogger();
}
else
{
config = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath, "Logs", "log-{Date}.txt"))
.CreateLogger();
}
Log.Logger = config; Log.Logger = config;
//}
//if (env.IsProduction())
//{
// Log.Logger = new LoggerConfiguration()
// .MinimumLevel.Debug()
// .WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt"))
// .WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
// .CreateLogger();
//}
} }
public IConfigurationRoot Configuration { get; } public IConfigurationRoot Configuration { get; }
@ -126,7 +104,6 @@ namespace Ombi
{ {
x.UseSQLiteStorage(sqliteStorage); x.UseSQLiteStorage(sqliteStorage);
x.UseActivator(new IoCJobActivator(services.BuildServiceProvider())); x.UseActivator(new IoCJobActivator(services.BuildServiceProvider()));
//x.UseConsole();
}); });
services.AddCors(o => o.AddPolicy("MyPolicy", builder => services.AddCors(o => o.AddPolicy("MyPolicy", builder =>