API CHANGE:

Add a new action to the sysadm/users class: "groupmod"
This action allows for modifying a given group on the system

REQUIRED: "name"="<name of group to modify>"
and any one of these options is also required:
"users":["array of users"] (will set the list of users for this group)
"add_users":["array of users"] (will add the listed users to the current users)
"remove_users":["array of users"] (will remove the listed users from the current users)

Example API Request (JSON)
{
"id":"sample",
"namespace":"sysadm",
"name":"users",
"args":{
  "action":"groupmod",
  "name":"operator",
  "users":["user1","user2"]
  }
}
This commit is contained in:
Ken Moore
2016-08-17 12:15:48 -04:00
parent 8700aab62a
commit 1fd947f5b4
2 changed files with 45 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;
}