From d88e4a31f35d9197e79ff0d55ecd75085404be9a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 25 Nov 2022 15:02:08 -0600 Subject: add IsRelayAgent to Program, simplify checks --- .../API/Controllers/ConversationsController.cs | 13 ++++++------- .../API/Controllers/PublicChatController.cs | 5 ++--- .../Messaging/API/Controllers/RoomsController.cs | 21 ++++++++++----------- 3 files changed, 18 insertions(+), 21 deletions(-) (limited to 'src/slskd/Messaging/API/Controllers') diff --git a/src/slskd/Messaging/API/Controllers/ConversationsController.cs b/src/slskd/Messaging/API/Controllers/ConversationsController.cs index 90e7f380..d39c2c10 100644 --- a/src/slskd/Messaging/API/Controllers/ConversationsController.cs +++ b/src/slskd/Messaging/API/Controllers/ConversationsController.cs @@ -60,7 +60,6 @@ namespace slskd.Messaging.API private IStateMonitor ApplicationStateMonitor { get; } private IConversationTracker Tracker { get; } private IOptionsSnapshot OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum() == RelayMode.Agent; /// /// Acknowledges the given message id for the given username. @@ -78,7 +77,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task Acknowledge([FromRoute]string username, [FromRoute]int id) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -107,7 +106,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task AcknowledgeAll([FromRoute]string username) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -146,7 +145,7 @@ namespace slskd.Messaging.API [ProducesResponseType(204)] public IActionResult Delete([FromRoute]string username) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -171,7 +170,7 @@ namespace slskd.Messaging.API [ProducesResponseType(typeof(Dictionary>), 200)] public IActionResult GetAll() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -198,7 +197,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public IActionResult GetByUsername([FromRoute]string username) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -229,7 +228,7 @@ namespace slskd.Messaging.API [ProducesResponseType(400)] public async Task Send([FromRoute]string username, [FromBody]string message) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } diff --git a/src/slskd/Messaging/API/Controllers/PublicChatController.cs b/src/slskd/Messaging/API/Controllers/PublicChatController.cs index 8b6ce4f8..b3779fe3 100644 --- a/src/slskd/Messaging/API/Controllers/PublicChatController.cs +++ b/src/slskd/Messaging/API/Controllers/PublicChatController.cs @@ -44,7 +44,6 @@ namespace slskd.Messaging.API private ISoulseekClient Client { get; } private IOptionsSnapshot OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum() == RelayMode.Agent; /// /// Starts public chat. @@ -54,7 +53,7 @@ namespace slskd.Messaging.API [Authorize(Policy = AuthPolicy.Any)] public async Task Start() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -71,7 +70,7 @@ namespace slskd.Messaging.API [Authorize(Policy = AuthPolicy.Any)] public async Task Stop() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } diff --git a/src/slskd/Messaging/API/Controllers/RoomsController.cs b/src/slskd/Messaging/API/Controllers/RoomsController.cs index 1036e10e..0f2ccf25 100644 --- a/src/slskd/Messaging/API/Controllers/RoomsController.cs +++ b/src/slskd/Messaging/API/Controllers/RoomsController.cs @@ -58,7 +58,6 @@ namespace slskd.Messaging.API private IStateMonitor ApplicationStateMonitor { get; } private IRoomTracker Tracker { get; } private IOptionsSnapshot OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum() == RelayMode.Agent; /// /// Gets all rooms. @@ -70,7 +69,7 @@ namespace slskd.Messaging.API [ProducesResponseType(typeof(Dictionary>), 200)] public IActionResult GetAll() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -91,7 +90,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public IActionResult GetByRoomName([FromRoute]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -118,7 +117,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task SendMessage([FromRoute]string roomName, [FromBody]string message) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -146,7 +145,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task SetTicker([FromRoute] string roomName, [FromBody] string message) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -174,7 +173,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task AddRoomMember([FromRoute]string roomName, [FromBody]string username) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -201,7 +200,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public IActionResult GetUsersByRoomName([FromRoute]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -230,7 +229,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public IActionResult GetMessagesByRoomName([FromRoute]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -255,7 +254,7 @@ namespace slskd.Messaging.API [ProducesResponseType(typeof(List), 200)] public async Task GetRooms() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -289,7 +288,7 @@ namespace slskd.Messaging.API [ProducesResponseType(304)] public async Task JoinRoom([FromBody]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -330,7 +329,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task LeaveRoom([FromRoute]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } -- cgit v1.2.3