flag editing for users and roles
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 26 Apr 2010 18:03:45 +0000 (18:03 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 26 Apr 2010 18:03:45 +0000 (18:03 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@445 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/mwin/acltabs.cpp
src/mwin/acltabs.h
wob/basics.wolf
wob/user.wolf
www/inc/machine/muser.php
www/inc/wext/flag.php

index 7c59ac1..65965b6 100644 (file)
@@ -57,6 +57,9 @@ MUserTab::MUserTab(QString pk)
        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));
@@ -246,6 +249,44 @@ void MUserTab::setUserPassword()
        }
 }
 
+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)
@@ -491,7 +532,7 @@ MRoleTab::MRoleTab(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));
@@ -576,7 +617,40 @@ void MRoleTab::editDescription()
 }
 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()
 {
@@ -609,7 +683,7 @@ 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();
@@ -698,7 +772,7 @@ void MFlagTab::removeFlag()
        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
index dbad63d..18fdb51 100644 (file)
@@ -53,6 +53,8 @@ class MUserTab:public QWidget
                void editUserHosts();
                /**set a users password*/
                void setUserPassword();
+               /**change users flags*/
+               void editFlags();
                
        private:
                //the profile associated with this session
index 32f9e19..37c05b0 100644 (file)
@@ -49,7 +49,7 @@
                <Property name="description" type="string"/>
        </Class>
        <Transaction name="GetValidFlags" updating="no">
-               <Call lang="php" method="WOFlag::getAll($this);"/>
+               <Call lang="php" method="WOFlag::getAllTrn($this);"/>
                <Output>
                        <Var name="flags" type="List:Flag"/>
                </Output>
index c14abe6..4e56c33 100644 (file)
                <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());"/>
index 0c061fb..7f24d7d 100644 (file)
@@ -209,6 +209,56 @@ class MachineUser
                $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)
        {
index f6572f6..5170eaf 100644 (file)
 class WOFlag extends WOFlagAbstract
 {
        /**GetValidFlags transaction*/
-       public static function getAll($trans)
+       public static function getAllTrn($trans)
+       {
+               $trans->setflags(WOFlag::getAll());
+       }
+       /**returns all existing flags*/
+       public static function getAll()
        {
                global $db;
                $cfgs=WTconfig::selectFromDb("ckey LIKE 'Flag %'");
@@ -26,9 +31,9 @@ class WOFlag extends WOFlagAbstract
                                $ret[]=$f;
                        }
                }
-               $trans->setflags($ret);
+               return $ret;
        }
-       
+               
        /**SetFlag transaction*/
        public static function setFlagTrn($trans)
        {