Warning, file /network/ruqola/src/rocketchatrestapi-qt/createupdateuserinfo.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "createupdateuserinfo.h" 0008 0009 #include <QJsonArray> 0010 #include <QJsonObject> 0011 using namespace RocketChatRestApi; 0012 0013 bool CreateUpdateUserInfo::isValid() const 0014 { 0015 bool valid = !mEmail.isEmpty() && !mName.isEmpty(); 0016 if (mTypeInfo == Create) { 0017 if (mSetRandomPassword) { 0018 return valid; 0019 } 0020 return valid && !mPassword.isEmpty(); 0021 } 0022 return valid && !mUserId.isEmpty(); // Need password ? 0023 } 0024 0025 QDebug operator<<(QDebug d, const RocketChatRestApi::CreateUpdateUserInfo &t) 0026 { 0027 d << "roles " << t.mRoles; 0028 d << "mUserId " << t.mUserId; 0029 d << "mEmail " << t.mEmail; 0030 d << "mName " << t.mName; 0031 d << "mUserName " << t.mUserName; 0032 d << "mBio " << t.mBio; 0033 // d << "mPassword " << t.mPassword; 0034 d << "mStatusText " << t.mStatusText; 0035 d << "mNickName " << t.mNickName; 0036 d << "mJoinDefaultChannels " << t.mJoinDefaultChannels; 0037 d << "mRequirePasswordChange " << t.mRequirePasswordChange; 0038 d << "mAssignRandomPassword " << t.mSetRandomPassword; 0039 d << "mSendWelcomeEmail " << t.mSendWelcomeEmail; 0040 return d; 0041 } 0042 0043 QJsonDocument CreateUpdateUserInfo::json() const 0044 { 0045 // TODO add update support 0046 QJsonObject userInfoObj; 0047 if (!mEmail.isEmpty()) { 0048 userInfoObj[QLatin1String("email")] = mEmail; 0049 } 0050 if (!mName.isEmpty()) { 0051 userInfoObj[QLatin1String("name")] = mName; 0052 } 0053 if (!mUserName.isEmpty()) { 0054 userInfoObj[QLatin1String("username")] = mUserName; 0055 } 0056 if (!mStatusText.isEmpty()) { 0057 userInfoObj[QLatin1String("statusText")] = mStatusText; 0058 } 0059 if (!mBio.isEmpty()) { 0060 userInfoObj[QLatin1String("bio")] = mBio; 0061 } 0062 if (!mNickName.isEmpty()) { 0063 userInfoObj[QLatin1String("nickname")] = mNickName; 0064 } 0065 if (!mRoles.isEmpty()) { 0066 userInfoObj[QLatin1String("roles")] = QJsonArray::fromStringList(mRoles); 0067 } 0068 0069 userInfoObj[QLatin1String("password")] = mSetRandomPassword ? QString() : mPassword; 0070 0071 userInfoObj[QLatin1String("requirePasswordChange")] = mRequirePasswordChange; 0072 userInfoObj[QLatin1String("sendWelcomeEmail")] = mSendWelcomeEmail; 0073 userInfoObj[QLatin1String("setRandomPassword")] = mSetRandomPassword; 0074 userInfoObj[QLatin1String("verified")] = mVerified; 0075 userInfoObj[QLatin1String("joinDefaultChannels")] = mJoinDefaultChannels; 0076 if (mTypeInfo == Update) { 0077 QJsonObject dataObj; 0078 dataObj[QLatin1String("data")] = userInfoObj; 0079 dataObj[QLatin1String("userId")] = mUserId; 0080 const QJsonDocument postData = QJsonDocument(dataObj); 0081 return postData; 0082 } 0083 const QJsonDocument postData = QJsonDocument(userInfoObj); 0084 return postData; 0085 }