diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-25 15:02:08 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-11-25 15:02:08 -0600 |
| commit | d88e4a31f35d9197e79ff0d55ecd75085404be9a (patch) | |
| tree | 5e2e7c5f7c64b80052f2f4dfb574398b685e0d54 /src/slskd/Messaging/API/Controllers | |
| parent | fd56f6fc0d2f1fa081c312bb5dea976b40131b94 (diff) | |
| download | slskd-d88e4a31f35d9197e79ff0d55ecd75085404be9a.tar.gz | |
add IsRelayAgent to Program, simplify checks
Diffstat (limited to 'src/slskd/Messaging/API/Controllers')
3 files changed, 18 insertions, 21 deletions
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<State> ApplicationStateMonitor { get; } private IConversationTracker Tracker { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Acknowledges the given message id for the given username. @@ -78,7 +77,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task<IActionResult> 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<IActionResult> 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<string, List<PrivateMessageResponse>>), 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<IActionResult> 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<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Starts public chat. @@ -54,7 +53,7 @@ namespace slskd.Messaging.API [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> Start() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -71,7 +70,7 @@ namespace slskd.Messaging.API [Authorize(Policy = AuthPolicy.Any)] public async Task<IActionResult> 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<State> ApplicationStateMonitor { get; } private IRoomTracker Tracker { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } - private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent; /// <summary> /// Gets all rooms. @@ -70,7 +69,7 @@ namespace slskd.Messaging.API [ProducesResponseType(typeof(Dictionary<string, Dictionary<string, Room>>), 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<RoomInfo>), 200)] public async Task<IActionResult> GetRooms() { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -289,7 +288,7 @@ namespace slskd.Messaging.API [ProducesResponseType(304)] public async Task<IActionResult> JoinRoom([FromBody]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } @@ -330,7 +329,7 @@ namespace slskd.Messaging.API [ProducesResponseType(404)] public async Task<IActionResult> LeaveRoom([FromRoute]string roomName) { - if (IsAgent) + if (Program.IsRelayAgent) { return Forbid(); } |
