Leosac  0.7.0
OpenSourceAccessControl
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 
95  IAccessProfilePtr profile();
96 
97  void profile(IAccessProfilePtr p);
98 
106  const UserGroupMembershipSet &user_memberships() const;
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
This is the header file for a generated source file, GitSHA1.cpp.
std::string name_
Definition: Group.hpp:154
static void validate(const Group &grp)
Validate the group&#39;s attributes.
Definition: Group.cpp:167
A authentication group regroup users that share permissions.
Definition: Group.hpp:57
std::shared_ptr< ScheduleMapping > ScheduleMappingPtr
Definition: ToolsFwd.hpp:41
unsigned long GroupId
Definition: AuthFwd.hpp:41
unsigned long UserId
Definition: AuthFwd.hpp:34
IAccessProfilePtr profile_
Definition: Group.hpp:164
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
GroupRank
The rank of an User inside a Group.
Definition: AuthFwd.hpp:49
GroupId id_
The group identifier.
Definition: Group.hpp:135
std::shared_ptr< UserGroupMembership > UserGroupMembershipPtr
Definition: AuthFwd.hpp:81
std::set< UserGroupMembershipPtr, UserGroupMembershipComparator > UserGroupMembershipSet
static void validate_name(const std::string &name)
Definition: Group.cpp:172
This is class that can be used to access some object&#39;s internal.
Definition: LeosacFwd.hpp:59
Validate a Group object&#39;s attributes, throwing ModelException if some attributes are invalid...
Definition: Group.hpp:43
std::vector< UserPtr > loaded_members_
This returns a vector of loaded User object.
Definition: Group.hpp:149
const size_t version_
Definition: Group.hpp:167
UserGroupMembershipSet membership_
Definition: Group.hpp:138
std::vector< Tools::ScheduleMappingLWPtr > schedules_mapping_
Definition: Group.hpp:141
std::string description_
A (potentially long) description of the group.
Definition: Group.hpp:161