Leosac  0.8.0
Open Source Access Control
ScheduleEventSerializer.cpp
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 
21 #include "AuditSerializer.hpp"
22 #include "core/SecurityContext.hpp"
24 #include "tools/log.hpp"
25 
26 namespace Leosac
27 {
28 namespace Audit
29 {
30 namespace Serializer
31 {
33  const SecurityContext &sc)
34 {
35  auto serialized = Audit::Serializer::AuditJSON::serialize(in, sc);
36  // Now we override the type.
37  ASSERT_LOG(serialized.at("type").is_string(),
38  "Base audit serialization did something unexpected.");
39  serialized["type"] = "audit-schedule-event";
40 
41  serialized["relationships"]["target"] = {
42  {{"id", in.target_id()}, {"type", "schedule"}}};
43 
45  {
46  serialized["attributes"]["before"] = in.before();
47  serialized["attributes"]["after"] = in.after();
48  }
49 
50  return serialized;
51 }
52 }
53 }
54 }
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
Leosac::SecurityContext::check_permission
virtual bool check_permission(Action a, const ActionParam &ap) const
Check for the permission to perform action a with parameters ap.
Definition: SecurityContext.cpp:30
AuditSerializer.hpp
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac::Audit::IScheduleEvent::before
virtual void before(const std::string &repr)=0
An optional JSON representation of the object before the event took place.
ScheduleEventSerializer.hpp
Leosac::Audit::IScheduleEvent::after
virtual void after(const std::string &repr)=0
An optional JSON representation of the object after the event took place.
SecurityContext.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Audit::Serializer::AuditJSON::serialize
static json serialize(const Audit::IAuditEntry &in, const SecurityContext &sc)
Definition: AuditSerializer.cpp:30
Leosac::Audit::IScheduleEvent::target_id
virtual Tools::ScheduleId target_id() const =0
Leosac::Audit::IScheduleEvent
Audit interface to Schedule related events.
Definition: IScheduleEvent.hpp:32
log.hpp
IScheduleEvent.hpp
Leosac::SecurityContext::Action::AUDIT_READ_FULL
@ AUDIT_READ_FULL
Read the audit log and access additional information, such as the JSON "before" and "after" field.
Leosac::Audit::Serializer::ScheduleEventJSON::serialize
static json serialize(const Audit::IScheduleEvent &in, const SecurityContext &sc)
Definition: ScheduleEventSerializer.cpp:32
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40