Adding note support.

This commit is contained in:
stephb9959
2021-07-06 16:35:11 -07:00
parent 0566ae3560
commit dbd67205e8
4 changed files with 111 additions and 13 deletions

View File

@@ -275,7 +275,9 @@ components:
waitingForEmailCheck:
type: boolean
notes:
type: string
type: array
items:
$ref: '#/components/schemas/NoteInfo'
location:
type: string
format: uuid
@@ -358,6 +360,17 @@ components:
items:
$ref: '#/components/schemas/TagValuePair'
NoteInfo:
type: object
properties:
created:
type: integer
format: int64
createdBy:
type: string
note:
type: string
SystemCommandDetails:
type: object
properties:
@@ -412,7 +425,9 @@ components:
role:
type: string
notes:
type: string
type: array
items:
$ref: '#/components/schemas/NoteInfo'
SecurityProfileList:
type: object

View File

@@ -232,5 +232,22 @@ namespace uCentral::SecurityObjects {
return false;
}
void NoteInfo::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj,"created", created);
field_to_json(Obj,"createdBy", createdBy);
field_to_json(Obj,"note", note);
}
bool NoteInfo::from_json(Poco::JSON::Object::Ptr Obj) {
try {
field_from_json(Obj,"created",created);
field_from_json(Obj,"createdBy",createdBy);
field_from_json(Obj,"note",note);
} catch(...) {
}
return false;
}
}

View File

@@ -39,7 +39,16 @@ namespace uCentral::SecurityObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct UserInfo {
struct NoteInfo {
uint64_t created = std::time(nullptr);
std::string createdBy;
std::string note;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(Poco::JSON::Object::Ptr Obj);
};
typedef std::vector<NoteInfo> NoteInfoVec;
struct UserInfo {
uint64_t Id = 0;
std::string name;
std::string description;
@@ -57,7 +66,7 @@ namespace uCentral::SecurityObjects {
uint64_t lastEmailCheck = 0;
bool waitingForEmailCheck = false;
std::string locale;
std::string notes;
NoteInfoVec notes;
std::string location;
std::string owner;
bool suspended = false;
@@ -76,6 +85,15 @@ namespace uCentral::SecurityObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct UserInfoAndPolicy {
WebToken webtoken;
UserInfo userinfo;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
typedef std::map<std::string,SecurityObjects::UserInfoAndPolicy> UserInfoCache;
struct InternalServiceInfo {
std::string privateURI;
std::string publicURI;
@@ -108,15 +126,6 @@ namespace uCentral::SecurityObjects {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct UserInfoAndPolicy {
WebToken webtoken;
UserInfo userinfo;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
typedef std::map<std::string,SecurityObjects::UserInfoAndPolicy> UserInfoCache;
}
#endif //UCENTRAL_RESTAPI_SECURITYOBJECTS_H

View File

@@ -8,6 +8,7 @@
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "uCentralTypes.h"
#include "Utils.h"
namespace uCentral::RESTAPI_utils {
@@ -89,6 +90,62 @@ namespace uCentral::RESTAPI_utils {
Value.from_json(A);
}
}
template<class T> std::string to_string(const std::vector<T> & ObjectArray) {
Poco::JSON::Array OutputArr;
if(ObjectArray.empty())
return "[]";
for(auto const &i:ObjectArray) {
Poco::JSON::Object O;
i.to_json(O);
OutputArr.add(O);
}
std::ostringstream OS;
Poco::JSON::Stringifier::condense(OutputArr,OS);
return OS.str();
}
template<class T> std::string to_string(const T & Object) {
Poco::JSON::Object OutputObj;
Object.to_json(OutputObj);
std::ostringstream OS;
Poco::JSON::Stringifier::condense(OutputObj,OS);
return OS.str();
}
template<class T> std::vector<T> to_object_array(const std::string & ObjectString) {
std::vector<T> Result;
if(ObjectString.empty())
return Result;
try {
Poco::JSON::Parser P;
auto Object = P.parse(ObjectString).template extract<Poco::JSON::Array::Ptr>();
for (auto const i : *Object) {
auto InnerObject = i.template extract<Poco::JSON::Object::Ptr>();
T Obj;
Obj.from_json(InnerObject);
Result.push_back(Obj);
}
} catch (...) {
}
return Result;
}
template<class T> T to_object(const std::string & ObjectString) {
T Result;
if(ObjectString.empty())
return Result;
Poco::JSON::Parser P;
auto Object = P.parse(ObjectString).template extract<Poco::JSON::Object::Ptr>();
Result.from_json(Object);
return Result;
}
}
#endif // UCENTRALGW_RESTAPI_UTILS_H