Add maintenance banner on UI (#797)

* fix bug on email separator

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* allow group name change

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* add maintenance banner on UI

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

* removes unnecessary comments

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>

---------

Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
Denis Barbaron
2024-07-19 10:33:52 +02:00
committed by GitHub
parent cf56911e9f
commit 489ba0427e
17 changed files with 446 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright © 2019 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
* Copyright © 2019-2024 code initially contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
**/
const dbapi = require('../../../db/api')
@@ -11,6 +11,7 @@ const wire = require('../../../wire')
const wireutil = require('../../../wire/util')
const userapi = require('./user')
/* --------------------------------- PRIVATE FUNCTIONS --------------------------------------- */
function userApiWrapper(fn, req, res) {
@@ -142,6 +143,92 @@ function getUserInfo(req, email) {
})
}
function updateUsersAlertMessage(req, res) {
const lock = {}
return dbapi.lockUser(req.user.email).then(function(stats) {
if (!stats.replaced) {
return apiutil.lightComputeStats(res, stats)
}
lock.user = stats.changes[0].new_val
return dbapi.updateUsersAlertMessage(req.body).then(function(stats) {
if (stats.unchanged) {
dbapi.loadUser(req.user.email).then(function(user) {
apiutil.respond(res, 200, 'Unchanged (users alert message)',
{alertMessage: user.settings.alertMessage})
})
}
else {
apiutil.respond(res, 200, 'Updated (users alert message)',
{alertMessage: stats.changes[0].new_val.settings.alertMessage})
}
})
.catch(function(err) {
apiutil.internalError(res, 'Failed to update users alert message: ', err.stack)
})
})
.catch(function(err) {
if (err !== 'busy') {
throw err
}
})
.finally(function() {
lockutil.unlockUser(lock)
})
}
function getUsersAlertMessage(req, res) {
const fields = req.swagger.params.fields.value
dbapi.getRootGroup().then(function(group) {
return dbapi.loadUser(group.owner.email).then(function(user) {
if (typeof user.settings.alertMessage === 'undefined') {
const lock = {}
return dbapi.lockUser(req.user.email).then(function(stats) {
if (!stats.replaced) {
return apiutil.lightComputeStats(res, stats)
}
lock.user = stats.changes[0].new_val
const alertMessage = {
activation: 'False'
, data: '*** this site is currently under maintenance, please wait ***'
, level: 'Critical'
}
return dbapi.updateUsersAlertMessage(alertMessage).then(function(stats) {
if (!stats.errors) {
return stats.changes[0].new_val.settings.alertMessage
}
throw new Error('Failed to initialize users alert message')
})
})
.finally(function() {
lockutil.unlockUser(lock)
})
}
return user.settings.alertMessage
})
.then(function(alertMessage) {
if (fields) {
return _.pick(alertMessage, fields.split(','))
}
else {
return alertMessage
}
})
.then(function(alertMessage) {
apiutil.respond(res, 200, 'Users Alert Message', {alertMessage: alertMessage})
})
})
.catch(function(err) {
if (err !== 'busy') {
apiutil.internalError(res, 'Failed to get users alert message: ', err.stack)
}
})
}
function updateUserGroupsQuotas(req, res) {
const email = req.swagger.params.email.value
const duration =
@@ -379,6 +466,8 @@ module.exports = {
updateUserGroupsQuotas: updateUserGroupsQuotas
, updateDefaultUserGroupsQuotas: updateDefaultUserGroupsQuotas
, getUsers: getUsers
, getUsersAlertMessage: getUsersAlertMessage
, updateUsersAlertMessage: updateUsersAlertMessage
, getUserByEmail: getUserByEmail
, getUserInfo: getUserInfo
, createUser: createUser

View File

@@ -1,10 +1,10 @@
##
# Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
# Copyright © 2019-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
##
swagger: "2.0"
info:
version: "2.4.0"
version: "2.4.1"
title: Smartphone Test Farm
description: Control and manages real Smartphone devices from browser and restful apis
license:
@@ -728,6 +728,62 @@ paths:
$ref: "#/definitions/UnexpectedErrorResponse"
security:
- accessTokenAuth: []
/users/alertMessage:
x-swagger-router-controller: users
get:
summary: Gets the users alert message
description: The Users Alert Message endpoint returns the current alert message launched by the administrator user
operationId: getUsersAlertMessage
tags:
- users
parameters:
- name: fields
in: query
description: Fields query parameter takes a comma seperated list of fields. Only listed field will be return in response
required: false
type: string
responses:
"200":
description: Current Users Alert Message
schema:
$ref: "#/definitions/AlertMessageResponse"
default:
description: >
Unexpected Error:
* 401: Unauthorized => bad credentials
* 500: Internal Server Error
schema:
$ref: "#/definitions/UnexpectedErrorResponse"
security:
- accessTokenAuth: []
put:
summary: Updates the users alert message
description: Updates the users alert message
operationId: updateUsersAlertMessage
tags:
- admin
parameters:
- name: alertMessage
in: body
description: Alert message properties
required: true
schema:
$ref: "#/definitions/AlertMessagePayload"
responses:
"200":
description: Updated Users Alert Message
schema:
$ref: "#/definitions/AlertMessageResponse"
default:
description: >
Unexpected Error:
* 400: Bad Request
* 401: Unauthorized => bad credentials
* 500: Internal Server Error
schema:
$ref: "#/definitions/UnexpectedErrorResponse"
security:
- accessTokenAuth: []
/users/groupsQuotas:
x-swagger-router-controller: users
put:
@@ -2270,6 +2326,49 @@ definitions:
type: string
user:
type: object
AlertMessage:
type: object
properties:
activation:
description: Enable or disablee the alert message
type: string
data:
description: Alert message text to display
type: string
level:
description: Alert message level
type: string
AlertMessageResponse:
required:
- success
- description
- alertMessage
properties:
success:
type: boolean
description:
type: string
alertMessage:
$ref: '#/definitions/AlertMessage'
AlertMessagePayload:
description: Payload object for updating the alert message
properties:
activation:
description: Enable or disablee the alert message
type: string
enum:
- 'True'
- 'False'
data:
description: Alert message text to display
type: string
level:
description: Alert message level
type: string
enum:
- Information
- Warning
- Critical
Token:
type: object
properties: