This commit is contained in:
@@ -19,11 +19,11 @@ namespace AyaNova.Api.ControllerHelpers
|
|||||||
{
|
{
|
||||||
///<summary>Unknown state, used for parsing</summary>
|
///<summary>Unknown state, used for parsing</summary>
|
||||||
UNKNOWN = 0,
|
UNKNOWN = 0,
|
||||||
///<summary>No access for anyone API completely locked down</summary>
|
///<summary>No access for anyone API completely locked down. Not set by user but rather by internal server operations like importing or backup.</summary>
|
||||||
Closed = 1,
|
Closed = 1,
|
||||||
///<summary>Access only to API Operations routes</summary>
|
///<summary>Access only to API Operations routes. Can be set by Ops user</summary>
|
||||||
OpsOnly = 2,
|
OpsOnly = 2,
|
||||||
///<summary>Open for all users (default)</summary>
|
///<summary>Open for all users (default). Can be set by Ops user</summary>
|
||||||
Open = 3
|
Open = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,27 +62,22 @@ namespace AyaNova.Api.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<IActionResult> PostServerState([FromBody] ServerStateModel state)
|
public async Task<IActionResult> PostServerState([FromBody] ServerStateModel state)
|
||||||
{
|
{
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerState))
|
if (serverState.IsClosed)//no state change allowed when closed
|
||||||
{
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serverState.IsSystemLocked)//no state change allowed when system locked, must correct the problem first
|
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerState))
|
||||||
{
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
}
|
|
||||||
|
|
||||||
ApiServerState.ServerState desiredState;
|
ApiServerState.ServerState desiredState;
|
||||||
|
|
||||||
if (!Enum.TryParse<ApiServerState.ServerState>(state.ServerState, true, out desiredState))
|
if (!Enum.TryParse<ApiServerState.ServerState>(state.ServerState, true, out desiredState))
|
||||||
{
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Invalid state - must be one of \"OpsOnly\" or \"Open\""));
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Invalid state - must be one of \"Closing\", \"Closed\", \"OpsOnly\" or \"Open\""));
|
|
||||||
}
|
//don't allow a server to be set to closed, that's for internal ops only
|
||||||
|
if (desiredState == ApiServerState.ServerState.Closed)
|
||||||
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Invalid state - must be one of \"OpsOnly\" or \"Open\""));
|
||||||
|
|
||||||
log.LogInformation($"ServerState change request by user {UserNameFromContext.Name(HttpContext.Items)} from current state of \"{serverState.GetState().ToString()}\" to \"{desiredState.ToString()}\"");
|
log.LogInformation($"ServerState change request by user {UserNameFromContext.Name(HttpContext.Items)} from current state of \"{serverState.GetState().ToString()}\" to \"{desiredState.ToString()}\"");
|
||||||
|
|
||||||
@@ -101,7 +96,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
public class ServerStateModel
|
public class ServerStateModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// One of "Closed", "OpsOnly" or "Open"
|
/// "OpsOnly" or "Open"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Required]
|
[Required]
|
||||||
|
|||||||
@@ -1635,5 +1635,8 @@
|
|||||||
"ErrorPickListQueryInvalid":"Abfrage ungültig - Klicken Sie auf das Hilfesymbol, um weitere Informationen zu erhalten",
|
"ErrorPickListQueryInvalid":"Abfrage ungültig - Klicken Sie auf das Hilfesymbol, um weitere Informationen zu erhalten",
|
||||||
"UserInterfaceSettings":"Benutzeroberfläche",
|
"UserInterfaceSettings":"Benutzeroberfläche",
|
||||||
"PickListTemplates":"Wählen Sie Listenvorlagen aus",
|
"PickListTemplates":"Wählen Sie Listenvorlagen aus",
|
||||||
"ResetToDefault":"Auf Standard zurücksetzen"
|
"ResetToDefault":"Auf Standard zurücksetzen",
|
||||||
|
"ServerState":"Serverstatus",
|
||||||
|
"ServerStateOpen":"Öffnen",
|
||||||
|
"ServerStateOps":"Nur Systembetrieb"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1636,7 +1636,10 @@
|
|||||||
"ErrorPickListQueryInvalid":"Query not valid - click help icon to learn more",
|
"ErrorPickListQueryInvalid":"Query not valid - click help icon to learn more",
|
||||||
"UserInterfaceSettings":"User interface",
|
"UserInterfaceSettings":"User interface",
|
||||||
"PickListTemplates":"Select list templates",
|
"PickListTemplates":"Select list templates",
|
||||||
"ResetToDefault":"Reset to default"
|
"ResetToDefault":"Reset to default",
|
||||||
|
"ServerState":"Server state",
|
||||||
|
"ServerStateOpen":"Open",
|
||||||
|
"ServerStateOps":"Server operations only"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1635,7 +1635,10 @@
|
|||||||
"ErrorPickListQueryInvalid":"Consulta no válida: haga clic en el icono de ayuda para obtener más información",
|
"ErrorPickListQueryInvalid":"Consulta no válida: haga clic en el icono de ayuda para obtener más información",
|
||||||
"UserInterfaceSettings":"Interfaz de usuario",
|
"UserInterfaceSettings":"Interfaz de usuario",
|
||||||
"PickListTemplates":"Seleccionar plantillas de lista",
|
"PickListTemplates":"Seleccionar plantillas de lista",
|
||||||
"ResetToDefault":"Restablecen a los predeterminados"
|
"ResetToDefault":"Restablecen a los predeterminados",
|
||||||
|
"ServerState":"Estado del servidor",
|
||||||
|
"ServerStateOpen":"Abrir",
|
||||||
|
"ServerStateOps":"Solo operaciones del sistema"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1633,5 +1633,8 @@
|
|||||||
"ErrorPickListQueryInvalid": "Requête non valide - cliquez sur l'icône d'aide pour en savoir plus",
|
"ErrorPickListQueryInvalid": "Requête non valide - cliquez sur l'icône d'aide pour en savoir plus",
|
||||||
"UserInterfaceSettings": "Interface utilisateur",
|
"UserInterfaceSettings": "Interface utilisateur",
|
||||||
"PickListTemplates": "Sélectionner des modèles de liste",
|
"PickListTemplates": "Sélectionner des modèles de liste",
|
||||||
"ResetToDefault": "Rétablir la valeur par défaut"
|
"ResetToDefault": "Rétablir la valeur par défaut",
|
||||||
|
"ServerState":"État du serveur",
|
||||||
|
"ServerStateOpen":"Ouvrir",
|
||||||
|
"ServerStateOps":"Opérations système uniquement"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user