ORE Studio 0.0.4
Loading...
Searching...
No Matches
account_role_repository.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_ACCOUNTS_REPOSITORY_ACCOUNT_ROLE_REPOSITORY_HPP
21#define ORES_ACCOUNTS_REPOSITORY_ACCOUNT_ROLE_REPOSITORY_HPP
22
23#include <string>
24#include <vector>
25#include <boost/uuid/uuid.hpp>
26#include <sqlgen/postgres.hpp>
27#include "ores.utility/log/make_logger.hpp"
28#include "ores.database/domain/context.hpp"
29#include "ores.accounts/domain/account_role.hpp"
30#include "ores.accounts/domain/role.hpp"
31
32namespace ores::accounts::repository {
33
38private:
39 inline static std::string_view logger_name =
40 "ores.accounts.repository.account_role_repository";
41
42 [[nodiscard]] static auto& lg() {
43 using namespace ores::utility::log;
44 static auto instance = make_logger(logger_name);
45 return instance;
46 }
47
48public:
50
51 explicit account_role_repository(context ctx);
52
56 std::string sql();
57
62 void write(const domain::account_role& account_role);
63 void write(const std::vector<domain::account_role>& account_roles);
69 std::vector<domain::account_role> read_latest();
70
74 std::vector<domain::account_role>
75 read_latest_by_account(const boost::uuids::uuid& account_id);
76
80 std::vector<domain::account_role>
81 read_latest_by_role(const boost::uuids::uuid& role_id);
82
88 bool exists(const boost::uuids::uuid& account_id,
89 const boost::uuids::uuid& role_id);
90
94 void remove(const boost::uuids::uuid& account_id,
95 const boost::uuids::uuid& role_id);
96
100 void remove_all_for_account(const boost::uuids::uuid& account_id);
101
108 std::vector<std::string>
109 read_effective_permissions(const boost::uuids::uuid& account_id);
110
117 std::vector<domain::role>
118 read_roles_with_permissions(const boost::uuids::uuid& account_id);
119
120private:
121 context ctx_;
122};
123
124}
125
126#endif
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Represents the assignment of a role to an account.
Definition account_role.hpp:36
Reads and writes account-role assignments to data storage.
Definition account_role_repository.hpp:37
void remove(const boost::uuids::uuid &account_id, const boost::uuids::uuid &role_id)
Removes a specific account-role assignment.
Definition account_role_repository.cpp:125
void write(const domain::account_role &account_role)
Writes account-role assignments to database.
Definition account_role_repository.cpp:45
std::vector< domain::account_role > read_latest_by_role(const boost::uuids::uuid &role_id)
Reads all accounts assigned to a specific role.
Definition account_role_repository.cpp:88
std::vector< std::string > read_effective_permissions(const boost::uuids::uuid &account_id)
Gets all effective permission codes for an account in a single query.
Definition account_role_repository.cpp:157
bool exists(const boost::uuids::uuid &account_id, const boost::uuids::uuid &role_id)
Checks if a specific account-role assignment exists.
Definition account_role_repository.cpp:102
std::vector< domain::account_role > read_latest_by_account(const boost::uuids::uuid &account_id)
Reads all roles assigned to a specific account.
Definition account_role_repository.cpp:73
std::string sql()
Returns the SQL created by sqlgen to construct the table.
Definition account_role_repository.cpp:38
std::vector< domain::role > read_roles_with_permissions(const boost::uuids::uuid &account_id)
Gets all roles assigned to an account with their permissions.
Definition account_role_repository.cpp:174
std::vector< domain::account_role > read_latest()
Reads all active account-role assignments.
Definition account_role_repository.cpp:61
void remove_all_for_account(const boost::uuids::uuid &account_id)
Removes all role assignments for an account.
Definition account_role_repository.cpp:142
Context for the operations on a postgres database.
Definition context.hpp:30