ORE Studio 0.0.4
Loading...
Searching...
No Matches
system_settings_service.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_VARIABILITY_SERVICE_SYSTEM_SETTINGS_SERVICE_HPP
21#define ORES_VARIABILITY_SERVICE_SYSTEM_SETTINGS_SERVICE_HPP
22
23#include <string>
24#include <string_view>
25#include <optional>
26#include <vector>
27#include "ores.logging/make_logger.hpp"
28#include "ores.database/domain/context.hpp"
29#include "ores.variability.api/domain/system_setting.hpp"
30#include "ores.variability.core/repository/system_settings_repository.hpp"
31
33
42private:
43 inline static std::string_view logger_name =
44 "ores.variability.service.system_settings_service";
45
46 [[nodiscard]] static auto& lg() {
47 using namespace ores::logging;
48 static auto instance = make_logger(logger_name);
49 return instance;
50 }
51
52public:
61 std::string tenant_id = {});
62
63 // -------------------------------------------------------------------------
64 // Raw access
65 // -------------------------------------------------------------------------
66
70 [[nodiscard]] std::optional<domain::system_setting>
71 get(const std::string& name);
72
76 [[nodiscard]] std::vector<domain::system_setting> get_all();
77
81 void save(const domain::system_setting& setting);
82
86 void remove(const std::string& name);
87
91 [[nodiscard]] std::vector<domain::system_setting>
92 get_history(const std::string& name);
93
94 // -------------------------------------------------------------------------
95 // Typed accessors (return registry default if absent from DB)
96 // -------------------------------------------------------------------------
97
104 [[nodiscard]] bool get_bool(std::string_view name) const;
105
111 [[nodiscard]] int get_int(std::string_view name) const;
112
118 [[nodiscard]] std::string get_string(std::string_view name) const;
119
126 [[nodiscard]] std::string get_json(std::string_view name) const;
127
131 void refresh();
132
133 // -------------------------------------------------------------------------
134 // Convenience methods
135 // -------------------------------------------------------------------------
136
137 [[nodiscard]] bool is_bootstrap_mode_enabled() const;
138 void set_bootstrap_mode(bool enabled, std::string_view modified_by,
139 std::string_view change_reason_code,
140 std::string_view change_commentary);
141
142 [[nodiscard]] bool is_user_signups_enabled() const;
143 void set_user_signups(bool enabled, std::string_view modified_by,
144 std::string_view change_reason_code,
145 std::string_view change_commentary);
146
147 [[nodiscard]] bool is_signup_requires_authorization_enabled() const;
148 void set_signup_requires_authorization(bool enabled,
149 std::string_view modified_by,
150 std::string_view change_reason_code,
151 std::string_view change_commentary);
152
153 [[nodiscard]] bool is_password_validation_disabled() const;
154
155private:
156 void set_bool_setting(std::string_view name, bool value,
157 std::string_view modified_by,
158 std::string_view change_reason_code,
159 std::string_view change_commentary);
160
161 // Cache: name → value text, populated by refresh()
162 std::unordered_map<std::string, std::string> cache_;
163
165 std::string tenant_id_;
167};
168
169}
170
171#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Service layer for the variability module.
Definition ores.variability.service.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
Represents a typed system setting in the domain layer.
Definition system_setting.hpp:35
Reads and writes system settings from data storage.
Definition system_settings_repository.hpp:36
Service for managing typed system settings.
Definition system_settings_service.hpp:41
std::string get_json(std::string_view name) const
Returns the JSON value of a setting as a raw string.
Definition system_settings_service.cpp:138
std::string get_string(std::string_view name) const
Returns the string value of a setting.
Definition system_settings_service.cpp:131
std::vector< domain::system_setting > get_all()
Retrieves all currently active settings.
Definition system_settings_service.cpp:51
int get_int(std::string_view name) const
Returns the integer value of a setting.
Definition system_settings_service.cpp:115
void remove(const std::string &name)
Logically removes a setting.
Definition system_settings_service.cpp:72
void refresh()
Refreshes the in-memory cache by re-reading all settings from the DB.
Definition system_settings_service.cpp:89
void save(const domain::system_setting &setting)
Saves a setting using the bitemporal update pattern.
Definition system_settings_service.cpp:56
std::optional< domain::system_setting > get(const std::string &name)
Retrieves a single setting by name (latest active version).
Definition system_settings_service.cpp:35
bool get_bool(std::string_view name) const
Returns the boolean value of a setting.
Definition system_settings_service.cpp:100
std::vector< domain::system_setting > get_history(const std::string &name)
Retrieves all historical versions of a setting.
Definition system_settings_service.cpp:79