15.2.147. camcops_server.cc_modules.cc_serversettings

camcops_server/cc_modules/cc_serversettings.py


Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.


Represents server-wide configuration settings.

Previously, we had a key/value pair system, both for device stored variables (table “storedvars”) and server ones (“_server_storedvars”). We used a “type” column to indicate type, and then columns named “valueInteger”, “valueText”, “valueReal” for the actual values.

Subsequently

  • There’s no need for devices to upload their settings here, so that table goes.

  • The server stored vars stored

idDescription1 - idDescription8             } now have their own table
idShortDescription1 - idShortDescription8   }

idPolicyUpload                              } now part of Group definition
idPolicyFinalize                            }

lastAnalyticsSentAt                         now unused

serverCamcopsVersion                        unnecessary (is in code)

databaseTitle                               still needed somehow

So, two options: https://stackoverflow.com/questions/2300356/using-a-single-row-configuration-table-in-sql-server-database-bad-idea

Let’s use a single row, based on a fixed PK (of 1).

On some databases, you can constrain the PK value to enforce “one row only”; MySQL isn’t one of those.

class camcops_server.cc_modules.cc_serversettings.ServerSettings(**kwargs)[source]

Singleton SQLAlchemy object (i.e. there is just one row in the database table) representing server settings.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

get_last_dummy_login_failure_clearance_pendulum() Optional[pendulum.datetime.DateTime][source]

Returns the time at which login failure records were cleared for nonexistent users.

This is part of a security failure to prevent attackers discovering usernames: since repeated attempts to hack a real account leads to an account lockout, we arrange things so that attempts to hack nonexistent accounts do likewise.

Specifically, this function returns an offset-aware (timezone-aware) version of the raw UTC DATETIME from the database.

class camcops_server.cc_modules.cc_serversettings.ServerStoredVarNamesDefunct[source]

Variable names for the ServerStoredVars system.

Defunct, but maintained for database imports.

class camcops_server.cc_modules.cc_serversettings.StoredVarTypesDefunct[source]

Variable types for the ServerStoredVars system.

Defunct, but maintained for database imports.

camcops_server.cc_modules.cc_serversettings.get_server_settings(req: CamcopsRequest) camcops_server.cc_modules.cc_serversettings.ServerSettings[source]

Gets the camcops_server.cc_modules.cc_serversettings.ServerSettings object for the request.