From c2c8a772dd0c9aeb004091eb874132890da9fa27 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Wed, 23 Jan 2019 16:30:15 +0000 Subject: [PATCH] Did #2756 --- src/Ombi.Helpers/OmbiRoles.cs | 1 + src/Ombi/ClientApp/app/app.module.ts | 3 +- .../app/custompage/custompage.component.ts | 6 +-- .../app/services/custompage.service.ts | 25 +++++++++ src/Ombi/ClientApp/app/services/index.ts | 1 + .../customization.component.html | 2 +- src/Ombi/Controllers/CustomPageController.cs | 53 +++++++++++++++++++ src/Ombi/Controllers/IdentityController.cs | 1 + src/Ombi/Controllers/SettingsController.cs | 21 -------- src/Ombi/Startup.cs | 35 +++--------- 10 files changed, 93 insertions(+), 55 deletions(-) create mode 100644 src/Ombi/ClientApp/app/services/custompage.service.ts create mode 100644 src/Ombi/Controllers/CustomPageController.cs diff --git a/src/Ombi.Helpers/OmbiRoles.cs b/src/Ombi.Helpers/OmbiRoles.cs index e0cfc5398..02a480fdf 100644 --- a/src/Ombi.Helpers/OmbiRoles.cs +++ b/src/Ombi.Helpers/OmbiRoles.cs @@ -15,5 +15,6 @@ public const string Disabled = nameof(Disabled); public const string ReceivesNewsletter = nameof(ReceivesNewsletter); public const string ManageOwnRequests = nameof(ManageOwnRequests); + public const string EditCustomPage = nameof(EditCustomPage); } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/app.module.ts b/src/Ombi/ClientApp/app/app.module.ts index 6917cc85b..a68405f75 100644 --- a/src/Ombi/ClientApp/app/app.module.ts +++ b/src/Ombi/ClientApp/app/app.module.ts @@ -39,7 +39,7 @@ import { ImageService } from "./services"; import { LandingPageService } from "./services"; import { NotificationService } from "./services"; import { SettingsService } from "./services"; -import { IssuesService, JobService, PlexTvService, StatusService } from "./services"; +import { CustomPageService, IssuesService, JobService, PlexTvService, StatusService } from "./services"; const routes: Routes = [ { path: "*", component: PageNotFoundComponent }, @@ -144,6 +144,7 @@ export function JwtTokenGetter() { JobService, IssuesService, PlexTvService, + CustomPageService, ], bootstrap: [AppComponent], }) diff --git a/src/Ombi/ClientApp/app/custompage/custompage.component.ts b/src/Ombi/ClientApp/app/custompage/custompage.component.ts index f346bef2b..61094e793 100644 --- a/src/Ombi/ClientApp/app/custompage/custompage.component.ts +++ b/src/Ombi/ClientApp/app/custompage/custompage.component.ts @@ -2,7 +2,7 @@ import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { DomSanitizer } from "@angular/platform-browser"; import { AuthService } from "../auth/auth.service"; -import { NotificationService, SettingsService } from "../services"; +import { CustomPageService, NotificationService } from "../services"; @Component({ templateUrl: "./custompage.component.html", @@ -14,7 +14,7 @@ export class CustomPageComponent implements OnInit { public isEditing: 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 sanitizer: DomSanitizer) { } @@ -29,7 +29,7 @@ export class CustomPageComponent implements OnInit { fontAwesomeIcon: [x.fontAwesomeIcon, [Validators.required]], }); }); - this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser"); + this.isAdmin = this.auth.hasRole("EditCustomPage"); } public onSubmit() { diff --git a/src/Ombi/ClientApp/app/services/custompage.service.ts b/src/Ombi/ClientApp/app/services/custompage.service.ts new file mode 100644 index 000000000..1fc1ea028 --- /dev/null +++ b/src/Ombi/ClientApp/app/services/custompage.service.ts @@ -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 { + return this.http.get(this.url, {headers: this.headers}); + } + + public saveCustomPage(model: ICustomPage): Observable { + return this.http.post(this.url, model, {headers: this.headers}); + } +} diff --git a/src/Ombi/ClientApp/app/services/index.ts b/src/Ombi/ClientApp/app/services/index.ts index edffdd625..5065ce938 100644 --- a/src/Ombi/ClientApp/app/services/index.ts +++ b/src/Ombi/ClientApp/app/services/index.ts @@ -16,3 +16,4 @@ export * from "./notificationMessage.service"; export * from "./recentlyAdded.service"; export * from "./vote.service"; export * from "./requestretry.service"; +export * from "./custompage.service"; diff --git a/src/Ombi/ClientApp/app/settings/customization/customization.component.html b/src/Ombi/ClientApp/app/settings/customization/customization.component.html index 21a992c32..1f7a158ae 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.html +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.html @@ -75,7 +75,7 @@
-
diff --git a/src/Ombi/Controllers/CustomPageController.cs b/src/Ombi/Controllers/CustomPageController.cs new file mode 100644 index 000000000..6ee6fa159 --- /dev/null +++ b/src/Ombi/Controllers/CustomPageController.cs @@ -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 settings) + { + _settings = settings; + } + + private readonly ISettingsService _settings; + + /// + /// Gets the Custom Page Settings. + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task CustomPageSettings() + { + return await Get(); + } + + /// + /// Saves the Custom Page Settings. + /// + /// + [HttpPost] + [Authorize(OmbiRoles.EditCustomPage)] + public async Task CustomPageSettings([FromBody] CustomPageSettings page) + { + return await Save(page); + } + private async Task Get() + { + return await _settings.GetSettingsAsync(); + } + + private async Task Save(CustomPageSettings settingsModel) + { + return await _settings.SaveSettingsAsync(settingsModel); + } + } +} \ No newline at end of file diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index 2976069ed..4838eabf1 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -239,6 +239,7 @@ namespace Ombi.Controllers await CreateRole(OmbiRoles.Disabled); await CreateRole(OmbiRoles.ReceivesNewsletter); await CreateRole(OmbiRoles.ManageOwnRequests); + await CreateRole(OmbiRoles.EditCustomPage); } private async Task CreateRole(string role) diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 0fe67edfd..b5ec57e29 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -707,27 +707,6 @@ namespace Ombi.Controllers return emailSettings.Enabled; } - /// - /// Gets the Custom Page Settings. - /// - /// - [HttpGet("CustomPage")] - [AllowAnonymous] - public async Task CustomPageSettings() - { - return await Get(); - } - - /// - /// Saves the Custom Page Settings. - /// - /// - [HttpPost("CustomPage")] - public async Task CustomPageSettings([FromBody] CustomPageSettings page) - { - return await Save(page); - } - /// /// Saves the discord notification settings. /// diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 282034ea5..bbf56c517 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -26,6 +26,7 @@ using Ombi.Store.Context; using Ombi.Store.Entities; using Ombi.Store.Repository; using Serilog; +using ILogger = Serilog.ILogger; namespace Ombi { @@ -42,35 +43,12 @@ namespace Ombi .AddEnvironmentVariables(); Configuration = builder.Build(); - //if (env.IsDevelopment()) - //{ - Serilog.ILogger config; - if (string.IsNullOrEmpty(StoragePath.StoragePath)) - { - 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; - + ILogger config = new LoggerConfiguration() + .MinimumLevel.Debug() + .WriteTo.RollingFile(Path.Combine(StoragePath.StoragePath.IsNullOrEmpty() ? env.ContentRootPath : StoragePath.StoragePath, "Logs", "log-{Date}.txt")) + .CreateLogger(); - //} - //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(); - //} + Log.Logger = config; } public IConfigurationRoot Configuration { get; } @@ -126,7 +104,6 @@ namespace Ombi { x.UseSQLiteStorage(sqliteStorage); x.UseActivator(new IoCJobActivator(services.BuildServiceProvider())); - //x.UseConsole(); }); services.AddCors(o => o.AddPolicy("MyPolicy", builder =>