From 893a0dfdacc676d46deaa2b8e2ea09d0c693e15b Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 11 Dec 2020 17:41:57 +0330 Subject: [PATCH] #45 upload enabled switch on appsettings.json --- RMuseum/Controllers/RecitationController.cs | 38 +++++++++++++++---- RMuseum/RMuseum.xml | 17 +++++++++ RMuseum/Services/IRecitationService.cs | 5 +++ .../Implementation/RecitationService.cs | 18 +++++++++ RMuseum/appsettings.json | 1 + 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/RMuseum/Controllers/RecitationController.cs b/RMuseum/Controllers/RecitationController.cs index 20d0b2f2..20948c49 100644 --- a/RMuseum/Controllers/RecitationController.cs +++ b/RMuseum/Controllers/RecitationController.cs @@ -36,7 +36,6 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] public async Task GetPublished([FromQuery] PagingParameterModel paging, string searchTerm = "") { - if (paging.PageSize == -1 || paging.PageSize > 100) paging.PageSize = 100; var res = await _audioService.GetPublishedRecitations(paging, searchTerm); @@ -61,8 +60,6 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))] public async Task GetPublishedRecitationById(int id) { - - var res = await _audioService.GetPublishedRecitationById(id); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); @@ -111,7 +108,6 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))] - public async Task Get([FromQuery] PagingParameterModel paging, bool allUsers = false, AudioReviewStatus status = AudioReviewStatus.All, string searchTerm = "") { Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); @@ -261,7 +257,8 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))] public async Task UpdatePoemNarration(int id, [FromBody] RecitationViewModel metadata) { - + if (!_audioService.UploadEnabled) + return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); @@ -323,6 +320,9 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))] public async Task ModeratePoemNarration(int id, [FromBody] RecitationModerateViewModel model) { + if (!_audioService.UploadEnabled) + return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); @@ -351,6 +351,9 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.Forbidden)] public async Task DeleteRecitation(int id) { + if (!_audioService.UploadEnabled) + return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); RServiceResult res = await _audioService.Delete(id, loggedOnUserId); if (!string.IsNullOrEmpty(res.ExceptionString)) @@ -407,6 +410,20 @@ namespace RMuseum.Controllers return Ok(res.Result.Items); } + /// + /// upload, update, moderate and delete operations on recitations might temporarily become disabled, + /// this method gets the current status + /// + /// + + [HttpGet("uploadenabled")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))] + public IActionResult IsUploadEnabled() + { + return Ok(_audioService.UploadEnabled); + } + /// /// Reciation Upload /// @@ -425,6 +442,8 @@ namespace RMuseum.Controllers { try { + if (!_audioService.UploadEnabled) + return BadRequest("ارسال خوانش جدید به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); RServiceResult resSession = await _audioService.InitiateNewUploadSession(loggedOnUserId, replace); if (!string.IsNullOrEmpty(resSession.ExceptionString)) @@ -482,6 +501,9 @@ namespace RMuseum.Controllers { try { + if (!_audioService.UploadEnabled) + return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); + await _audioService.RetryPublish(); return Ok(); } @@ -683,6 +705,9 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] public async Task MakeFFRecitationsFirst() { + if (!_audioService.UploadEnabled) + return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."); + var resExec = await _audioService.MakeArtistRecitationsFirst("فریدون فرح‌اندوز"); if (!string.IsNullOrEmpty(resExec.ExceptionString)) return BadRequest(resExec.ExceptionString); @@ -715,8 +740,6 @@ namespace RMuseum.Controllers ); if (!string.IsNullOrEmpty(canViewAll.ExceptionString)) return BadRequest(canViewAll.ExceptionString); - - var res = await _audioService.GetSynchronizationQueue(canViewAll.Result ? Guid.Empty : loggedOnUserId); if (!string.IsNullOrEmpty(res.ExceptionString)) return BadRequest(res.ExceptionString); @@ -724,6 +747,7 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// /// constructor /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 3bc384fd..9c57e864 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -821,6 +821,13 @@ default: false, user must have recitation::moderate permission to be able to see all users uploads + + + upload, update, moderate and delete operations on recitations might temporarily become disabled, + this method gets the current status + + + Reciation Upload @@ -5585,6 +5592,11 @@ + + + Upload Enabled (temporary switch off/on for upload) + + Configuration @@ -5889,6 +5901,11 @@ + + + Upload Enabled (temporary switch off/on for upload) + + Internal messaging system interface diff --git a/RMuseum/Services/IRecitationService.cs b/RMuseum/Services/IRecitationService.cs index 0ba29e4c..509840ca 100644 --- a/RMuseum/Services/IRecitationService.cs +++ b/RMuseum/Services/IRecitationService.cs @@ -203,5 +203,10 @@ namespace RMuseum.Services /// /// Task> GetSynchronizationQueue(Guid filteredUserId); + + /// + /// Upload Enabled (temporary switch off/on for upload) + /// + bool UploadEnabled { get; } } } diff --git a/RMuseum/Services/Implementation/RecitationService.cs b/RMuseum/Services/Implementation/RecitationService.cs index 1925535b..c7255c7a 100644 --- a/RMuseum/Services/Implementation/RecitationService.cs +++ b/RMuseum/Services/Implementation/RecitationService.cs @@ -1990,6 +1990,24 @@ namespace RMuseum.Services.Implementationa } } + /// + /// Upload Enabled (temporary switch off/on for upload) + /// + public bool UploadEnabled + { + get + { + try + { + return bool.Parse(Configuration.GetSection("AudioUploadService")["Enabled"]); + } + catch + { + return false; + } + } + } + /// /// Configuration /// diff --git a/RMuseum/appsettings.json b/RMuseum/appsettings.json index 48ec38d6..6ee489c3 100644 --- a/RMuseum/appsettings.json +++ b/RMuseum/appsettings.json @@ -50,6 +50,7 @@ "RootPath": "/home" }, "AudioUploadService": { + "Enabled": "True", "TempUploadPath": "C:\\tempaudio", "LocalAudioRepositoryPath": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i", "CurrentSoundFilesFolder": "a2"