Leosac  0.7.0
OpenSourceAccessControl
ScheduleMapping.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 "core/auth/AuthFwd.hpp"
24 #include "tools/ToolsFwd.hpp"
25 #include <vector>
26 
27 namespace Leosac
28 {
29 namespace Tools
30 {
36 #pragma db object optimistic
37 struct ScheduleMapping : public std::enable_shared_from_this<ScheduleMapping>
38 {
39  ScheduleMappingId id() const;
40 
41  const std::string &alias() const;
42  void alias(const std::string &);
43 
47  ScheduleId schedule_id() const;
48 
49  ScheduleLWPtr schedule() const;
50 
51  const std::vector<Auth::UserLWPtr> &users() const;
52  const std::vector<Auth::GroupLWPtr> &groups() const;
53  const std::vector<Cred::CredentialLWPtr> &credentials() const;
54  const std::vector<Auth::DoorLWPtr> &doors() const;
55 
56  size_t odb_version() const;
57 
62  bool has_user(Auth::UserId) const;
63 
67  bool has_group(Auth::GroupId) const;
68 
72  bool has_cred(Cred::CredentialId) const;
73 
77  bool has_door(Auth::DoorId) const;
78 
86  bool has_user_indirect(Auth::UserPtr) const;
87 
94  void add_door(const Auth::DoorLPtr &door);
95 
96  void clear_doors();
97 
104  void add_user(const Auth::UserLPtr &user);
105 
106  void clear_users();
107 
114  void add_group(const Auth::GroupLPtr &group);
115 
116  void clear_groups();
117 
124  void add_credential(const Cred::CredentialLPtr &cred);
125 
126  void clear_credential();
127 
128 #pragma db id auto
130 
131  protected:
132 #pragma db id_column("schedule_mapping_id") value_column("user_id")
133 #pragma db value_not_null unordered
134 #pragma db on_delete(cascade)
135  std::vector<Auth::UserLWPtr> users_;
136 
137 #pragma db id_column("schedule_mapping_id") value_column("group_id")
138 #pragma db value_not_null unordered
139 #pragma db on_delete(cascade)
140  std::vector<Auth::GroupLWPtr> groups_;
141 
142 #pragma db id_column("schedule_mapping_id") value_column("credential_id")
143 #pragma db value_not_null unordered
144 #pragma db on_delete(cascade)
145  std::vector<Cred::CredentialLWPtr> creds_;
146 
147 #pragma db id_column("schedule_mapping_id") value_column("door_id")
148 #pragma db value_not_null unordered
149 #pragma db on_delete(cascade)
150  std::vector<Auth::DoorLWPtr> doors_;
151 
155 #pragma db not_null inverse(mapping_)
157 
161  std::string alias_;
162 
163 #pragma db version
164  size_t odb_version_;
165 
166  private:
167  friend class Schedule;
168  friend class odb::access;
169 };
170 }
171 }
172 
173 #ifdef ODB_COMPILER
174 #include "core/auth/Door.hpp"
175 #include "core/auth/Group.hpp"
176 #include "core/auth/User.hpp"
178 #include "tools/Schedule.hpp"
179 #endif
void add_user(const Auth::UserLPtr &user)
Add a user to the mapping.
odb::lazy_weak_ptr< Schedule > ScheduleLWPtr
Definition: ToolsFwd.hpp:34
std::vector< Auth::DoorLWPtr > doors_
void add_credential(const Cred::CredentialLPtr &cred)
Add a credential to the mapping.
const std::vector< Auth::DoorLWPtr > & doors() const
bool has_user_indirect(Auth::UserPtr) const
Check wether the user is mapped, either directly or not, by this ScheduleMapping object.
ScheduleLWPtr schedule() const
ScheduleId schedule_id() const
Retrieve the id of the owning schedule.
This is the header file for a generated source file, GitSHA1.cpp.
odb::lazy_shared_ptr< Door > DoorLPtr
Definition: AuthFwd.hpp:111
odb::lazy_shared_ptr< User > UserLPtr
Definition: AuthFwd.hpp:32
const std::vector< Cred::CredentialLWPtr > & credentials() const
std::string alias_
A non unique, optional alias.
Represent one of the mapping of a schedule.
unsigned long GroupId
Definition: AuthFwd.hpp:41
unsigned long UserId
Definition: AuthFwd.hpp:34
ScheduleLWPtr schedule_
The schedule that owns the mapping.
unsigned long DoorId
Definition: AuthFwd.hpp:107
const std::string & alias() const
bool has_user(Auth::UserId) const
Check if the user with id uid is directly part of the mapping.
const std::vector< Auth::GroupLWPtr > & groups() const
const std::vector< Auth::UserLWPtr > & users() const
void add_door(const Auth::DoorLPtr &door)
Add a door to the mapping.
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
unsigned long ScheduleId
Definition: ToolsFwd.hpp:33
A schedule is simply a list of time frame (SingleTimeFrame) with a name.
Definition: Schedule.hpp:41
bool has_group(Auth::GroupId) const
Check if the group is directly mapping by the ScheduleMapping object.
unsigned long CredentialId
std::vector< Auth::UserLWPtr > users_
std::vector< Cred::CredentialLWPtr > creds_
odb::lazy_shared_ptr< Group > GroupLPtr
Definition: AuthFwd.hpp:40
ScheduleMappingId id() const
odb::lazy_shared_ptr< Credential > CredentialLPtr
unsigned long ScheduleMappingId
Definition: ToolsFwd.hpp:44
std::vector< Auth::GroupLWPtr > groups_
bool has_cred(Cred::CredentialId) const
Check if the credential is mapped by this ScheduleMapping.
bool has_door(Auth::DoorId) const
Check if the door is mapped by this object.
void add_group(const Auth::GroupLPtr &group)
Add a group to the mapping.