From f1e17235ecb0d8b64ca726a611130ba32960f91b Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 26 Apr 2010 17:16:14 +0000 Subject: [PATCH] implement flag management some minor corrections in regards to flags git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@444 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/aclwin.cpp | 2 + src/dialogs/aclwin.h | 2 + src/dialogs/flagedit.h | 2 +- src/mwin/acltabs.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++++ src/mwin/acltabs.h | 19 ++++++++ wob/basics.wolf | 12 +++++ www/inc/db/dbupgrade.php | 2 +- www/inc/wext/flag.php | 30 +++++++++++++ 8 files changed, 175 insertions(+), 2 deletions(-) diff --git a/src/dialogs/aclwin.cpp b/src/dialogs/aclwin.cpp index 0dcb429..38d83ea 100644 --- a/src/dialogs/aclwin.cpp +++ b/src/dialogs/aclwin.cpp @@ -64,6 +64,8 @@ MAclWindow::MAclWindow(QWidget*par) tab->addTab(roletab=new MRoleTab(profilekey),tr("Roles")); //host tab tab->addTab(hosttab=new MHostTab(profilekey),tr("Hosts")); + //flags tab + tab->addTab(flagtab=new MFlagTab(profilekey),tr("Flags")); mb->addMenu(MApplication::helpMenu()); diff --git a/src/dialogs/aclwin.h b/src/dialogs/aclwin.h index 68c4636..0428ff7 100644 --- a/src/dialogs/aclwin.h +++ b/src/dialogs/aclwin.h @@ -20,6 +20,7 @@ class MUserTab; class MHostTab; class MRoleTab; +class MFlagTab; class MAclWindow:public QMainWindow { @@ -41,6 +42,7 @@ class MAclWindow:public QMainWindow MUserTab*usertab; MHostTab*hosttab; MRoleTab*roletab; + MFlagTab*flagtab; //refresh timers QTimer rtimer; }; diff --git a/src/dialogs/flagedit.h b/src/dialogs/flagedit.h index 5f113db..e61a18d 100644 --- a/src/dialogs/flagedit.h +++ b/src/dialogs/flagedit.h @@ -21,7 +21,7 @@ class QStandardItemModel; class QTableView; -/**enables the user to edit flags as defined by MagicSmoke*/ +/**enables the user to edit flags attached to an entity as defined by MagicSmoke*/ class MFlagEditor:public QDialog { Q_OBJECT diff --git a/src/mwin/acltabs.cpp b/src/mwin/acltabs.cpp index f82e37e..7c59ac1 100644 --- a/src/mwin/acltabs.cpp +++ b/src/mwin/acltabs.cpp @@ -620,3 +620,111 @@ void MRoleTab::editRights() if(srr.hasError()) QMessageBox::warning(this,tr("Warning"),tr("Error while setting rights: %1").arg(srr.errorString())); } + +/*****************************************************************************/ + +MFlagTab::MFlagTab(QString pk) +{ + profilekey=pk; + + QHBoxLayout*hl;QVBoxLayout*vl; + QPushButton*p; + //host tab + setLayout(hl=new QHBoxLayout); + hl->addWidget(table=new QTableView,10); + table->setModel(model=new QStandardItemModel(this)); + table->setSelectionMode(QAbstractItemView::SingleSelection); + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + hl->addSpacing(5); + hl->addLayout(vl=new QVBoxLayout,0); + vl->addWidget(p=new QPushButton(tr("New Flag...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(addFlag())); + p->setEnabled(req->hasRight(req->RSetFlag)); + vl->addWidget(p=new QPushButton(tr("Delete Flag...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(removeFlag())); + p->setEnabled(req->hasRight(req->RDeleteFlag)); + vl->addSpacing(20); + vl->addWidget(p=new QPushButton(tr("Change Description...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(changeFlag())); + p->setEnabled(req->hasRight(req->RSetFlag)); + vl->addStretch(10); + + if(req->hasRight(req->RGetValidFlags)){ + updateFlags(); + }else{ + setEnabled(false); + } +} + +void MFlagTab::updateFlags() +{ + MTGetValidFlags gvf=MTGetValidFlags::query(); + if(gvf.hasError())return; + model->clear(); + model->insertColumns(0,2); + model->setHorizontalHeaderLabels(QStringList()< flg=gvf.getflags(); + model->insertRows(0,flg.size()); + for(int i=0;isetData(model->index(i,0),flg[i].flag().value()); + model->setData(model->index(i,1),flg[i].description().value()); + } + table->resizeColumnsToContents(); +} + +void MFlagTab::addFlag() +{ + QString flg; + do{ + bool ok; + flg=QInputDialog::getText(this,tr("Create New Flag"),tr("Please enter a name for the flag, it must contain only letters and digits."),QLineEdit::Normal,flg,&ok); + if(!ok)return; + if(QRegExp("[a-zA-Z0-9]+").exactMatch(flg))break; + }while(1); + MOFlag f; + f.setflag(flg); + MTSetFlag cf=MTSetFlag::query(f); + if(cf.hasError()) + QMessageBox::warning(this,tr("Warning"),tr("Error while creating flag: %1").arg(cf.errorString())); + else + updateFlags(); +} + +void MFlagTab::removeFlag() +{ + //get flag + QModelIndex idx=table->currentIndex(); + if(!idx.isValid())return; + QString flg=model->data(model->index(idx.row(),0)).toString(); + //sanity check + if(flg=="")return; + if(flg[0]=='_');//TODO + //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 + MTDeleteFlag df=MTDeleteFlag::query(flg); + if(df.hasError()) + QMessageBox::warning(this,tr("Warning"),tr("Error while attempting to delete flag: %1").arg(df.errorString())); + else + updateFlags(); +} + +void MFlagTab::changeFlag() +{ + //get flag + QModelIndex idx=table->currentIndex(); + if(!idx.isValid())return; + QString flg=model->data(model->index(idx.row(),0)).toString(); + QString d=model->data(model->index(idx.row(),1)).toString(); + //get new text + bool ok; + d=QInputDialog::getText(this,tr("Change Flag"),tr("Please enter a new description for flag '%1':").arg(flg),QLineEdit::Normal,d,&ok); + if(!ok)return; + //do it + MOFlag f;f.setflag(flg);f.setdescription(d); + MTSetFlag sf=MTSetFlag::query(f); + if(sf.hasError()) + QMessageBox::warning(this,tr("Warning"),tr("Error while attempting to alter flag: %1").arg(sf.errorString())); + else + updateFlags(); +} diff --git a/src/mwin/acltabs.h b/src/mwin/acltabs.h index 31aba05..dbad63d 100644 --- a/src/mwin/acltabs.h +++ b/src/mwin/acltabs.h @@ -113,4 +113,23 @@ class MRoleTab:public QWidget QStandardItemModel*rolemodel; }; +/**flag admin tab*/ +class MFlagTab:public QWidget +{ + Q_OBJECT + public: + MFlagTab(QString); + public slots: + void updateFlags(); + void addFlag(); + void removeFlag(); + void changeFlag(); + private: + //the profile associated with this session + QString profilekey; + //widgets + QTableView*table; + QStandardItemModel*model; +}; + #endif diff --git a/wob/basics.wolf b/wob/basics.wolf index 69f041e..32f9e19 100644 --- a/wob/basics.wolf +++ b/wob/basics.wolf @@ -54,4 +54,16 @@ + + + + + + + + + + + + diff --git a/www/inc/db/dbupgrade.php b/www/inc/db/dbupgrade.php index 3152958..7398091 100644 --- a/www/inc/db/dbupgrade.php +++ b/www/inc/db/dbupgrade.php @@ -277,7 +277,7 @@ class DBUpgrade $ships=$olddb->select("shipping","*"); foreach($ships as $ship){ $flag=""; - if(!$ship["canuseweb"])$flag="-web"; + if(!$ship["canuseweb"])$flag="-_web"; if(!$ship["canallusers"])$flag.=" +anyshipping"; unset($ship["canuseweb"]);unset($ship["canallusers"]); $ship["flags"]=trim($flag); diff --git a/www/inc/wext/flag.php b/www/inc/wext/flag.php index e5095b6..f6572f6 100644 --- a/www/inc/wext/flag.php +++ b/www/inc/wext/flag.php @@ -11,6 +11,7 @@ class WOFlag extends WOFlagAbstract { + /**GetValidFlags transaction*/ public static function getAll($trans) { global $db; @@ -27,6 +28,35 @@ class WOFlag extends WOFlagAbstract } $trans->setflags($ret); } + + /**SetFlag transaction*/ + public static function setFlagTrn($trans) + { + global $db; + $f=$trans->getflag(); + //check flag name + if(!ereg("^[a-zA-Z0-9]+$",$f->getflag())){ + $trans->abortWithError("Invalid flag name."); + return; + } + //set it + $db->setConfig("Flag ".$f->getflag(),$f->getdescription()); + } + /**DeleteFlag transaction*/ + public static function deleteFlag($trans) + { + global $db; + $f=$trans->getflag(); + //check flag name + if(!ereg("^[a-zA-Z0-9]+$",$f)){ + $trans->abortWithError("Invalid flag name or attempt to delete special flag."); + return; + } + //set it + $cfg=WTconfig::getFromDb("Flag ".$f); + if($cfg instanceof WTconfig) + $cfg->deleteFromDb(); + } }; ?> -- 1.7.2.5