ORE Studio 0.0.4
Loading...
Searching...
No Matches
role_permission_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_ROLE_PERMISSION_REPOSITORY_HPP
21#define ORES_ACCOUNTS_REPOSITORY_ROLE_PERMISSION_REPOSITORY_HPP
22
23#include <map>
24#include <string>
25#include <vector>
26#include <boost/uuid/uuid.hpp>
27#include <sqlgen/postgres.hpp>
28#include "ores.utility/log/make_logger.hpp"
29#include "ores.database/domain/context.hpp"
30#include "ores.accounts/domain/role_permission.hpp"
31
32namespace ores::accounts::repository {
33
38private:
39 inline static std::string_view logger_name =
40 "ores.accounts.repository.role_permission_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
52
56 std::string sql();
57
62 void write(const domain::role_permission& role_permission);
63 void write(const std::vector<domain::role_permission>& role_permissions);
69 std::vector<domain::role_permission> read_latest();
70
74 std::vector<domain::role_permission>
75 read_latest_by_role(const boost::uuids::uuid& role_id);
76
80 std::vector<domain::role_permission>
81 read_latest_by_permission(const boost::uuids::uuid& permission_id);
82
86 void remove(const boost::uuids::uuid& role_id,
87 const boost::uuids::uuid& permission_id);
88
92 void remove_all_for_role(const boost::uuids::uuid& role_id);
93
100 std::map<std::string, std::vector<std::string>> read_all_role_permission_codes();
101
108 std::map<std::string, std::vector<std::string>>
109 read_role_permission_codes(const std::vector<boost::uuids::uuid>& role_ids);
110
111private:
112 context ctx_;
113};
114
115}
116
117#endif
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Represents the assignment of a permission to a role.
Definition role_permission.hpp:34
Reads and writes role-permission assignments to data storage.
Definition role_permission_repository.hpp:37
void remove(const boost::uuids::uuid &role_id, const boost::uuids::uuid &permission_id)
Removes a specific role-permission assignment.
Definition role_permission_repository.cpp:103
std::map< std::string, std::vector< std::string > > read_all_role_permission_codes()
Gets all role-permission mappings with permission codes in a single query.
Definition role_permission_repository.cpp:136
std::vector< domain::role_permission > read_latest_by_role(const boost::uuids::uuid &role_id)
Reads all permissions assigned to a specific role.
Definition role_permission_repository.cpp:73
std::vector< domain::role_permission > read_latest_by_permission(const boost::uuids::uuid &permission_id)
Reads all roles that have a specific permission.
Definition role_permission_repository.cpp:88
void write(const domain::role_permission &role_permission)
Writes role-permission assignments to database.
Definition role_permission_repository.cpp:44
std::map< std::string, std::vector< std::string > > read_role_permission_codes(const std::vector< boost::uuids::uuid > &role_ids)
Gets permission codes for specific roles in a single query.
Definition role_permission_repository.cpp:148
std::vector< domain::role_permission > read_latest()
Reads all active role-permission assignments.
Definition role_permission_repository.cpp:61
void remove_all_for_role(const boost::uuids::uuid &role_id)
Removes all permission assignments for a role.
Definition role_permission_repository.cpp:121
std::string sql()
Returns the SQL created by sqlgen to construct the table.
Definition role_permission_repository.cpp:37
Context for the operations on a postgres database.
Definition context.hpp:30