Leosac  0.8.0
Open Source Access Control
Group.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "LeosacFwd.hpp"
23 #include "core/auth/AuthFwd.hpp"
25 #include "tools/ToolsFwd.hpp"
26 #include "tools/db/database.hpp"
27 #include <odb/callback.hxx>
28 #include <string>
29 #include <vector>
30 
31 namespace Leosac
32 {
33 namespace Auth
34 {
35 
44 {
45  public:
49  static void validate(const Group &grp);
50  static void validate_name(const std::string &name);
51 };
52 
56 #pragma db object callback(odb_callback) optimistic
57 class Group : public std::enable_shared_from_this<Group>
58 {
59  public:
60  Group();
61  explicit Group(const std::string &group_name);
62 
66  GroupId id() const;
67 
73  void id(const GroupId &new_id);
74 
75  const std::string &name() const;
76  void name(const std::string &name);
77 
78  const std::string &description() const;
79  void description(const std::string &desc);
80 
81  const std::vector<UserPtr> &members() const;
82 
86  std::vector<UserLPtr> lazy_members() const;
87 
91  std::vector<Tools::ScheduleMappingLWPtr> lazy_schedules_mapping() const;
92 
94 
96 
97  void profile(IAccessProfilePtr p);
98 
107 
114  bool member_has(Auth::UserId user_id, GroupRank *rank_out = nullptr) const;
115 
120  void schedule_mapping_added(const Tools::ScheduleMappingPtr &sched_mapping);
121 
122  private:
123  friend class odb::access;
124  friend class GroupValidator;
125  friend class Leosac::TestAccess;
126 
127  void odb_callback(odb::callback_event e, odb::database &) const;
128 
134 #pragma db id auto
136 
137 #pragma db value_not_null inverse(group_)
139 
140 #pragma db value_not_null inverse(groups_)
141  std::vector<Tools::ScheduleMappingLWPtr> schedules_mapping_;
142 
148 #pragma db transient
149  mutable std::vector<UserPtr> loaded_members_;
150 
151 #pragma db not_null
152 #pragma db unique
153 #pragma db type("VARCHAR(128)")
154  std::string name_;
155 
160 #pragma db not_null
161  std::string description_;
162 
163 #pragma db transient
165 
166 #pragma db version
167  const size_t version_;
168 };
169 }
170 }
171 
172 #ifdef ODB_COMPILER
173 #include "core/auth/User.hpp"
174 #endif
Leosac::Auth::Group::user_memberships
const UserGroupMembershipSet & user_memberships() const
Retrieve the UserGroupMembership that this group is involved with.
Definition: Group.cpp:128
Leosac::Auth::Group::name_
std::string name_
Definition: Group.hpp:154
database.hpp
Leosac::Auth::GroupRank::MEMBER
@ MEMBER
Leosac::Auth::Group::profile
IAccessProfilePtr profile()
Definition: Group.cpp:73
Leosac::Auth::Group::id
GroupId id() const
Retrieve the unique identifier of the group.
Definition: Group.cpp:83
Leosac::Auth::Group::version_
const size_t version_
Definition: Group.hpp:167
Leosac::Auth::Group::Group
Group()
Definition: Group.cpp:28
AuthFwd.hpp
Leosac::Auth::Group::membership_
UserGroupMembershipSet membership_
Definition: Group.hpp:138
Leosac::Auth::Group::schedules_mapping_
std::vector< Tools::ScheduleMappingLWPtr > schedules_mapping_
Definition: Group.hpp:141
LeosacFwd.hpp
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
User.hpp
Leosac::Auth::Group::description_
std::string description_
A (potentially long) description of the group.
Definition: Group.hpp:161
Leosac::Auth::IAccessProfilePtr
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
Leosac::Tools::ScheduleMappingPtr
std::shared_ptr< ScheduleMapping > ScheduleMappingPtr
Definition: ToolsFwd.hpp:41
UserGroupMembership.hpp
Leosac::Auth::Group::lazy_schedules_mapping
std::vector< Tools::ScheduleMappingLWPtr > lazy_schedules_mapping() const
Returns the vector of lazy_weak_ptr to schedule mapping.
Definition: Group.cpp:157
Leosac::Auth::Group::odb_callback
void odb_callback(odb::callback_event e, odb::database &) const
Definition: Group.cpp:113
ToolsFwd.hpp
Leosac::Auth::Group::id_
GroupId id_
The group identifier.
Definition: Group.hpp:135
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::GroupValidator
Validate a Group object's attributes, throwing ModelException if some attributes are invalid.
Definition: Group.hpp:43
Leosac::Auth::GroupValidator::validate_name
static void validate_name(const std::string &name)
Definition: Group.cpp:172
Leosac::Auth::Group::member_add
UserGroupMembershipPtr member_add(UserPtr m, GroupRank rank=GroupRank::MEMBER)
Definition: Group.cpp:61
Leosac::Auth::Group
A authentication group regroup users that share permissions.
Definition: Group.hpp:57
Leosac::Auth::Group::access
friend class odb::access
Definition: Group.hpp:123
Leosac::Auth::Group::member_has
bool member_has(Auth::UserId user_id, GroupRank *rank_out=nullptr) const
Check if user_id is a member of this group.
Definition: Group.cpp:143
Leosac::Auth::Group::name
const std::string & name() const
Definition: Group.cpp:41
Leosac::Auth::UserGroupMembershipPtr
std::shared_ptr< UserGroupMembership > UserGroupMembershipPtr
Definition: AuthFwd.hpp:81
Leosac::Auth::Group::profile_
IAccessProfilePtr profile_
Definition: Group.hpp:164
Leosac::Auth::Group::loaded_members_
std::vector< UserPtr > loaded_members_
This returns a vector of loaded User object.
Definition: Group.hpp:149
Leosac::TestAccess
This is class that can be used to access some object's internal.
Definition: LeosacFwd.hpp:59
Leosac::Auth::UserGroupMembershipSet
std::set< UserGroupMembershipPtr, UserGroupMembershipComparator > UserGroupMembershipSet
Definition: UserGroupMembership.hpp:96
Leosac::Auth::GroupId
unsigned long GroupId
Definition: AuthFwd.hpp:41
Leosac::Auth::Group::lazy_members
std::vector< UserLPtr > lazy_members() const
Retrieve lazy pointers to members.
Definition: Group.cpp:93
Leosac::Auth::UserId
unsigned long UserId
Definition: AuthFwd.hpp:34
Leosac::Auth::GroupRank
GroupRank
The rank of an User inside a Group.
Definition: AuthFwd.hpp:49
Leosac::Auth::Group::schedule_mapping_added
void schedule_mapping_added(const Tools::ScheduleMappingPtr &sched_mapping)
The group has been mapped by a schedule.
Definition: Group.cpp:162
Leosac::Auth::Group::members
const std::vector< UserPtr > & members() const
Definition: Group.cpp:46
Leosac::Auth::GroupValidator::validate
static void validate(const Group &grp)
Validate the group's attributes.
Definition: Group.cpp:167
Leosac::Auth::Group::description
const std::string & description() const
Definition: Group.cpp:133