|
Leosac
0.8.0
Open Source Access Control
|
Go to the documentation of this file.
26 #include "core/auth/Group_odb.h"
52 odb::transaction t(db->begin());
61 db->persist(new_group);
76 db->update(new_group);
77 audit_add_to_group->finalize();
89 using Result = odb::result<Auth::Group>;
91 odb::transaction t(db->begin());
103 rep[
"data"] = json::array();
107 for (
const auto &group : result)
109 if (
ctx_.
session->security_context().check_permission(
111 {.group = {.group_id = group.id()}}))
112 rep[
"data"].push_back(
120 boost::optional<json> GroupCRUD::update_impl(
const json &req)
123 DBPtr db = ctx_.dbsrv->db();
124 odb::transaction t(db->begin());
134 validate_and_unique(grp);
145 boost::optional<json> GroupCRUD::delete_impl(
const json &req)
148 DBPtr db = ctx_.dbsrv->db();
149 odb::transaction t(db->begin());
166 using Query = odb::query<Auth::Group>;
169 auto grp_with_same_name =
170 ctx_.dbsrv->db()->query_one<
Auth::Group>(Query::name == grp->name());
173 if (grp_with_same_name && grp_with_same_name != grp)
176 "data/attributes/name",
177 BUILD_STR(
"A group named " << grp->name() <<
" already exists."));
181 std::vector<CRUDResourceHandler::ActionActionParam>
184 std::vector<CRUDResourceHandler::ActionActionParam> ret;
190 catch (
const json::out_of_range &e)
static SecurityContext & instance()
static void unserialize(Auth::Group &out, const json &in, const SecurityContext &sc)
void validate_and_unique(Auth::GroupPtr grp)
Make sure the group's attribute is valid (by calling GroupValidator) and that the name is unique.
#define BUILD_STR(param)
Internal macro.
virtual boost::optional< json > create_impl(const json &req) override
Create a new group.
std::unique_ptr< CRUDResourceHandler > CRUDResourceHandlerUPtr
@ GROUP_MEMBERSHIP_JOINED
Someone joined the group.
Base CRUD handler for use within the websocket module.
std::shared_ptr< odb::database > DBPtr
All modules that provides features to Leosac shall be in this namespace.
odb::query< Tools::LogEntry > Query
static std::string serialize(const Auth::Group &in, const SecurityContext &sc)
This is the header file for a generated source file, GitSHA1.cpp.
GroupCRUD(RequestContext ctx)
static CRUDResourceHandlerUPtr instanciate(RequestContext)
std::shared_ptr< Group > GroupPtr
A authentication group regroup users that share permissions.
An exception class for general API error.
static IGroupEventPtr GroupEvent(const DBPtr &database, Auth::GroupPtr target_group, IAuditEntryPtr parent)
static json serialize(const Auth::Group &group, const SecurityContext &sc)
Audit::IAuditEntryPtr audit
The initial audit trail for the request.
Holds valuable pointer to provide context to a request.
static void validate(const Group &grp)
Validate the group's attributes.
virtual boost::optional< json > read_impl(const json &req) override
Retrieve information about a group.
odb::result< Tools::LogEntry > Result
virtual UserSecurityContext & security_context() const override
Helper function that returns the security context.
static IUserGroupMembershipEventPtr UserGroupMembershipEvent(const DBPtr &database, Auth::GroupPtr target_group, Auth::UserPtr target_user, IAuditEntryPtr parent)