Framework update + added modified to userrecord.

This commit is contained in:
stephb9959
2022-01-10 22:39:46 -08:00
parent 76175d8bbb
commit 30431ab954
9 changed files with 64 additions and 64 deletions

View File

@@ -348,6 +348,9 @@ components:
securityPolicyChange:
type: integer
format: int64
modified:
type: integer
format: int64
userTypeProprietaryInfo:
$ref: '#/components/schemas/UserLoginLoginExtensions'

View File

@@ -309,6 +309,7 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
field_to_json( Obj,"rrm",rrm);
field_to_json( Obj,"managementPolicy",managementPolicy);
field_to_json( Obj,"state",state);
}
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -326,6 +327,7 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"deviceConfiguration",deviceConfiguration);
field_from_json( Obj,"rrm",rrm);
field_from_json( Obj,"managementPolicy",managementPolicy);
field_from_json( Obj,"state",state);
return true;
} catch(...) {

View File

@@ -284,6 +284,7 @@ namespace OpenWifi::ProvObjects {
std::string deviceConfiguration;
std::string rrm;
Types::UUID_t managementPolicy;
std::string state;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -254,6 +254,7 @@ namespace OpenWifi::SecurityObjects {
field_to_json(Obj,"lastPasswords",lastPasswords);
field_to_json(Obj,"oauthType",oauthType);
field_to_json(Obj,"oauthUserInfo",oauthUserInfo);
field_to_json(Obj,"modified",modified);
};
bool UserInfo::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -288,6 +289,7 @@ namespace OpenWifi::SecurityObjects {
field_from_json(Obj,"lastPasswords",lastPasswords);
field_from_json(Obj,"oauthType",oauthType);
field_from_json(Obj,"oauthUserInfo",oauthUserInfo);
field_from_json(Obj,"modified",modified);
return true;
} catch (const Poco::Exception &E) {

View File

@@ -136,6 +136,7 @@ namespace OpenWifi {
OpenWifi::Types::StringVec lastPasswords;
std::string oauthType;
std::string oauthUserInfo;
uint64_t modified;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);

View File

@@ -59,5 +59,6 @@ namespace OpenWifi::RESTAPI::Errors {
static const std::string MissingAuthenticationInformation{"Missing authentication information."};
static const std::string InsufficientAccessRights{"Insufficient access rights to complete the operation."};
static const std::string ExpiredToken{"Token has expired, user must login."};
static const std::string SubscriberMustExist{"Subscriber must exist."};
}

View File

@@ -171,6 +171,9 @@ namespace ORM {
template <typename RecordTuple, typename RecordType> class DB {
public:
typedef const char * field_name_t;
DB( OpenWifi::DBType dbtype,
const char *TableName,
const FieldVec & Fields,
@@ -258,27 +261,27 @@ namespace ORM {
[[nodiscard]] const std::string & SelectList() const { return SelectList_; };
[[nodiscard]] const std::string & UpdateFields() const { return UpdateFields_; };
inline std::string OP(const char *F, SqlComparison O , bool V) {
inline std::string OP(field_name_t F, SqlComparison O , bool V) {
assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + (V ? "true" : "false") + ")" ;
}
inline std::string OP(const char *F, SqlComparison O , int V) {
inline std::string OP(field_name_t F, SqlComparison O , int V) {
assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ;
}
inline std::string OP(const char *F, SqlComparison O , uint64_t V) {
inline std::string OP(field_name_t F, SqlComparison O , uint64_t V) {
assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + std::to_string(V) + ")" ;
}
std::string OP(const char *F, SqlComparison O , const std::string & V) {
std::string OP(field_name_t F, SqlComparison O , const std::string & V) {
assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ;
}
std::string OP(const char *F, SqlComparison O , const char * V) {
std::string OP(field_name_t F, SqlComparison O , const char * V) {
assert( FieldNames_.find(F) != FieldNames_.end() );
return std::string{"("} + F + SQLCOMPS[O] + "'" + Escape(V) + "')" ;
}
@@ -299,9 +302,12 @@ namespace ORM {
return std::string{"("} + P1 + BOPS[BOP] + OP(true, P2, More...);
}
inline bool Create() {
std::string S;
bool Upgrade() {
uint32_t To;
return Upgrade(0, To);
}
inline bool Create() {
switch(Type_) {
case OpenWifi::DBType::mysql: {
try {
@@ -309,12 +315,10 @@ namespace ORM {
std::string Statement = IndexCreation_.empty() ? "create table if not exists " + TableName_ +" ( " + CreateFields_ + " )" :
"create table if not exists " + TableName_ +" ( " + CreateFields_ + " ), " + IndexCreation_[0] + " )";
Session << Statement , Poco::Data::Keywords::now;
return true;
} catch (const Poco::Exception &E) {
Logger_.error("Failure to create MySQL DB resources.");
Logger_.log(E);
}
return false;
}
break;
@@ -326,7 +330,6 @@ namespace ORM {
for(const auto &i:IndexCreation_) {
Session << i , Poco::Data::Keywords::now;
}
return true;
} catch (const Poco::Exception &E) {
Logger_.error("Failure to create SQLITE DB resources.");
Logger_.log(E);
@@ -342,7 +345,6 @@ namespace ORM {
for(const auto &i:IndexCreation_) {
Session << i , Poco::Data::Keywords::now;
}
return true;
} catch (const Poco::Exception &E) {
Logger_.error("Failure to create POSTGRESQL DB resources.");
Logger_.log(E);
@@ -350,7 +352,7 @@ namespace ORM {
}
break;
}
return false;
return Upgrade();
}
[[nodiscard]] std::string ConvertParams(const std::string & S) const {
@@ -400,7 +402,7 @@ namespace ORM {
return false;
}
template<typename T> bool GetRecord( const char * FieldName, const T & Value, RecordType & R) {
template<typename T> bool GetRecord(field_name_t FieldName, const T & Value, RecordType & R) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -438,7 +440,7 @@ namespace ORM {
typedef std::vector<std::string> StringVec;
template < typename T,
typename T0, typename T1> bool GR(const char *FieldName, T & R,T0 &V0, T1 &V1) {
typename T0, typename T1> bool GR(field_name_t FieldName, T & R,T0 &V0, T1 &V1) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -495,7 +497,7 @@ namespace ORM {
return false;
}
template <typename T> bool UpdateRecord( const char *FieldName, const T & Value, const RecordType & R) {
template <typename T> bool UpdateRecord(field_name_t FieldName, const T & Value, const RecordType & R) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -522,7 +524,7 @@ namespace ORM {
return false;
}
template <typename T> bool ReplaceRecord( const char *FieldName, const T & Value, RecordType & R) {
template <typename T> bool ReplaceRecord(field_name_t FieldName, const T & Value, RecordType & R) {
try {
if(Exists(FieldName, Value)) {
return UpdateRecord(FieldName,Value,R);
@@ -534,7 +536,7 @@ namespace ORM {
return false;
}
template <typename T> bool GetNameAndDescription(const char *FieldName, const T & Value, std::string & Name, std::string & Description ) {
template <typename T> bool GetNameAndDescription(field_name_t FieldName, const T & Value, std::string & Name, std::string & Description ) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
Poco::Data::Session Session = Pool_.get();
@@ -561,7 +563,7 @@ namespace ORM {
return false;
}
template <typename T> bool DeleteRecord( const char *FieldName, const T & Value) {
template <typename T> bool DeleteRecord(field_name_t FieldName, const T & Value) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -599,7 +601,7 @@ namespace ORM {
return false;
}
bool Exists(const char *FieldName, const std::string & Value) {
bool Exists(field_name_t FieldName, const std::string & Value) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -616,7 +618,7 @@ namespace ORM {
bool Iterate( std::function<bool(const RecordType &R)> F) {
try {
uint64_t Offset=1;
uint64_t Offset=0;
uint64_t Batch=50;
bool Done=false;
while(!Done) {
@@ -691,7 +693,7 @@ namespace ORM {
return 0;
}
template <typename X> bool ManipulateVectorMember( X T, const char *FieldName, std::string & ParentUUID, std::string & ChildUUID, bool Add) {
template <typename X> bool ManipulateVectorMember( X T, field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID, bool Add) {
try {
assert( FieldNames_.find(FieldName) != FieldNames_.end() );
@@ -751,89 +753,89 @@ namespace ORM {
return true;
}
inline bool AddChild( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddChild(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteChild( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteChild(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::children, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddLocation( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddLocation(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteLocation( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteLocation(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddContact( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddContact(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteContact( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteContact(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddVenue( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddVenue(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteVenue( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteVenue(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::venues, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddDevice( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddDevice(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteDevice( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteDevice(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::devices, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddEntity( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddEntity(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteEntity( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DeleteEntity(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddUser( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool AddUser(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, true);
}
inline bool DelUser( const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
inline bool DelUser(field_name_t FieldName, const std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::users, FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddInUse(const char *FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
inline bool AddInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
std::string FakeUUID{ Prefix + ":" + ChildUUID};
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, true);
}
inline bool DeleteInUse(const char *FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
inline bool DeleteInUse(field_name_t FieldName, std::string & ParentUUID, const std::string & Prefix, const std::string & ChildUUID) {
std::string FakeUUID{ Prefix + ":" + ChildUUID};
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, FakeUUID, false);
}
inline bool DeleteContact(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
inline bool DeleteContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddContact(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
inline bool AddContact(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::contacts,FieldName, ParentUUID, ChildUUID, true);
}
inline bool DeleteLocation(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
inline bool DeleteLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, false);
}
inline bool AddLocation(const char *FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
inline bool AddLocation(field_name_t FieldName, std::string & ParentUUID, const std::string & ChildUUID) {
return ManipulateVectorMember(&RecordType::locations,FieldName, ParentUUID, ChildUUID, true);
}
inline bool GetInUse(const char *FieldName, std::string & UUID, std::vector<std::string> & UUIDs ) {
inline bool GetInUse(field_name_t FieldName, const std::string & UUID, std::vector<std::string> & UUIDs ) {
RecordType R;
if(GetRecord(FieldName,UUID,R)) {
UUIDs = R.inUse;

View File

@@ -72,7 +72,8 @@ namespace OpenWifi {
ORM::Field{"currentPassword", ORM::FieldType::FT_TEXT},
ORM::Field{"lastPasswords", ORM::FieldType::FT_TEXT},
ORM::Field{"oauthType", ORM::FieldType::FT_TEXT},
ORM::Field{"oauthUserInfo", ORM::FieldType::FT_TEXT}
ORM::Field{"oauthUserInfo", ORM::FieldType::FT_TEXT},
ORM::Field{"modified", ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec MakeIndices(const std::string & shortname) {
@@ -94,27 +95,11 @@ namespace OpenWifi {
}
bool BaseUserDB::Upgrade(uint32_t from, uint32_t &to) {
if(from == CurrentVersion) {
to = CurrentVersion ;
return true;
}
auto Session = Pool_.get();
Poco::Data::Statement S(Session);
if(from==0) {
std::vector<std::string> Statements{
"alter table " + TableName_ + " rename column owner to entity;",
"alter table " + TableName_ + " rename column oauth to deviceList;",
"alter table " + TableName_ + " rename column oauthuserinfo to loginRecords;",
"alter table " + TableName_ + " add column modified BIGINT;"
};
RunScript(Statements);
}
to = CurrentVersion;
return true;
}
@@ -328,6 +313,7 @@ template<> void ORM::DB<OpenWifi::UserInfoRecordTuple,
U.lastPasswords = OpenWifi::RESTAPI_utils::to_object_array(T.get<27>());
U.oauthType = T.get<28>();
U.oauthUserInfo = T.get<29>();
U.modified = T.get<30>();
}
template<> void ORM::DB< OpenWifi::UserInfoRecordTuple,
@@ -363,4 +349,5 @@ template<> void ORM::DB< OpenWifi::UserInfoRecordTuple,
T.set<27>(OpenWifi::RESTAPI_utils::to_string(U.lastPasswords));
T.set<28>(U.oauthType);
T.set<29>(U.oauthUserInfo);
T.set<30>(U.modified);
}

View File

@@ -39,7 +39,8 @@ namespace OpenWifi {
std::string, // currentPassword;
std::string, // lastPasswords;
std::string, // oauthType;
std::string // oauthUserInfo;
std::string, // oauthUserInfo;
uint64_t // modified
> UserInfoRecordTuple;
typedef std::vector <UserInfoRecordTuple> UserInfoRecordTupleList;