#45 upload enabled switch on appsettings.json

This commit is contained in:
Hamid Reza Mohammadi 2020-12-11 17:41:57 +03:30
parent ba3cfd2d0d
commit 893a0dfdac
5 changed files with 72 additions and 7 deletions

View File

@ -36,7 +36,6 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPublished([FromQuery] PagingParameterModel paging, string searchTerm = "") public async Task<IActionResult> GetPublished([FromQuery] PagingParameterModel paging, string searchTerm = "")
{ {
if (paging.PageSize == -1 || paging.PageSize > 100) if (paging.PageSize == -1 || paging.PageSize > 100)
paging.PageSize = 100; paging.PageSize = 100;
var res = await _audioService.GetPublishedRecitations(paging, searchTerm); var res = await _audioService.GetPublishedRecitations(paging, searchTerm);
@ -61,8 +60,6 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))]
public async Task<IActionResult> GetPublishedRecitationById(int id) public async Task<IActionResult> GetPublishedRecitationById(int id)
{ {
var res = await _audioService.GetPublishedRecitationById(id); var res = await _audioService.GetPublishedRecitationById(id);
if (!string.IsNullOrEmpty(res.ExceptionString)) if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString); return BadRequest(res.ExceptionString);
@ -111,7 +108,6 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<RecitationViewModel>))] [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<RecitationViewModel>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))]
public async Task<IActionResult> Get([FromQuery] PagingParameterModel paging, bool allUsers = false, AudioReviewStatus status = AudioReviewStatus.All, string searchTerm = "") public async Task<IActionResult> 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); 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))] [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))]
public async Task<IActionResult> UpdatePoemNarration(int id, [FromBody] RecitationViewModel metadata) public async Task<IActionResult> UpdatePoemNarration(int id, [FromBody] RecitationViewModel metadata)
{ {
if (!_audioService.UploadEnabled)
return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); 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))] [ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))]
public async Task<IActionResult> ModeratePoemNarration(int id, [FromBody] RecitationModerateViewModel model) public async Task<IActionResult> ModeratePoemNarration(int id, [FromBody] RecitationModerateViewModel model)
{ {
if (!_audioService.UploadEnabled)
return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
@ -351,6 +351,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.Forbidden)]
public async Task<IActionResult> DeleteRecitation(int id) public async Task<IActionResult> DeleteRecitation(int id)
{ {
if (!_audioService.UploadEnabled)
return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
RServiceResult<bool> res = await _audioService.Delete(id, loggedOnUserId); RServiceResult<bool> res = await _audioService.Delete(id, loggedOnUserId);
if (!string.IsNullOrEmpty(res.ExceptionString)) if (!string.IsNullOrEmpty(res.ExceptionString))
@ -407,6 +410,20 @@ namespace RMuseum.Controllers
return Ok(res.Result.Items); return Ok(res.Result.Items);
} }
/// <summary>
/// upload, update, moderate and delete operations on recitations might temporarily become disabled,
/// this method gets the current status
/// </summary>
/// <returns></returns>
[HttpGet("uploadenabled")]
[Authorize]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
public IActionResult IsUploadEnabled()
{
return Ok(_audioService.UploadEnabled);
}
/// <summary> /// <summary>
/// Reciation Upload /// Reciation Upload
/// </summary> /// </summary>
@ -425,6 +442,8 @@ namespace RMuseum.Controllers
{ {
try try
{ {
if (!_audioService.UploadEnabled)
return BadRequest("ارسال خوانش جدید به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
RServiceResult<UploadSession> resSession = await _audioService.InitiateNewUploadSession(loggedOnUserId, replace); RServiceResult<UploadSession> resSession = await _audioService.InitiateNewUploadSession(loggedOnUserId, replace);
if (!string.IsNullOrEmpty(resSession.ExceptionString)) if (!string.IsNullOrEmpty(resSession.ExceptionString))
@ -482,6 +501,9 @@ namespace RMuseum.Controllers
{ {
try try
{ {
if (!_audioService.UploadEnabled)
return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
await _audioService.RetryPublish(); await _audioService.RetryPublish();
return Ok(); return Ok();
} }
@ -683,6 +705,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> MakeFFRecitationsFirst() public async Task<IActionResult> MakeFFRecitationsFirst()
{ {
if (!_audioService.UploadEnabled)
return BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است.");
var resExec = await _audioService.MakeArtistRecitationsFirst("فریدون فرح‌اندوز"); var resExec = await _audioService.MakeArtistRecitationsFirst("فریدون فرح‌اندوز");
if (!string.IsNullOrEmpty(resExec.ExceptionString)) if (!string.IsNullOrEmpty(resExec.ExceptionString))
return BadRequest(resExec.ExceptionString); return BadRequest(resExec.ExceptionString);
@ -715,8 +740,6 @@ namespace RMuseum.Controllers
); );
if (!string.IsNullOrEmpty(canViewAll.ExceptionString)) if (!string.IsNullOrEmpty(canViewAll.ExceptionString))
return BadRequest(canViewAll.ExceptionString); return BadRequest(canViewAll.ExceptionString);
var res = await _audioService.GetSynchronizationQueue(canViewAll.Result ? Guid.Empty : loggedOnUserId); var res = await _audioService.GetSynchronizationQueue(canViewAll.Result ? Guid.Empty : loggedOnUserId);
if (!string.IsNullOrEmpty(res.ExceptionString)) if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString); return BadRequest(res.ExceptionString);
@ -724,6 +747,7 @@ namespace RMuseum.Controllers
return Ok(res.Result); return Ok(res.Result);
} }
/// <summary> /// <summary>
/// constructor /// constructor
/// </summary> /// </summary>

View File

@ -821,6 +821,13 @@
<param name="allUsers">default: false, user must have recitation::moderate permission to be able to see all users uploads</param> <param name="allUsers">default: false, user must have recitation::moderate permission to be able to see all users uploads</param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:RMuseum.Controllers.RecitationController.IsUploadEnabled">
<summary>
upload, update, moderate and delete operations on recitations might temporarily become disabled,
this method gets the current status
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.RecitationController.UploadReciation(System.Boolean)"> <member name="M:RMuseum.Controllers.RecitationController.UploadReciation(System.Boolean)">
<summary> <summary>
Reciation Upload Reciation Upload
@ -5585,6 +5592,11 @@
<param name="filteredUserId"></param> <param name="filteredUserId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="P:RMuseum.Services.Implementationa.RecitationService.UploadEnabled">
<summary>
Upload Enabled (temporary switch off/on for upload)
</summary>
</member>
<member name="P:RMuseum.Services.Implementationa.RecitationService.Configuration"> <member name="P:RMuseum.Services.Implementationa.RecitationService.Configuration">
<summary> <summary>
Configuration Configuration
@ -5889,6 +5901,11 @@
<param name="filteredUserId"></param> <param name="filteredUserId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="P:RMuseum.Services.IRecitationService.UploadEnabled">
<summary>
Upload Enabled (temporary switch off/on for upload)
</summary>
</member>
<member name="T:RMuseum.Services.IRNotificationService"> <member name="T:RMuseum.Services.IRNotificationService">
<summary> <summary>
Internal messaging system interface Internal messaging system interface

View File

@ -203,5 +203,10 @@ namespace RMuseum.Services
/// <param name="filteredUserId"></param> /// <param name="filteredUserId"></param>
/// <returns></returns> /// <returns></returns>
Task<RServiceResult<RecitationViewModel[]>> GetSynchronizationQueue(Guid filteredUserId); Task<RServiceResult<RecitationViewModel[]>> GetSynchronizationQueue(Guid filteredUserId);
/// <summary>
/// Upload Enabled (temporary switch off/on for upload)
/// </summary>
bool UploadEnabled { get; }
} }
} }

View File

@ -1990,6 +1990,24 @@ namespace RMuseum.Services.Implementationa
} }
} }
/// <summary>
/// Upload Enabled (temporary switch off/on for upload)
/// </summary>
public bool UploadEnabled
{
get
{
try
{
return bool.Parse(Configuration.GetSection("AudioUploadService")["Enabled"]);
}
catch
{
return false;
}
}
}
/// <summary> /// <summary>
/// Configuration /// Configuration
/// </summary> /// </summary>

View File

@ -50,6 +50,7 @@
"RootPath": "/home" "RootPath": "/home"
}, },
"AudioUploadService": { "AudioUploadService": {
"Enabled": "True",
"TempUploadPath": "C:\\tempaudio", "TempUploadPath": "C:\\tempaudio",
"LocalAudioRepositoryPath": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i", "LocalAudioRepositoryPath": "D:\\My Documents\\My Web Design\\ganjoor\\www\\i",
"CurrentSoundFilesFolder": "a2" "CurrentSoundFilesFolder": "a2"