More work on multiuser
parent
30d148931d
commit
92327bb6ec
|
|
@ -6,7 +6,7 @@
|
|||
UserInfo::UserInfo(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
qRegisterMetaType<UserInfo::PermissionScopes>("UserInfo.PermissionScopes");
|
||||
}
|
||||
|
||||
UserInfo::UserInfo(const QString &username, QObject *parent):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ public:
|
|||
PermissionScopeConfigureRules = 0x0030,
|
||||
PermissionScopeAdmin = 0xFFFF,
|
||||
};
|
||||
Q_ENUM(PermissionScope)
|
||||
Q_DECLARE_FLAGS(PermissionScopes, PermissionScope)
|
||||
Q_FLAG(PermissionScopes)
|
||||
|
||||
|
|
@ -43,4 +42,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(UserInfo::PermissionScope)
|
||||
Q_DECLARE_METATYPE(UserInfo::PermissionScopes)
|
||||
|
||||
#endif // USERINFO_H
|
||||
|
|
|
|||
|
|
@ -70,14 +70,15 @@ Users *UserManager::users() const
|
|||
return m_users;
|
||||
}
|
||||
|
||||
int UserManager::createUser(const QString &username, const QString &password, UserInfo::PermissionScopes scopes)
|
||||
int UserManager::createUser(const QString &username, const QString &password, int permissionScopes)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("username", username);
|
||||
params.insert("password", password);
|
||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.6")) {
|
||||
params.insert("scopes", UserInfo::scopesToList(scopes));
|
||||
params.insert("scopes", UserInfo::scopesToList((UserInfo::PermissionScopes)permissionScopes));
|
||||
}
|
||||
qCDebug(dcUserManager()) << "Creating user" << username << permissionScopes;
|
||||
return m_engine->jsonRpcClient()->sendCommand("Users.CreateUser", params, this, "createUserResponse");
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +106,15 @@ int UserManager::removeUser(const QString &username)
|
|||
return m_engine->jsonRpcClient()->sendCommand("Users.RemoveUser", params, this, "removeUserResponse");
|
||||
}
|
||||
|
||||
int UserManager::setUserScopes(const QString &username, int scopes)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("username", username);
|
||||
params.insert("scopes", UserInfo::scopesToList((UserInfo::PermissionScopes)scopes));
|
||||
qCDebug(dcUserManager()) << "Setting new permission scopes for user" << username << scopes << (int)scopes;
|
||||
return m_engine->jsonRpcClient()->sendCommand("Users.SetUserScopes", params, this, "setUserScopesResponse");
|
||||
}
|
||||
|
||||
void UserManager::notificationReceived(const QVariantMap &data)
|
||||
{
|
||||
qCDebug(dcUserManager()) << "Users notification" << data;
|
||||
|
|
@ -211,15 +221,6 @@ void UserManager::setUserScopesResponse(int commandId, const QVariantMap ¶ms
|
|||
emit setUserScopesReply(commandId, error);
|
||||
}
|
||||
|
||||
int UserManager::setUserScopes(const QString &username, UserInfo::PermissionScopes scopes)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("username", username);
|
||||
params.insert("scopes", UserInfo::scopesToList(scopes));
|
||||
qCDebug(dcUserManager()) << "Setting new permission scopes for user" << username << scopes << (int)scopes;
|
||||
return m_engine->jsonRpcClient()->sendCommand("Users.SetUserScopes", params, this, "setUserScopesResponse");
|
||||
}
|
||||
|
||||
Users::Users(QObject *parent): QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -45,11 +45,13 @@ public:
|
|||
TokenInfos* tokenInfos() const;
|
||||
Users *users() const;
|
||||
|
||||
Q_INVOKABLE int createUser(const QString &username, const QString &password, UserInfo::PermissionScopes scopes = UserInfo::PermissionScopeAdmin);
|
||||
// NOTE: Q_FLAG from another QObject (UserInfo::PermissionScopes) doesn't seem to work in certain Qt versions. Using int instead
|
||||
Q_INVOKABLE int createUser(const QString &username, const QString &password, int permissionScopes = UserInfo::PermissionScopeAdmin);
|
||||
Q_INVOKABLE int changePassword(const QString &newPassword);
|
||||
Q_INVOKABLE int removeToken(const QUuid &id);
|
||||
Q_INVOKABLE int removeUser(const QString &username);
|
||||
Q_INVOKABLE int setUserScopes(const QString &username, UserInfo::PermissionScopes scopes);
|
||||
// NOTE: Q_FLAG from another QObject (UserInfo::PermissionScopes) doesn't seem to work in certain Qt versions. Using int instead
|
||||
Q_INVOKABLE int setUserScopes(const QString &username, int permissionScopes);
|
||||
|
||||
signals:
|
||||
void engineChanged();
|
||||
|
|
|
|||
|
|
@ -61,13 +61,17 @@ Page {
|
|||
var message;
|
||||
switch (error) {
|
||||
case "UserErrorInvalidUserId":
|
||||
message = qsTr("The email you've entered isn't valid.")
|
||||
if (engine.jsonRpcClient.ensureServerVersion("7.0")) {
|
||||
message = qsTr("The email you've entered isn't valid.")
|
||||
} else {
|
||||
message = qsTr("The username you've entered isn't valid.")
|
||||
}
|
||||
break;
|
||||
case "UserErrorDuplicateUserId":
|
||||
message = qsTr("The email you've entered is already used.")
|
||||
message = qsTr("The username you've entered is already used.")
|
||||
break;
|
||||
case "UserErrorBadPassword":
|
||||
message = qsTr("The password you've chose is too weak.")
|
||||
message = qsTr("The password you've chosen is too weak.")
|
||||
break;
|
||||
case "UserErrorBackendError":
|
||||
message = qsTr("An error happened with the user storage. Please make sure your %1 system is installed correctly.").arg(Configuration.systemName)
|
||||
|
|
@ -102,7 +106,7 @@ Page {
|
|||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: engine.jsonRpcClient.initialSetupRequired ?
|
||||
qsTr("In order to use your %1 system, please enter your email address and set a password for it.").arg(Configuration.systemName)
|
||||
qsTr("In order to use your %1 system, please create an account.").arg(Configuration.systemName)
|
||||
: qsTr("In order to use your %1 system, please log in.").arg(Configuration.systemName)
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
|
@ -116,14 +120,16 @@ Page {
|
|||
columnSpacing: app.margins
|
||||
|
||||
Label {
|
||||
text: qsTr("Your e-mail address:")
|
||||
text: engine.jsonRpcClient.ensureServerVersion("7.0") ? qsTr("Username:") : qsTr("Your e-mail address:")
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumWidth: implicitWidth
|
||||
}
|
||||
TextField {
|
||||
id: usernameTextField
|
||||
Layout.fillWidth: true
|
||||
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
||||
inputMethodHints: engine.jsonRpcClient.ensureServerVersion("7.0")
|
||||
? Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
|
||||
: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
|
||||
// placeholderText: "john.smith@cooldomain.com"
|
||||
}
|
||||
Label {
|
||||
|
|
@ -146,7 +152,7 @@ Page {
|
|||
Layout.fillWidth: true
|
||||
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
|
||||
text: qsTr("OK")
|
||||
enabled: passwordTextField.isValid
|
||||
enabled: usernameTextField.displayText.length >= 3 && passwordTextField.isValid
|
||||
onClicked: {
|
||||
if (engine.jsonRpcClient.initialSetupRequired) {
|
||||
print("create user")
|
||||
|
|
|
|||
|
|
@ -240,8 +240,8 @@ SettingsPageBase {
|
|||
Layout.fillWidth: true
|
||||
text: model.text
|
||||
checked: (userDetailsPage.userInfo.scopes & model.scope) === model.scope
|
||||
enabled: model.scope === UserInfo.ScopeAdmin ||
|
||||
(userDetailsPage.userInfo.scopes & UserInfo.ScopeAdmin) == 0
|
||||
enabled: model.scope === UserInfo.PermissionScopeAdmin ||
|
||||
((userDetailsPage.userInfo.scopes & UserInfo.PermissionScopeAdmin) !== UserInfo.PermissionScopeAdmin)
|
||||
onClicked: {
|
||||
print("scopes:", userDetailsPage.userInfo.scopes)
|
||||
var scopes = userDetailsPage.userInfo.scopes
|
||||
|
|
@ -251,6 +251,8 @@ SettingsPageBase {
|
|||
scopes &= ~model.scope
|
||||
scopes |= model.resetOnUnset
|
||||
}
|
||||
print("username:", userDetailsPage.userInfo.username)
|
||||
print("new scopes:", scopes, UserInfo.PermissionScopeAdmin)
|
||||
userManager.setUserScopes(userDetailsPage.userInfo.username, scopes)
|
||||
}
|
||||
}
|
||||
|
|
@ -331,7 +333,7 @@ SettingsPageBase {
|
|||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Style.margins
|
||||
Layout.rightMargin: Style.margins
|
||||
enabled: usernameTextField.displayText.length > 3 && passwordTextField.isValid
|
||||
enabled: usernameTextField.displayText.length >= 3 && passwordTextField.isValid
|
||||
onClicked: {
|
||||
userManager.createUser(usernameTextField.displayText, passwordTextField.password, createUserPage.permissionScopes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue