From b0387b6ec5a170ee40cd89d09a32103fb723c011 Mon Sep 17 00:00:00 2001 From: kambizzandi Date: Thu, 28 Apr 2022 15:49:27 +0430 Subject: [PATCH] add enable email and mobile alert columns to users --- Interfaces/AAA/AAADefs.hpp | 3 + Interfaces/Test/testCommon.hpp | 23 +++---- .../Account/functionalTest/testAccount.hpp | 26 +++++--- ...20220425_105147_AAA_review_userwallets.sql | 2 +- Modules/Account/moduleSrc/Account.cpp | 66 +++++-------------- Modules/Account/moduleSrc/Account.h | 24 ++----- Modules/Account/moduleSrc/ORM/User.cpp | 60 +++++++++-------- Modules/Account/moduleSrc/ORM/User.h | 4 +- ...eting_create_table_department_and_unit.sql | 2 +- 9 files changed, 92 insertions(+), 118 deletions(-) diff --git a/Interfaces/AAA/AAADefs.hpp b/Interfaces/AAA/AAADefs.hpp index 84ca0db8..c035dccf 100644 --- a/Interfaces/AAA/AAADefs.hpp +++ b/Interfaces/AAA/AAADefs.hpp @@ -69,6 +69,7 @@ namespace tblUser { } constexpr quint64 MinNormalUserID = 100; + TARGOMAN_CREATE_CONSTEXPR(usrID); TARGOMAN_CREATE_CONSTEXPR(usrGender); TARGOMAN_CREATE_CONSTEXPR(usrName); @@ -80,6 +81,8 @@ namespace tblUser { TARGOMAN_CREATE_CONSTEXPR(usr_rolID); TARGOMAN_CREATE_CONSTEXPR(usrSpecialPrivs); TARGOMAN_CREATE_CONSTEXPR(usrLanguage); + TARGOMAN_CREATE_CONSTEXPR(usrEnableEmailAlerts); + TARGOMAN_CREATE_CONSTEXPR(usrEnableSMSAlerts); TARGOMAN_CREATE_CONSTEXPR(usrMaxSessions); TARGOMAN_CREATE_CONSTEXPR(usrActiveSessions); TARGOMAN_CREATE_CONSTEXPR(usrLastLogin); diff --git a/Interfaces/Test/testCommon.hpp b/Interfaces/Test/testCommon.hpp index 3bea3123..ce83a162 100644 --- a/Interfaces/Test/testCommon.hpp +++ b/Interfaces/Test/testCommon.hpp @@ -272,17 +272,18 @@ class clsBaseTest : public QObject // DAC.execQuery("", QString("DELETE FROM %1AAA.tblRoles WHERE rolName IN(?,?)").arg(this->DBPrefix), {UT_ServiceRoleName, UT_RoleName}); /* -DELETE FROM tblWalletsTransactions; -DELETE FROM tblWalletBalances; -DELETE FROM tblUserWallets; -DELETE FROM tblOnlinePayments; -DELETE FROM tblOfflinePayments; -DELETE FROM tblOfflinePaymentClaims; -DELETE FROM tblVoucher; -DELETE FROM tblApprovalRequest; -DELETE FROM tblActiveSessions; -DELETE FROM tblUser WHERE usrID > 100; -DELETE FROM tblRoles WHERE LOWER(rolName) LIKE '%test%' +DELETE FROM dev_AAA.tblWalletsTransactions; +DELETE FROM dev_AAA.tblWalletBalances; +DELETE FROM dev_AAA.tblUserWallets; +DELETE FROM dev_AAA.tblOnlinePayments; +DELETE FROM dev_AAA.tblOfflinePayments; +DELETE FROM dev_AAA.tblOfflinePaymentClaims; +DELETE FROM dev_AAA.tblVoucher; +DELETE FROM dev_AAA.tblApprovalRequest; +DELETE FROM dev_AAA.tblActiveSessions; +DELETE FROM dev_AAA.tblUser WHERE usrID > 100; +DELETE FROM dev_AAA.tblRoles WHERE LOWER(rolName) LIKE '%test%'; +DELETE FROM dev_Common.tblAlerts; */ } }; diff --git a/Modules/Account/functionalTest/testAccount.hpp b/Modules/Account/functionalTest/testAccount.hpp index 8a74f7e3..0252e7a4 100644 --- a/Modules/Account/functionalTest/testAccount.hpp +++ b/Modules/Account/functionalTest/testAccount.hpp @@ -247,6 +247,8 @@ private slots: { "mobile", "0999-888-1010" }, { "signupIfNotExists", true }, { "signupRole", UT_RoleName }, + { "signupEnableEmailAlerts", false }, + { "signupEnableSMSAlerts", false }, }) ; @@ -328,11 +330,13 @@ private slots: //df6d2338b2b8fce1ec2f6dda0a630eb0 # 987 QVERIFY((gUserID = callUserAPI(RESTClientHelper::PUT, "Account/signup", {}, { - {"emailOrMobile", UT_UserEmail}, - {"name", "unit"}, - {"family", "test"}, - {"pass", "df6d2338b2b8fce1ec2f6dda0a630eb0"}, - {"role", UT_RoleName} + { "emailOrMobile", UT_UserEmail }, + { "name", "unit" }, + { "family", "test" }, + { "pass", "df6d2338b2b8fce1ec2f6dda0a630eb0" }, + { "role", UT_RoleName }, + { "enableEmailAlerts", false }, + { "enableSMSAlerts", false }, }) .toMap() .value("usrID") @@ -342,11 +346,13 @@ private slots: //df6d2338b2b8fce1ec2f6dda0a630eb0 # 987 QVERIFY((gAdminUserID = callUserAPI(RESTClientHelper::PUT, "Account/signup", {}, { - {"emailOrMobile", UT_AdminUserEmail}, - {"name", "admin unit"}, - {"family", "test"}, - {"pass", "df6d2338b2b8fce1ec2f6dda0a630eb0"}, - {"role", UT_RoleName} + { "emailOrMobile", UT_AdminUserEmail }, + { "name", "admin unit" }, + { "family", "test" }, + { "pass", "df6d2338b2b8fce1ec2f6dda0a630eb0" }, + { "role", UT_RoleName }, + { "enableEmailAlerts", false }, + { "enableSMSAlerts", false }, }) .toMap() .value("usrID") diff --git a/Modules/Account/migrations/db/m20220425_105147_AAA_review_userwallets.sql b/Modules/Account/migrations/db/m20220425_105147_AAA_review_userwallets.sql index 551bb6e9..30ae25aa 100644 --- a/Modules/Account/migrations/db/m20220425_105147_AAA_review_userwallets.sql +++ b/Modules/Account/migrations/db/m20220425_105147_AAA_review_userwallets.sql @@ -1,5 +1,5 @@ /* Migration File: m20220425_105147_AAA_review_userwallets.sql */ - +/* CAUTION: don't forget to use {{dbprefix}} for schemas */ ALTER TABLE `tblWalletsTransactions` DROP INDEX `wltType`, diff --git a/Modules/Account/moduleSrc/Account.cpp b/Modules/Account/moduleSrc/Account.cpp index 805f9162..1186a5dc 100644 --- a/Modules/Account/moduleSrc/Account.cpp +++ b/Modules/Account/moduleSrc/Account.cpp @@ -284,6 +284,8 @@ QVariantMap Account::apiPUTsignup( QString _role, QString _name, QString _family, + bool _enableEmailAlerts, + bool _enableSMSAlerts, TAPI::JSON_t _specialPrivs, qint8 _maxSessions ) { @@ -313,6 +315,8 @@ QVariantMap Account::apiPUTsignup( { "iSpecialPrivs", _specialPrivs.isEmpty()? QVariant() : _specialPrivs }, { "iMaxSessions", _maxSessions }, { "iCreatorUserID", QVariant() }, + { "iEnableEmailAlerts", _enableEmailAlerts ? 1 : 0 }, + { "iEnableSMSAlerts", _enableSMSAlerts ? 1 : 0 }, }) .spDirectOutputs() .value("oUserID") @@ -323,51 +327,7 @@ QVariantMap Account::apiPUTsignup( { "usrID", UserID }, }; } -/* -QVariantMap Account::apiPUTsignupByMobileOnly( - TAPI::Mobile_t _mobile, -// quint32 _verifyCode, -// TAPI::MD5_t _pass, - QString _role, - QString _name, - QString _family, - TAPI::JSON_t _specialPrivs, - qint8 _maxSessions - ) { - Authorization::validateIPAddress(_APICALLBOOM.getIP()); - - if (QFV.mobile().isValid(_mobile) == false) - throw exHTTPBadRequest("Incorrect mobile."); - - _mobile = PhoneHelper::NormalizePhoneNumber(_mobile); - - QFV.asciiAlNum().maxLenght(50).validate(_role); - - if (_role.toLower() == "administrator" || _role.toLower() == "system" || _role.toLower() == "baseuser") - throw exHTTPForbidden("Selected role is not allowed to signup"); - - quint64 UserID = this->callSP("spSignup", { - { "iBy", "M" }, - { "iLogin", _mobile }, - { "iPass", "" }, - { "iRole", _role }, - { "iIP", _APICALLBOOM.getIP() }, - { "iName", _name.isEmpty()? QVariant() : _name }, - { "iFamily", _family.isEmpty()? QVariant() : _family }, - { "iSpecialPrivs", _specialPrivs.isEmpty()? QVariant() : _specialPrivs }, - { "iMaxSessions", _maxSessions }, - { "iCreatorUserID", QVariant() }, - }) - .spDirectOutputs() - .value("oUserID") - .toDouble(); - return { - { "type", "mobile" }, - { "usrID", UserID }, - }; -} -*/ TAPI::EncodedJWT_t Account::apiPOSTapproveEmail( APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, QString _email, @@ -493,7 +453,9 @@ bool Account::apiloginByMobileOnly( APICALLBOOM_TYPE_NO_JWT_IMPL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, bool _signupIfNotExists, - QString _signupRole + QString _signupRole, + bool _signupEnableEmailAlerts, + bool _signupEnableSMSAlerts ) { Authorization::validateIPAddress(_APICALLBOOM.getIP()); @@ -514,6 +476,8 @@ bool Account::apiloginByMobileOnly( { "iMobile", _mobile }, { "iSignupIfNotExists", _signupIfNotExists ? 1 : 0 }, { "iSignupRole", _signupRole }, + { "iSignupEnableEmailAlerts", _signupEnableEmailAlerts ? 1 : 0 }, + { "iSignupEnableSMSAlerts", _signupEnableSMSAlerts ? 1 : 0 }, }); return true; @@ -648,7 +612,7 @@ QString Account::apicreateForgotPasswordLink( this->callSP("spForgotPass_Request", { { "iLogin", _emailOrMobile }, - { "iVia", Type }, + { "iBy", Type }, }); return (Type == "E" ? "email" : "mobile"); @@ -702,7 +666,7 @@ bool Account::apichangePassByUUID( QString Type = PhoneHelper::ValidateAndNormalizeEmailOrPhoneNumber(_emailOrMobile); this->callSP("spPassword_ChangeByCode", { - { "iVia", Type }, + { "iBy", Type }, { "iLogin", _emailOrMobile }, { "iCode", _uuid }, { "iNewPass", _newPass }, @@ -1399,7 +1363,9 @@ QVariant Account::apiPOSTfixtureSetup( { "df6d2338b2b8fce1ec2f6dda0a630eb0" }, RoleName, "fixture test", - "user" + "user", + false, + false ); SignupUserResult.insert("email", UserEmail); @@ -1456,7 +1422,9 @@ QVariant Account::apiPOSTfixtureSetup( { "df6d2338b2b8fce1ec2f6dda0a630eb0" }, RoleName, "fixture test", - "admin" + "admin", + false, + false ); SignupAdminUserResult.insert("email", AdminUserEmail); diff --git a/Modules/Account/moduleSrc/Account.h b/Modules/Account/moduleSrc/Account.h index cc84a9eb..74f42038 100644 --- a/Modules/Account/moduleSrc/Account.h +++ b/Modules/Account/moduleSrc/Account.h @@ -96,30 +96,14 @@ private slots: QString _role = "BaseUser", QString _name = "", QString _family = "", + bool _enableEmailAlerts = true, + bool _enableSMSAlerts = true, TAPI::JSON_t _specialPrivs = {}, qint8 _maxSessions = -1 ), "Base method for signup with email or mobile. this method can be called just by predefined IPs" ) - /* - QVariantMap REST_PUT( - signupByMobileOnly, - ( - APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, - TAPI::Mobile_t _mobile, - QString _role = "BaseUser", - QString _name = "", - QString _family = "", - TAPI::JSON_t _specialPrivs = {}, - qint8 _maxSessions = -1 - ), - "Base method for signup with mobile only. this method can be called just by predefined IPs" - ) - */ -// "If verifyCode is empty, a new random code is generated and sent to the user via SMS." -// "After the user submits this code, signupByMobile must be called again with verifyCode." - TAPI::EncodedJWT_t REST_POST( approveEmail, ( @@ -172,7 +156,9 @@ private slots: APICALLBOOM_TYPE_NO_JWT_DECL &APICALLBOOM_PARAM, TAPI::Mobile_t _mobile, bool _signupIfNotExists = false, - QString _signupRole = "BaseUser" + QString _signupRole = "BaseUser", + bool _signupEnableEmailAlerts = true, + bool _signupEnableSMSAlerts = true // quint32 _verifyCode = 0/* = {}*/, // TAPI::MD5_t _pass = {}, // QString _salt = {}, diff --git a/Modules/Account/moduleSrc/ORM/User.cpp b/Modules/Account/moduleSrc/ORM/User.cpp index 1e0cabcf..25147978 100644 --- a/Modules/Account/moduleSrc/ORM/User.cpp +++ b/Modules/Account/moduleSrc/ORM/User.cpp @@ -41,31 +41,33 @@ User::User() : intfSQLBasedModule( AAASchema, tblUser::Name, - {///< ColName Type Validation Default UpBy Sort Filter Self Virt PK + {///< ColName Type Validation Default UpBy Sort Filter Self Virt PK //ORM_PRIMARYKEY_64 with self:true - { tblUser::usrID, S(quint64), QFV.integer().minValue(1), QAuto, UPNone, true, true, true, false, true }, - { tblUser::usrEmail, S(TAPI::Email_t), QFV.emailNotFake(), QNull, UPOwner }, - { tblUser::usrName, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner }, - { tblUser::usrFamily, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner }, - { tblUser::usrGender, S(TAPI::enuGender::Type), QFV, TAPI::enuGender::NotExpressed, UPOwner }, - { tblUser::usrMobile, S(TAPI::Mobile_t), QFV, QNull, UPOwner }, - { tblUser::usrApprovalState, S(TAPI::enuUserApproval::Type), QFV, TAPI::enuUserApproval::None }, + { tblUser::usrID, S(quint64), QFV.integer().minValue(1), QAuto, UPNone, true, true, true, false, true }, + { tblUser::usrEmail, S(TAPI::Email_t), QFV.emailNotFake(), QNull, UPOwner }, + { tblUser::usrName, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner }, + { tblUser::usrFamily, S(QString), QFV.unicodeAlNum().maxLenght(128), QNull, UPOwner }, + { tblUser::usrGender, S(TAPI::enuGender::Type), QFV, TAPI::enuGender::NotExpressed, UPOwner }, + { tblUser::usrMobile, S(TAPI::Mobile_t), QFV, QNull, UPOwner }, + { tblUser::usrApprovalState, S(TAPI::enuUserApproval::Type), QFV, TAPI::enuUserApproval::None }, //{ tblUser::usrPass, - { tblUser::usr_rolID, S(quint32), QFV.integer().minValue(1), QRequired, UPAdmin }, - { tblUser::usrSpecialPrivs, S(TAPI::PrivObject_t), QFV, QNull, UPAdmin, false, false }, - { tblUser::usrLanguage, S(QString), QFV.languageCode(), "fa", UPOwner }, - { tblUser::usrMaxSessions, S(qint32), QFV.integer().betweenValues(-1, 100), -1, UPAdmin }, - { tblUser::usrActiveSessions, S(qint32), QFV.integer().betweenValues(-1, 1000), QInvalid, UPNone }, - { tblUser::usrLastLogin, S(TAPI::DateTime_t), QFV, QInvalid, UPNone }, - { tblUser::usrStatus, ORM_STATUS_FIELD(TAPI::enuUserStatus, TAPI::enuUserStatus::MustValidate) }, + { tblUser::usr_rolID, S(quint32), QFV.integer().minValue(1), QRequired, UPAdmin }, + { tblUser::usrSpecialPrivs, S(TAPI::PrivObject_t), QFV, QNull, UPAdmin, false, false }, + { tblUser::usrLanguage, S(QString), QFV.languageCode(), "fa", UPOwner }, + { tblUser::usrEnableEmailAlerts, S(bool), QFV, true, UPOwner }, + { tblUser::usrEnableSMSAlerts, S(bool), QFV, true, UPOwner }, + { tblUser::usrMaxSessions, S(qint32), QFV.integer().betweenValues(-1, 100), -1, UPAdmin }, + { tblUser::usrActiveSessions, S(qint32), QFV.integer().betweenValues(-1, 1000), QInvalid, UPNone }, + { tblUser::usrLastLogin, S(TAPI::DateTime_t), QFV, QInvalid, UPNone }, + { tblUser::usrStatus, ORM_STATUS_FIELD(TAPI::enuUserStatus, TAPI::enuUserStatus::MustValidate) }, { ORM_INVALIDATED_AT_FIELD }, - { tblUser::usrCreationDateTime, ORM_CREATED_ON }, - { tblUser::usrCreatedBy_usrID, ORM_CREATED_BY_NULLABLE }, - { tblUser::usrUpdatedBy_usrID, ORM_UPDATED_BY }, + { tblUser::usrCreationDateTime, ORM_CREATED_ON }, + { tblUser::usrCreatedBy_usrID, ORM_CREATED_BY_NULLABLE }, + { tblUser::usrUpdatedBy_usrID, ORM_UPDATED_BY }, }, - {///< Col Reference Table ForeignCol Rename LeftJoin - { tblUser::usr_rolID, R(AAASchema, tblRoles::Name), tblRoles::rolID }, - { tblUser::Relation::ExtraInfo, { tblUser::usrID, R(AAASchema, tblUserExtraInfo::Name), tblUserExtraInfo::uei_usrID, "", true } }, + {///< Col Reference Table ForeignCol Rename LeftJoin + { tblUser::usr_rolID, R(AAASchema, tblRoles::Name), tblRoles::rolID }, + { tblUser::Relation::ExtraInfo, { tblUser::usrID, R(AAASchema, tblUserExtraInfo::Name), tblUserExtraInfo::uei_usrID, "", true } }, ORM_RELATION_OF_CREATOR(tblUser::usrCreatedBy_usrID), ORM_RELATION_OF_UPDATER(tblUser::usrUpdatedBy_usrID), }, @@ -110,6 +112,8 @@ QVariant User::apiGET(GET_METHOD_ARGS_IMPL_APICALL) { tblUser::usr_rolID, // tblUser::usrSpecialPrivs, tblUser::usrLanguage, + tblUser::usrEnableEmailAlerts, + tblUser::usrEnableSMSAlerts, // tblUser::usrMaxSessions, tblUser::usrActiveSessions, tblUser::usrLastLogin, @@ -325,16 +329,20 @@ bool User::apiUPDATEpersonalInfo( QString _name, QString _family, TAPI::ISO639_2_t _language, - NULLABLE_TYPE(TAPI::enuGender::Type) _gender + NULLABLE_TYPE(TAPI::enuGender::Type) _gender, + NULLABLE_TYPE(bool) _enableEmailAlerts, + NULLABLE_TYPE(bool) _enableSMSAlerts ) { quint64 CurrentUserID = _APICALLBOOM.getUserID(); QVariantMap ToUpdate; - if (_name.isNull() == false) ToUpdate.insert(tblUser::usrName, _name); - if (_family.isNull() == false) ToUpdate.insert(tblUser::usrFamily, _family); - if (_language.isNull() == false) ToUpdate.insert(tblUser::usrLanguage, _language); - if (NULLABLE_HAS_VALUE(_gender)) ToUpdate.insert(tblUser::usrGender, *_gender); + if (_name.isNull() == false) ToUpdate.insert(tblUser::usrName, _name); + if (_family.isNull() == false) ToUpdate.insert(tblUser::usrFamily, _family); + if (_language.isNull() == false) ToUpdate.insert(tblUser::usrLanguage, _language); + if (NULLABLE_HAS_VALUE(_gender)) ToUpdate.insert(tblUser::usrGender, *_gender); + if (NULLABLE_HAS_VALUE(_enableEmailAlerts)) ToUpdate.insert(tblUser::usrEnableEmailAlerts, *_enableEmailAlerts ? 1 : 0); + if (NULLABLE_HAS_VALUE(_enableSMSAlerts)) ToUpdate.insert(tblUser::usrEnableSMSAlerts, *_enableSMSAlerts ? 1 : 0); if (ToUpdate.size()) this->Update(*this, diff --git a/Modules/Account/moduleSrc/ORM/User.h b/Modules/Account/moduleSrc/ORM/User.h index d88d674f..d2ab8310 100644 --- a/Modules/Account/moduleSrc/ORM/User.h +++ b/Modules/Account/moduleSrc/ORM/User.h @@ -103,7 +103,9 @@ private slots: QString _name = {}, QString _family = {}, TAPI::ISO639_2_t _language = {}, - NULLABLE_TYPE(TAPI::enuGender::Type) _gender = {} + NULLABLE_TYPE(TAPI::enuGender::Type) _gender = {}, + NULLABLE_TYPE(bool) _enableEmailAlerts = {}, + NULLABLE_TYPE(bool) _enableSMSAlerts = {} ), "Update User personal info" ) diff --git a/Modules/Ticketing/migrations/db/m20220401_200609_Ticketing_create_table_department_and_unit.sql b/Modules/Ticketing/migrations/db/m20220401_200609_Ticketing_create_table_department_and_unit.sql index 6503ada6..2a49940c 100644 --- a/Modules/Ticketing/migrations/db/m20220401_200609_Ticketing_create_table_department_and_unit.sql +++ b/Modules/Ticketing/migrations/db/m20220401_200609_Ticketing_create_table_department_and_unit.sql @@ -19,7 +19,7 @@ CREATE TABLE `tblUnits` ( `untCreatedBy_usrID` BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (`untID`) USING BTREE, INDEX `FK_tblUnits_tblDepartments` (`unt_depID`) USING BTREE, - CONSTRAINT `FK_tblUnits_tblDepartments` FOREIGN KEY (`unt_depID`) REFERENCES `dev_Ticketing`.`tblDepartments` (`depID`) ON UPDATE NO ACTION ON DELETE NO ACTION + CONSTRAINT `FK_tblUnits_tblDepartments` FOREIGN KEY (`unt_depID`) REFERENCES `{{dbprefix}}Ticketing`.`tblDepartments` (`depID`) ON UPDATE NO ACTION ON DELETE NO ACTION ) COLLATE='utf8mb4_general_ci' ENGINE=InnoDB