Exemple #1
0
bool FLVar::set(const QString &n, const QVariant &v)
{
  QString idSesion(aqApp->timeUser().toString(Qt::ISODate));
  QString where(QString::fromLatin1("idvar='") + n +
                QString::fromLatin1("' AND idsesion='") + idSesion +
                QString::fromLatin1("'"));

  FLSqlQuery q;
  q.setTablesList("flvar");
  q.setSelect("id");
  q.setFrom("flvar");
  q.setWhere(where);
  q.setForwardOnly(true);

  if (!q.exec())
    return false;
  if (q.next())
    return FLUtil::sqlUpdate("flvar", "valor", v.toString(),
                             QString::fromLatin1("id='") + q.value(0).toString() +
                             QString::fromLatin1("'"));

  QString values(n + QString::fromLatin1(",") + idSesion +
                 QString::fromLatin1(",") + v.toString());
  return FLUtil::sqlInsert("flvar", "idvar,idsesion,valor", values);
}
void FLAccessControlLists::makeRuleGroup(FLSqlQuery *q, QDomDocument *d, const QString &idgroup)
{
  if (idgroup.isEmpty() || !q || !d)
    return;

  FLSqlQuery qU;

  qU.setTablesList("flusers");
  qU.setSelect("iduser");
  qU.setFrom("flusers");
  qU.setWhere(QString::fromLatin1("idgroup='") + idgroup + QString::fromLatin1("'"));
  qU.setForwardOnly(true);

  if (qU.exec())
    while (qU.next())
      makeRuleUser(q, d, qU.value(0).toString());
}
void FLAccessControlLists::makeRuleUser(FLSqlQuery *q, QDomDocument *d, const QString &iduser)
{
  if (iduser.isEmpty() || !q || !d)
    return;

  FLAccessControl *ac = FLAccessControlFactory::create(q->value(1).toString());

  if (ac) {
    ac->setName(q->value(2).toString());
    ac->setUser(iduser);
    ac->setPerm(q->value(6).toString());

    FLSqlQuery qAcos;

    qAcos.setTablesList("flacos");
    qAcos.setSelect("nombre,permiso");
    qAcos.setFrom("flacos");
    qAcos.setWhere(QString::fromLatin1("idac='") + q->value(0).toString() +
                   QString::fromLatin1("'"));
    qAcos.setForwardOnly(true);

    QStringList acos;

    if (qAcos.exec()) {
      while (qAcos.next()) {
        acos << qAcos.value(0).toString();
        acos << qAcos.value(1).toString();
      }
    }

    ac->setAcos(acos);
    ac->get(d);

    delete ac;
  }
}
void FLAccessControlLists::installACL(const QString &idacl)
{
  QDomDocument doc("ACL");

  QDomElement root = doc.createElement("ACL");
  doc.appendChild(root);

  QDomElement name = doc.createElement("name");
  root.appendChild(name);
  QDomText n = doc.createTextNode(idacl);
  name.appendChild(n);

  FLSqlQuery q;

  q.setTablesList("flacs");
  q.setSelect("idac,tipo,nombre,iduser,idgroup,degrupo,permiso");
  q.setFrom("flacs");
  q.setWhere(QString::fromLatin1("idacl='") + idacl + QString::fromLatin1("'"));
  q.setOrderBy("prioridad DESC,tipo");
  q.setForwardOnly(true);

  if (q.exec()) {
    uint step = 0;
    QProgressDialog progress(QApplication::tr("Instalando control de acceso..."), 0,
                             q.size(), 0, 0, true);
    progress.setCaption(QApplication::tr("Instalando ACL"));
    progress.setMinimumDuration(0);
    progress.setProgress(++step);
    while (q.next()) {
      makeRule(&q, &doc);
      progress.setProgress(++step);
    }
    FLSqlConnections::database()->managerModules()->setContent("acl.xml", "sys",
                                                               doc.toString());
  }
}