Leosac  0.8.0
Open Source Access Control
AuditSerializer.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 
20 #include "AuditSerializer.hpp"
22 #include <boost/date_time/posix_time/conversion.hpp>
23 
24 namespace Leosac
25 {
26 namespace Audit
27 {
28 namespace Serializer
29 {
31 {
32  auto timestamp = boost::posix_time::to_time_t(in.timestamp());
33 
34  json serialized = {
35  {"id", in.id()},
36  {"type", "audit-entry"},
37  {"attributes",
38  {
39  {"event-mask", static_cast<unsigned long>(in.event_mask())},
40  {"timestamp", timestamp},
41  {"description", in.generate_description()},
42  {"finalized", in.finalized()},
43  }}};
44 
45  if (in.author_id())
46  {
47  serialized["relationships"]["author"] = {
48  {"data", {{"id", in.author_id()}, {"type", "user"}}}};
49  }
50  return serialized;
51 }
52 }
53 }
54 }
Leosac::json
nlohmann::json json
Definition: AuditSerializer.hpp:29
AuditSerializer.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::IAuditEntry::timestamp
virtual boost::posix_time::ptime timestamp() const =0
Retrieve unix timestamp.
Leosac::Audit::IAuditEntry::generate_description
virtual std::string generate_description() const
Generate a description for this event.
Definition: IAuditEntry.hpp:173
Leosac::Audit::IAuditEntry::author_id
virtual Auth::UserId author_id() const =0
Retrieve the user id of the author of this entry.
Leosac::Audit::IAuditEntry
Base interface to Audit object.
Definition: IAuditEntry.hpp:47
IAuditEntry.hpp
Leosac::Audit::IAuditEntry::event_mask
virtual void event_mask(const EventMask &mask)=0
Set the event mask for the entry.
Leosac::Audit::IAuditEntry::id
virtual AuditEntryId id() const =0
Retrieve the identifier of the entry.
Leosac::SecurityContext
A SecurityContext is used to query permission while doing an operation.
Definition: SecurityContext.hpp:40
Leosac::Audit::IAuditEntry::finalized
virtual bool finalized() const =0
Is this entry finalized.