This commit is contained in:
@@ -19,11 +19,11 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
///<summary>Unknown state, used for parsing</summary>
|
||||
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,
|
||||
///<summary>Access only to API Operations routes</summary>
|
||||
///<summary>Access only to API Operations routes. Can be set by Ops user</summary>
|
||||
OpsOnly = 2,
|
||||
///<summary>Open for all users (default)</summary>
|
||||
///<summary>Open for all users (default). Can be set by Ops user</summary>
|
||||
Open = 3
|
||||
}
|
||||
|
||||
|
||||
@@ -62,27 +62,22 @@ namespace AyaNova.Api.Controllers
|
||||
[Authorize]
|
||||
public async Task<IActionResult> PostServerState([FromBody] ServerStateModel state)
|
||||
{
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerState))
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
if (serverState.IsClosed)//no state change allowed when closed
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
if (serverState.IsSystemLocked)//no state change allowed when system locked, must correct the problem first
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, AyaType.ServerState))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
ApiServerState.ServerState 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 \"Closing\", \"Closed\", \"OpsOnly\" or \"Open\""));
|
||||
}
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Invalid state - must be one of \"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()}\"");
|
||||
|
||||
@@ -101,7 +96,7 @@ namespace AyaNova.Api.Controllers
|
||||
public class ServerStateModel
|
||||
{
|
||||
/// <summary>
|
||||
/// One of "Closed", "OpsOnly" or "Open"
|
||||
/// "OpsOnly" or "Open"
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Required]
|
||||
|
||||
@@ -1635,5 +1635,8 @@
|
||||
"ErrorPickListQueryInvalid":"Abfrage ungültig - Klicken Sie auf das Hilfesymbol, um weitere Informationen zu erhalten",
|
||||
"UserInterfaceSettings":"Benutzeroberfläche",
|
||||
"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",
|
||||
"UserInterfaceSettings":"User interface",
|
||||
"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",
|
||||
"UserInterfaceSettings":"Interfaz de usuario",
|
||||
"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",
|
||||
"UserInterfaceSettings": "Interface utilisateur",
|
||||
"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