void PermissionWidget::removePermissions(void)
{
	model->removePermissions(object);
	cancelOperation();
	perms_changed=true;
  updateCodePreview();
}
void PermissionWidget::addPermission(void)
{
	Permission *perm=nullptr;

	try
	{
		perm=new Permission(this->object);
		configurePermission(perm);
		model->addPermission(perm);
		listPermissions();
		cancelOperation();
		perms_changed=true;
    updateCodePreview();
	}
	catch(Exception &e)
	{
		if(perm)
		{
			model->removePermission(perm);
			delete(perm);
		}

		cancelOperation();
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
void PermissionWidget::removePermission(int)
{ 
	model->removePermission(permission);
	cancelOperation();
	permission=nullptr;
	permissions_tab->clearSelection();
	perms_changed=true;
  updateCodePreview();
}
void PermissionWidget::updatePermission(void)
{
	Permission *perm=nullptr,*perm_bkp=nullptr;
	int perm_idx=-1;

	try
	{
		perm=new Permission(this->object);

		/* Creates a backup permission. This will receive the current values of the
		editing permission, in case of errors these values can be restored */
		perm_bkp=new Permission(this->object);
		(*perm_bkp)=(*permission);

		configurePermission(perm);

		//Checking if the permission already exists on model
		perm_idx=model->getPermissionIndex(perm);

		if(perm_idx < 0 || (perm_idx >=0 && model->getObject(perm_idx,OBJ_PERMISSION)==permission))
		{
			(*permission)=(*perm);
			listPermissions();
			cancelOperation();
		}
		else
		{
			//Raises an error if the configured permission already exists
			throw Exception(Exception::getErrorMessage(ERR_ASG_DUPLIC_PERMISSION)
                      .arg(/*Utf8String::create(*/permission->getObject()->getName())
											.arg(permission->getObject()->getTypeName()),
											ERR_ASG_DUPLIC_PERMISSION,__PRETTY_FUNCTION__,__FILE__,__LINE__);
		}

		delete(perm_bkp);
		perms_changed=true;
    updateCodePreview();
	}
	catch(Exception &e)
	{
		(*permission)=(*perm_bkp);

		delete(perm);
		delete(perm_bkp);

		cancelOperation();
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
Beispiel #5
0
void ViewWidget::showReferenceData(Reference refer, bool selec_from, bool from_where, bool after_where, unsigned row)
{
	Table *tab=NULL;
	Column *col=NULL;
	QString str_aux;

	if(refer.getReferenceType()==Reference::REFER_COLUMN)
	{
		tab=refer.getTable();
		col=refer.getColumn();

		/* If the table is allocated but not the column indicates that the reference
		 is to all table columns this way shows a string in format: [SCHEMA].[TABLE].* */
		if(tab && !col)
			references_tab->setCellText(Utf8String::create(tab->getName(true) + QString(".*")),row,0);
		/* If the table and column are allocated indicates that the reference
		 is to a specific column this way shows a string in format: [SCHEMA].[TABLE].[COLUMN] */
		else
			references_tab->setCellText(Utf8String::create(tab->getName(true) + QString(".") + col->getName(true)),row,0);

		references_tab->setCellText(Utf8String::create(refer.getAlias()),row,1);

		if(col)
			references_tab->setCellText(Utf8String::create(refer.getColumnAlias()),row,2);
		else
			references_tab->setCellText(QString("-"),row,2);
	}
	else
	{
		references_tab->setCellText(Utf8String::create(refer.getExpression()),row,0);
		references_tab->setCellText(Utf8String::create(refer.getAlias()),row,1);
		references_tab->setCellText(QString("-"),row,2);
	}

	//Configures the string that denotes the SQL application for the reference
	str_aux+=(selec_from ? "1" : "0");
	str_aux+=(from_where ? "1" : "0");
	str_aux+=(after_where ? "1" : "0");
	references_tab->setCellText(str_aux,row,3);

	references_tab->setRowData(QVariant::fromValue<Reference>(refer), row);
	updateCodePreview();
}
void PermissionWidget::setAttributes(DatabaseModel *model, BaseObject *parent_obj, BaseObject *object)
{
	BaseObjectWidget::setAttributes(model,object,parent_obj);

	perms_changed=false;
	protected_obj_frm->setVisible(false);
	parent_form->apply_ok_btn->setEnabled(true);
	obj_id_lbl->setVisible(false);

	if(object)
	{
		unsigned priv;
		QCheckBox *chk=nullptr, *chk1=nullptr;

		connect(object_selection_wgt, SIGNAL(s_visibilityChanged(BaseObject*,bool)), this, SLOT(showSelectedRoleData(void)));
		connect(roles_tab, SIGNAL(s_rowAdded(int)), this, SLOT(selectRole(void)));
		connect(permissions_tab, SIGNAL(s_rowsRemoved(void)), this, SLOT(removePermissions(void)));

    name_edt->setText(/*Utf8String::create(*/object->getName(true));
    comment_edt->setText(/*Utf8String::create(*/object->getTypeName());

		for(priv=Permission::PRIV_SELECT; priv<=Permission::PRIV_USAGE; priv++)
		{
			//Gets the checkboxes that represents the privilege and the GRANT OPTION
			chk=dynamic_cast<QCheckBox *>(privileges_tbw->cellWidget(priv,0));
			chk1=dynamic_cast<QCheckBox *>(privileges_tbw->cellWidget(priv,1));

			chk->setChecked(false);
			chk1->setChecked(false);

			//Enabling the checkboxes using a validation of privilege type against the curret object type.
			privileges_tbw->setRowHidden(priv, !Permission::objectAcceptsPermission(object->getObjectType(), priv));
		}

		listPermissions();
		permissions_tab->blockSignals(true);
		permissions_tab->clearSelection();
		permissions_tab->blockSignals(false);
    updateCodePreview();
	}
}