Leosac  0.8.0
Open Source Access Control
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
Leosac::Tools::ScheduleMapping::schedule_id
ScheduleId schedule_id() const
Retrieve the id of the owning schedule.
Definition: ScheduleMapping.cpp:50
Leosac::Tools::ScheduleMapping
Represent one of the mapping of a schedule.
Definition: ScheduleMapping.hpp:37
Leosac::Tools::ScheduleMapping::add_group
void add_group(const Auth::GroupLPtr &group)
Add a group to the mapping.
Definition: ScheduleMapping.cpp:142
Leosac::Tools::ScheduleMapping::add_user
void add_user(const Auth::UserLPtr &user)
Add a user to the mapping.
Definition: ScheduleMapping.cpp:133
Leosac::Auth::GroupLPtr
odb::lazy_shared_ptr< Group > GroupLPtr
Definition: AuthFwd.hpp:40
Leosac::Tools::ScheduleMapping::doors
const std::vector< Auth::DoorLWPtr > & doors() const
Definition: ScheduleMapping.cpp:175
Leosac::Tools::ScheduleMapping::schedule
ScheduleLWPtr schedule() const
Definition: ScheduleMapping.cpp:57
AuthFwd.hpp
Leosac::Tools::ScheduleMapping::credentials
const std::vector< Cred::CredentialLWPtr > & credentials() const
Definition: ScheduleMapping.cpp:170
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
Leosac::Tools::ScheduleMapping::alias_
std::string alias_
A non unique, optional alias.
Definition: ScheduleMapping.hpp:161
User.hpp
Leosac::Tools::ScheduleMapping::odb_version
size_t odb_version() const
Definition: ScheduleMapping.cpp:200
Leosac::Tools::ScheduleMapping::schedule_
ScheduleLWPtr schedule_
The schedule that owns the mapping.
Definition: ScheduleMapping.hpp:156
Leosac::Tools::ScheduleMapping::has_user
bool has_user(Auth::UserId) const
Check if the user with id uid is directly part of the mapping.
Definition: ScheduleMapping.cpp:62
Leosac::Tools::ScheduleMapping::alias
const std::string & alias() const
Definition: ScheduleMapping.cpp:40
Credential.hpp
Leosac::Tools::ScheduleMapping::access
friend class odb::access
Definition: ScheduleMapping.hpp:168
Door.hpp
Leosac::Tools::ScheduleMapping::clear_users
void clear_users()
Definition: ScheduleMapping.cpp:185
ToolsFwd.hpp
Leosac::Tools::ScheduleMapping::users
const std::vector< Auth::UserLWPtr > & users() const
Definition: ScheduleMapping.cpp:160
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::ScheduleMapping::add_door
void add_door(const Auth::DoorLPtr &door)
Add a door to the mapping.
Definition: ScheduleMapping.cpp:124
Leosac::Auth::UserLPtr
odb::lazy_shared_ptr< User > UserLPtr
Definition: AuthFwd.hpp:32
Leosac::Tools::ScheduleMapping::clear_doors
void clear_doors()
Definition: ScheduleMapping.cpp:180
Leosac::Tools::ScheduleMapping::id_
ScheduleMappingId id_
Definition: ScheduleMapping.hpp:129
Leosac::Auth::DoorId
unsigned long DoorId
Definition: AuthFwd.hpp:107
Group.hpp
Leosac::Tools::ScheduleId
unsigned long ScheduleId
Definition: ToolsFwd.hpp:33
Leosac::Tools::ScheduleMapping::groups
const std::vector< Auth::GroupLWPtr > & groups() const
Definition: ScheduleMapping.cpp:165
Leosac::Tools::ScheduleLWPtr
odb::lazy_weak_ptr< Schedule > ScheduleLWPtr
Definition: ToolsFwd.hpp:34
Leosac::Tools::ScheduleMappingId
unsigned long ScheduleMappingId
Definition: ToolsFwd.hpp:44
Leosac::Tools::ScheduleMapping::odb_version_
size_t odb_version_
Definition: ScheduleMapping.hpp:164
Leosac::Tools::ScheduleMapping::creds_
std::vector< Cred::CredentialLWPtr > creds_
Definition: ScheduleMapping.hpp:145
Leosac::Cred::CredentialId
unsigned long CredentialId
Definition: CredentialFwd.hpp:35
Leosac::Auth::GroupId
unsigned long GroupId
Definition: AuthFwd.hpp:41
Leosac::Cred::CredentialLPtr
odb::lazy_shared_ptr< Credential > CredentialLPtr
Definition: CredentialFwd.hpp:38
Leosac::Tools::ScheduleMapping::clear_credential
void clear_credential()
Definition: ScheduleMapping.cpp:195
Leosac::Tools::ScheduleMapping::id
ScheduleMappingId id() const
Definition: ScheduleMapping.cpp:35
Leosac::Tools::ScheduleMapping::has_group
bool has_group(Auth::GroupId) const
Check if the group is directly mapping by the ScheduleMapping object.
Definition: ScheduleMapping.cpp:72
Leosac::Auth::UserId
unsigned long UserId
Definition: AuthFwd.hpp:34
Leosac::Tools::ScheduleMapping::clear_groups
void clear_groups()
Definition: ScheduleMapping.cpp:190
CredentialFwd.hpp
Leosac::Tools::ScheduleMapping::groups_
std::vector< Auth::GroupLWPtr > groups_
Definition: ScheduleMapping.hpp:140
Leosac::Tools::Schedule
A schedule is simply a list of time frame (SingleTimeFrame) with a name.
Definition: Schedule.hpp:41
Leosac::Tools::ScheduleMapping::has_cred
bool has_cred(Cred::CredentialId) const
Check if the credential is mapped by this ScheduleMapping.
Definition: ScheduleMapping.cpp:82
Schedule.hpp
Leosac::Tools::ScheduleMapping::has_door
bool has_door(Auth::DoorId) const
Check if the door is mapped by this object.
Definition: ScheduleMapping.cpp:92
Leosac::Auth::DoorLPtr
odb::lazy_shared_ptr< Door > DoorLPtr
Definition: AuthFwd.hpp:111
Leosac::Tools::ScheduleMapping::users_
std::vector< Auth::UserLWPtr > users_
Definition: ScheduleMapping.hpp:135
Leosac::Tools::ScheduleMapping::doors_
std::vector< Auth::DoorLWPtr > doors_
Definition: ScheduleMapping.hpp:150
Leosac::Tools::ScheduleMapping::has_user_indirect
bool has_user_indirect(Auth::UserPtr) const
Check wether the user is mapped, either directly or not, by this ScheduleMapping object.
Definition: ScheduleMapping.cpp:102
Leosac::Tools::ScheduleMapping::add_credential
void add_credential(const Cred::CredentialLPtr &cred)
Add a credential to the mapping.
Definition: ScheduleMapping.cpp:151