added disabling of combo elements in GxsIdChooser for creating forums posts with unautorised GXS ids. Still needs a bit of work

This commit is contained in:
csoler 2016-03-24 00:05:54 -04:00
parent 40d23509a1
commit d33a1e8555
4 changed files with 145 additions and 45 deletions

View File

@ -60,6 +60,7 @@ GxsIdChooser::GxsIdChooser(QWidget *parent)
setSizeAdjustPolicy(QComboBox::AdjustToContents);
mFirstLoad = true;
mAllowedCount = 0 ;
mDefaultId.clear() ;
@ -99,6 +100,13 @@ void GxsIdChooser::showEvent(QShowEvent *event)
QComboBox::showEvent(event);
}
void GxsIdChooser::setIdConstraintSet(const std::set<RsGxsId>& s)
{
mConstraintIdsSet = s ;
updateDisplay(true);
update(); // Qt flush
}
void GxsIdChooser::loadIds(uint32_t chooserFlags, const RsGxsId &defId)
{
mFlags = chooserFlags;
@ -118,6 +126,7 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
if (!chooser) {
return;
}
// this prevents the objects that depend on what's in the combo-box to activate and
// perform any change.Only user-changes should cause this.
@ -167,13 +176,22 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
//std::cerr << " - disabling ID - entry = " << index << std::endl;
chooser->setEntryEnabled(index,false) ;
}
std::cerr << std::endl;
if(!chooser->isInConstraintSet(details.mId))
chooser->setEntryEnabled(index,false) ;
chooser->model()->sort(0);
chooser->blockSignals(false) ;
}
bool GxsIdChooser::isInConstraintSet(const RsGxsId& id) const
{
if(mConstraintIdsSet.empty()) // special case: empty set means no constraint
return true ;
return mConstraintIdsSet.find(id) != mConstraintIdsSet.end() ;
}
void GxsIdChooser::setEntryEnabled(int indx,bool enabled)
{
bool disable = !enabled ;
@ -238,8 +256,7 @@ void GxsIdChooser::loadPrivateIds()
}
for (std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) {
/* add to Chooser */
GxsIdDetails::process(*it, loadPrivateIdsCallback, this);
GxsIdDetails::process(*it, loadPrivateIdsCallback, this); /* add to Chooser */
}
if (mFirstLoad) {

View File

@ -58,7 +58,10 @@ public:
bool setChosenId(const RsGxsId &gxsId);
ChosenId_Ret getChosenId(RsGxsId &gxsId);
void setEntryEnabled(int index, bool enabled);
void setEntryEnabled(int index, bool enabled);
void setIdConstraintSet(const std::set<RsGxsId>& s) ;
bool isInConstraintSet(const RsGxsId& id) const ;
signals:
// emitted after first load of own ids
void idsLoaded();
@ -79,7 +82,9 @@ private:
uint32_t mFlags;
RsGxsId mDefaultId;
bool mFirstLoad;
uint32_t mAllowedCount ;
std::set<RsGxsId> mConstraintIdsSet ; // leave empty if all allowed
RsGxsUpdateBroadcastBase *mBase;
};

View File

@ -28,6 +28,7 @@
#include <QPushButton>
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
#include "gui/settings/rsharesettings.h"
#include "gui/RetroShareLink.h"
@ -43,6 +44,7 @@
#define CREATEGXSFORUMMSG_FORUMINFO 1
#define CREATEGXSFORUMMSG_PARENTMSG 2
#define CREATEGXSFORUMMSG_CIRCLENFO 3
//#define ENABLE_GENERATE
@ -57,6 +59,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
/* Setup Queue */
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
mCirclesQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
@ -100,6 +103,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
mParentMsgLoaded = false;
mForumMetaLoaded = false;
mForumCircleLoaded = false;
newMsg();
@ -112,6 +116,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
CreateGxsForumMsg::~CreateGxsForumMsg()
{
delete(mForumQueue);
delete(mCirclesQueue);
}
void CreateGxsForumMsg::newMsg()
@ -297,33 +302,33 @@ void CreateGxsForumMsg::createMsg()
if (ui.signBox->isChecked()) {
RsGxsId authorId;
switch (ui.idChooser->getChosenId(authorId)) {
case GxsIdChooser::KnowId:
case GxsIdChooser::UnKnowId:
case GxsIdChooser::KnowId:
case GxsIdChooser::UnKnowId:
msg.mMeta.mAuthorId = authorId;
std::cerr << "CreateGxsForumMsg::createMsg() AuthorId: " << authorId;
std::cerr << std::endl;
break;
case GxsIdChooser::None:
{
// This is ONLY for the case where no id exists yet
// If an id exists, the chooser would not return None
IdEditDialog dlg(this);
dlg.setupNewId(false);
dlg.exec();
// fetch new id, we will then see if the identity creation was successful
std::list<RsGxsId> own_ids;
if(!rsIdentity->getOwnIds(own_ids) || own_ids.size() != 1)
return;
// we have only a single id, so we can use the first one
authorId = own_ids.front();
break;
}
case GxsIdChooser::NoId:
default:
case GxsIdChooser::None:
{
// This is ONLY for the case where no id exists yet
// If an id exists, the chooser would not return None
IdEditDialog dlg(this);
dlg.setupNewId(false);
dlg.exec();
// fetch new id, we will then see if the identity creation was successful
std::list<RsGxsId> own_ids;
if(!rsIdentity->getOwnIds(own_ids) || own_ids.size() != 1)
return;
// we have only a single id, so we can use the first one
authorId = own_ids.front();
break;
}
case GxsIdChooser::NoId:
default:
std::cerr << "CreateGxsForumMsg::createMsg() ERROR GETTING AuthorId!";
std::cerr << std::endl;
QMessageBox::warning(this, tr("RetroShare"),tr("Congrats, you found a bug!")+" "+QString(__FILE__)+":"+QString(__LINE__), QMessageBox::Ok, QMessageBox::Ok);
QMessageBox::warning(this, tr("RetroShare"),tr("Congrats, you found a bug!")+" "+QString(__FILE__)+":"+QString(__LINE__), QMessageBox::Ok, QMessageBox::Ok);
return;
}//switch (ui.idChooser->getChosenId(authorId))
@ -431,29 +436,82 @@ void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
{
std::cerr << "CreateGxsForumMsg::loadForumInfo()";
std::cerr << std::endl;
std::cerr << "CreateGxsForumMsg::loadForumInfo()";
std::cerr << std::endl;
std::list<RsGroupMetaData> groupInfo;
rsGxsForums->getGroupSummary(token, groupInfo);
std::list<RsGroupMetaData> groupInfo;
rsGxsForums->getGroupSummary(token, groupInfo);
if (groupInfo.size() == 1)
{
RsGroupMetaData fi = groupInfo.front();
if (groupInfo.size() == 1)
{
RsGroupMetaData fi = groupInfo.front();
mForumMeta = fi;
mForumMetaLoaded = true;
mForumMeta = fi;
mForumMetaLoaded = true;
loadFormInformation();
}
else
{
std::cerr << "CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums";
std::cerr << std::endl;
if(!fi.mCircleId.isNull())
{
std::cerr << "Circle ID is not null: " << fi.mCircleId << ": loading circle info to add constraint to the GXS ID chooser." << std::endl;
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(RsGxsGroupId(fi.mCircleId));
uint32_t _token;
mCirclesQueue->requestGroupInfo(_token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, CREATEGXSFORUMMSG_CIRCLENFO);
}
loadFormInformation();
}
else
{
std::cerr << "CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums";
std::cerr << std::endl;
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
}
}
void CreateGxsForumMsg::loadForumCircleInfo(const uint32_t& token)
{
std::cerr << "Loading forum circle info" << std::endl;
std::vector<RsGxsCircleGroup> circle_grp_v ;
rsGxsCircles->getGroupData(token, circle_grp_v);
if (circle_grp_v.empty())
{
std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl;
return ;
}
if (circle_grp_v.size() != 1)
{
std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl;
return ;
}
RsGxsCircleGroup cg = circle_grp_v.front();
mForumCircleData = cg;
mForumCircleLoaded = true;
std::cerr << "Loaded content of circle " << cg.mMeta.mGroupId << std::endl;
for(std::set<RsGxsId>::const_iterator it(cg.mInvitedMembers.begin());it!=cg.mInvitedMembers.end();++it)
std::cerr << " added constraint to circle element " << *it << std::endl;
ui.idChooser->setIdConstraintSet(cg.mInvitedMembers) ;
ui.idChooser->setFlags(IDCHOOSER_NO_CREATE | ui.idChooser->flags()) ; // since there's a circle involved, no ID creation can be needed
RsGxsId tmpid ;
if(ui.idChooser->getChosenId(tmpid) == GxsIdChooser::None)
{
QMessageBox::information(NULL,tr("No compatible ID for this forum"),tr("Sorry, but this forum is restricted to a circle that contains none of your identities. As a consequence you cannot post in this forum, since your posts could not be propagated.")) ;
close() ;
}
}
void CreateGxsForumMsg::loadParentMsg(const uint32_t &token)
@ -501,10 +559,23 @@ void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest
loadParentMsg(req.mToken);
break;
default:
std::cerr << "CreateGxsForum::loadRequest() UNKNOWN UserType ";
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mForumQueue";
std::cerr << std::endl;
}
}
if(queue == mCirclesQueue)
{
switch(req.mUserType)
{
case CREATEGXSFORUMMSG_CIRCLENFO:
loadForumCircleInfo(req.mToken) ;
break ;
default:
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mCirclesQueue";
std::cerr << std::endl;
}
}
}
void CreateGxsForumMsg::insertPastedText(QString msg)

View File

@ -27,6 +27,7 @@
#include "util/TokenQueue.h"
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
class UIStateHelper;
@ -54,22 +55,28 @@ private slots:
protected:
void closeEvent (QCloseEvent * event);
private:
void loadFormInformation();
void loadForumInfo(const uint32_t &token);
void loadParentMsg(const uint32_t &token);
void loadForumCircleInfo(const uint32_t &token);
RsGxsGroupId mForumId;
RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId;
bool mParentMsgLoaded;
bool mForumMetaLoaded;
bool mForumCircleLoaded ;
RsGxsForumMsg mParentMsg;
RsGroupMetaData mForumMeta;
RsGxsCircleGroup mForumCircleData ;
TokenQueue *mForumQueue;
TokenQueue *mCirclesQueue;
UIStateHelper *mStateHelper;
/** Qt Designer generated object */