vl->addWidget(p=new QPushButton(tr("Roles...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(editUserRoles()));
p->setEnabled(req->hasRight(req->RGetUserRoles));
+ vl->addWidget(p=new QPushButton(tr("Flags...")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(editFlags()));
+ p->setEnabled(req->hasRight(req->RSetRoleFlags));
vl->addWidget(p=new QPushButton(tr("Set Password...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(setUserPassword()));
p->setEnabled(req->hasRight(req->RChangePassword));
}
}
+void MUserTab::editFlags()
+{
+ //get selection
+ QModelIndex sel=usertable->currentIndex();
+ if(!sel.isValid())return;
+ //get uname & descr
+ QString name=usermodel->data(usermodel->index(sel.row(),0)).toString();
+ //...
+ MTGetUser gr=req->queryGetUser(name);
+ if(gr.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve user data: %1").arg(gr.errorString()));
+ return;
+ }
+ MTGetValidFlags gvf=req->queryGetValidFlags();
+ if(gvf.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve flag list: %1").arg(gvf.errorString()));
+ return;
+ }
+ QList<MOFlag> aflags=gvf.getflags();
+ MCheckList acl;
+ QStringList uflag=gr.getuser().value().flags().value().split(" ",QString::SkipEmptyParts);
+ for(int i=0;i<aflags.size();i++){
+ QString nm=aflags[i].flag();
+ QString lb=nm+": "+aflags[i].description();
+ acl<<MCheckItem(nm,uflag.contains(nm),lb);
+ }
+ MCheckDialog cd(this,acl,tr("Edit flags of user %1").arg(name));
+ if(cd.exec()!=QDialog::Accepted)return;
+ uflag.clear();
+ acl=cd.getCheckList();
+ for(int i=0;i<acl.size();i++)
+ if(acl[i].isSet())
+ uflag<<acl[i].key();
+ MTSetUserFlags sur=MTSetUserFlags::query(name,uflag);
+ if(sur.hasError())
+ QMessageBox::warning(this,tr("Warning"),tr("Error while setting users flags: %1").arg(sur.errorString()));
+}
+
/*****************************************************************************/
MHostTab::MHostTab(QString pk)
p->setEnabled(req->hasRight(req->RSetRoleDescription));
vl->addWidget(p=new QPushButton(tr("Edit Flags...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(editFlags()));
- p->setEnabled(false);
+ p->setEnabled(req->hasRight(req->RSetRoleFlags));
vl->addWidget(p=new QPushButton(tr("Edit Rights...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(editRights()));
p->setEnabled(req->hasRight(req->RSetRoleRights));
}
void MRoleTab::editFlags()
{
- //TODO: implement flags
+ //get selection
+ QModelIndex sel=roletable->currentIndex();
+ if(!sel.isValid())return;
+ //get uname & descr
+ QString name=rolemodel->data(rolemodel->index(sel.row(),0)).toString();
+ //...
+ MTGetRole gr=req->queryGetRole(name);
+ if(gr.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve role: %1").arg(gr.errorString()));
+ return;
+ }
+ MTGetValidFlags gvf=req->queryGetValidFlags();
+ if(gvf.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot retrieve flag list: %1").arg(gvf.errorString()));
+ return;
+ }
+ MCheckList acl;
+ QStringList rflags=gr.getrole().value().flags().value().split(" ",QString::SkipEmptyParts);
+ QList<MOFlag> aflags=gvf.getflags();
+ for(int i=0;i<aflags.size();i++){
+ QString nm=aflags[i].flag();
+ QString lb=nm+": "+aflags[i].description();
+ acl<<MCheckItem(nm,rflags.contains(nm),lb);
+ }
+ MCheckDialog cd(this,acl,tr("Edit flags of role %1").arg(name));
+ if(cd.exec()!=QDialog::Accepted)return;
+ acl=cd.getCheckList();
+ rflags.clear();
+ for(int i=0;i<acl.size();i++)
+ if(acl[i].isSet())
+ rflags<<acl[i].key();
+ MTSetRoleFlags srr=MTSetRoleFlags::query(name,rflags);
+ if(srr.hasError())
+ QMessageBox::warning(this,tr("Warning"),tr("Error while setting flags: %1").arg(srr.errorString()));
}
void MRoleTab::editRights()
{
}else lb=nm;
acl<<MCheckItem(nm,rrights.contains(nm),lb);
}
- MCheckDialog cd(this,acl,"Edit Rights of role "+name);
+ MCheckDialog cd(this,acl,tr("Edit rights of role %1").arg(name));
if(cd.exec()!=QDialog::Accepted)return;
acl=cd.getCheckList();
rrights.clear();
QString flg=model->data(model->index(idx.row(),0)).toString();
//sanity check
if(flg=="")return;
- if(flg[0]=='_');//TODO
+ if(flg[0]=='_')return;
//ask nicely (a'ka "annoy user")
if(QMessageBox::question(this,tr("Really Delete?"),tr("Really delete the flag '%1'? Doing so may make some entities visible or invisible unexpectedly.").arg(flg),QMessageBox::Yes|QMessageBox::No)!=QMessageBox::Yes)return;
//now attempt deletion
<Doc>This class represents the main information about users: login name plus description. Passwords are never carried towards the client, more detailed info is contained in other classes.</Doc>
<Property name="name" type="astring"/>
<Property name="description" type="string"/>
+ <Property name="flags" type="astring"/>
<Mapping table="user">
<Map column="uname" property="name"/>
<Map column="description"/>
+ <Map column="flags"/>
</Mapping>
</Class>
<Var name="users" type="List:User"/>
</Output>
</Transaction>
+ <Transaction name="GetUser" updating="no">
+ <Input>
+ <Var name="uname" type="astring"/>
+ </Input>
+ <Call lang="php" method="$this->setuser(WOUser::fromTableuser(WTuser::getFromDB($this->getuname())));"/>
+ <Output>
+ <Var name="user" type="User"/>
+ </Output>
+ </Transaction>
<Transaction name="CreateUser">
<Input>
</Input>
<Call lang="php" method="MachineUser::setUserHosts($this);"/>
</Transaction>
+ <Transaction name="SetUserFlags">
+ <Input>
+ <Var name="username" type="astring"/>
+ <Var name="flags" type="List:astring"/>
+ </Input>
+ <Call lang="php" method="MachineUser::setUserFlags($this);"/>
+ </Transaction>
<Class name="Role" abstract="yes">
<Property name="name" type="string"/>
</Input>
<Call lang="php" method="MachineUser::deleteRole($this);"/>
</Transaction>
+ <Transaction name="SetRoleFlags">
+ <Input>
+ <Var name="role" type="astring"/>
+ <Var name="flags" type="List:astring"/>
+ </Input>
+ <Call lang="php" method="MachineUser::setRoleFlags($this);"/>
+ </Transaction>
<Transaction name="GetAllRightNames" updating="no">
<Call lang="php" method="$this->setrights(WobTransaction::transactionNames()+WobTransaction::privilegeNames());"/>
$trans->sethostnames($ret);
}
+ /**sets the flags of a role*/
+ static public function setRoleFlags($trans)
+ {
+ //sanity check
+ $rname=$trans->getrole();
+ $role=WTrole::getFromDB($rname);
+ if($role===false){
+ $trans->abortWithError(tr("Role does not exist."));
+ return;
+ }
+ //verify flags
+ $aflags=array();
+ foreach(WOFlag::getAll() as $f)$aflags[]=$f->getflag();
+ $flags=array_unique(array_values($trans->getflags()));
+ foreach($flags as $f){
+ if(!in_array($f,$aflags)){
+ $trans->abortWithError(tr("Trying to assign non-existent flag."));
+ return;
+ }
+ }
+ //set
+ $role->flags=implode(" ",$flags);
+ $role->update();
+ }
+
+ /**sets the flags of a user*/
+ static public function setUserFlags($trans)
+ {
+ //sanity check
+ $uname=$trans->getusername();
+ $usr=WTuser::getFromDB($uname);
+ if($usr===false){
+ $trans->abortWithError(tr("User does not exist."));
+ return;
+ }
+ //verify flags
+ $aflags=array();
+ foreach(WOFlag::getAll() as $f)$aflags[]=$f->getflag();
+ $flags=array_unique(array_values($trans->getflags()));
+ foreach($flags as $f){
+ if(!in_array($f,$aflags)){
+ $trans->abortWithError(tr("Trying to assign non-existent flag."));
+ return;
+ }
+ }
+ //set
+ $usr->flags=implode(" ",$flags);
+ $usr->update();
+ }
+
/**sets the description of a role*/
static public function setRoleDescription($trans)
{