ORE Studio 0.0.4
Loading...
Searching...
No Matches
system_flags_service.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 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_FLAGS_SERVICE_HPP
21#define ORES_VARIABILITY_SERVICE_SYSTEM_FLAGS_SERVICE_HPP
22
23#include <string_view>
24#include "ores.utility/log/make_logger.hpp"
25#include "ores.database/domain/context.hpp"
26#include "ores.variability/domain/system_flags.hpp"
27#include "ores.variability/domain/system_flags_cache.hpp"
28#include "ores.variability/service/feature_flags_service.hpp"
29
30namespace ores::variability::service {
31
48private:
49 inline static std::string_view logger_name =
50 "ores.variability.service.system_flags_service";
51
52 [[nodiscard]] static auto& lg() {
53 using namespace ores::utility::log;
54 static auto instance = make_logger(logger_name);
55 return instance;
56 }
57
58public:
65
72 void refresh();
73
82 [[nodiscard]] const domain::system_flags_cache& cache() const;
83
92 [[nodiscard]] bool is_enabled(domain::system_flag flag) const;
93
103 void set_enabled(domain::system_flag flag, bool enabled,
104 std::string_view recorded_by);
105
106 // Convenience methods for specific flags
107
113 [[nodiscard]] bool is_bootstrap_mode_enabled() const;
114
123 void set_bootstrap_mode(bool enabled, std::string_view recorded_by);
124
130 [[nodiscard]] bool is_user_signups_enabled() const;
131
140 void set_user_signups(bool enabled, std::string_view recorded_by);
141
142private:
146 void update_cache(domain::system_flag flag, bool enabled);
147
148 feature_flags_service feature_flags_service_;
150};
151
152}
153
154#endif
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Context for the operations on a postgres database.
Definition context.hpp:30
POD containing cached values of well-known system flags.
Definition system_flags_cache.hpp:34
Service for managing feature flags.
Definition feature_flags_service.hpp:39
Service for accessing well-known system flags with type-safe methods.
Definition system_flags_service.hpp:47
const domain::system_flags_cache & cache() const
Gets a const reference to the cached system flags.
Definition system_flags_service.cpp:47
void set_user_signups(bool enabled, std::string_view recorded_by)
Sets the user signups state.
Definition system_flags_service.cpp:97
bool is_user_signups_enabled() const
Checks if user self-registration (signups) is enabled (from cache).
Definition system_flags_service.cpp:93
void refresh()
Refreshes the cache by reading all system flags from the database.
Definition system_flags_service.cpp:30
bool is_enabled(domain::system_flag flag) const
Checks if a system flag is enabled (from cache).
Definition system_flags_service.cpp:51
bool is_bootstrap_mode_enabled() const
Checks if the system is in bootstrap mode (from cache).
Definition system_flags_service.cpp:84
void set_enabled(domain::system_flag flag, bool enabled, std::string_view recorded_by)
Sets a system flag's enabled state.
Definition system_flags_service.cpp:64
void set_bootstrap_mode(bool enabled, std::string_view recorded_by)
Sets the bootstrap mode state.
Definition system_flags_service.cpp:88