diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 6d22613..45aa152 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -962,6 +962,9 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUserRequest(bool allaccess, if(ok){ out->insert("result","success"); } else{ out->insert("error","Could not delete group"); } + }else if(action=="groupmod" && allaccess){ + ok = sysadm::UserManager::modifyGroup(out, in_args.toObject() ); + }else if(action=="personacrypt_init"){ qDebug() << "got PC init request:" << in_args << allaccess << user; bool go = true; diff --git a/src/server/library/sysadm-users.cpp b/src/server/library/sysadm-users.cpp index d8e3b98..05bd8bd 100644 --- a/src/server/library/sysadm-users.cpp +++ b/src/server/library/sysadm-users.cpp @@ -277,7 +277,48 @@ bool UserManager::removeGroup(QString name){ bool UserManager::modifyGroup(QJsonObject* out, QJsonObject input){ bool ok = false; - + // REQUIRED: "name" + // OPTIONAL: "users", "add_users", "remove_users" (only one of these at a time) - all a string or array of strings + if(input.contains("name")){ + QStringList args; + QString group = input.value("name").toString(); + if(input.contains("users")){ + QStringList users; + ok = true; //got valid inputs + if(input.value("users").isString()){ users << input.value("users").toString(); } //only one user + else if(input.value("users").isArray()){ users = General::JsonArrayToStringList(input.value("users").toArray()); } + else{ ok = false; } //actually invalid - could not read users + if(ok){ + args << "groupmod" << "-n" << group << "-M" << users.join(","); + } + }else if(input.contains("add_users")){ + QStringList users; + ok = true; //got valid inputs + if(input.value("add_users").isString()){ users << input.value("add_users").toString(); } //only one user + else if(input.value("add_users").isArray()){ users =General:: JsonArrayToStringList(input.value("add_users").toArray()); } + else{ ok = false; } //actually invalid - could not read users + if(ok){ + args << "groupmod" << "-n" << group << "-m" << users.join(","); + } + }else if(input.contains("remove_users")){ + QStringList users; + ok = true; //got valid inputs + if(input.value("remove_users").isString()){ users << input.value("remove_users").toString(); } //only one user + else if(input.value("remove_users").isArray()){ users = General::JsonArrayToStringList(input.value("remove_users").toArray()); } + else{ ok = false; } //actually invalid - could not read users + if(ok){ + args << "groupmod" << "-n" << group << "-d" << users.join(","); + } + } + if(!args.isEmpty()){ + QString res = General::RunCommand(ok, "pw", args); + if(!ok){ out->insert("error",res); } + else{ out->insert("result","success"); } + }else{ + ok = false; //nothing to do + } + } + return ok; }