Question

How can I determine if the connected user belongs to the "System Administrator" group?

Good afternoon colleagues,

How can I implement on a Client Schema this query to know if the connected user belongs to the System Administrators group?

This is the SQL, but I cannot how to implement this on the client schema code

SELECT * FROM SysAdminUnitInRole WHERE SysAdminUnitRoleId = (SELECT top 1 Id FROM SysAdminUnit) AND SysAdminUnitId = Terrasoft.SysValue.CURRENT_USER.value

Thanks in advance,

Julio Falcón

File attachments

Like

5 comments
var systemAdminId = '83A43EBC-F36B-1410-298D-001E8C82BCAD'; //select Id from SysAdminUnit where Name = 'System administrators'

var select = Ext.create("Terrasoft.EntitySchemaQuery", {
	rootSchemaName: "SysUserInRole",
	rowCount: 1
});

select.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "Id");
select.addColumn("SysUser");
select.addColumn("SysRole");

var filters = Ext.create("Terrasoft.FilterGroup");
filters.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value));
select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole", systemAdminId));
select.filters = filters;

select.execute(function(response) {
	if (response.success) {
		if (response.collection.getCount() > 0) {
			console.log('true');
		}else{
			console.log('false');
		}
	}
}, this);

Try this. The code will work only if the system administrators group is on top of the hierarchy. If you need a request with dependancies, you need to use SysAdminUnitInRole instead of the SysUserInRole. 

Thanks Mark,

I understand also the System Administrator group ALWAYS (independent of bpm'online version) had the Id '83A43EBC-F36B-1410-298D-001E8C82BCAD'?

Best regards

Good Morning Mark & colleagues,

I have problems with this routine, no works with any of the tables, only found one record, means always any user I try is treated as member of System Administrator and this is not real, in fact on SQL works fine

This is the SQL's I tried and works, in this case this is the Supervisor user and the queries returns one record,

But if I try with other user, not member of Admin group, the queries returns no record

select * from SysAdminUnitInRole
where SysAdminUnitRoleId = '83A43EBC-F36B-1410-298D-001E8C82BCAD' and SysAdminUnitId = '7f3b869f-34f3-4f20-ab4d-7480a5fdf647'

select* from SysUserInRole
where SysRoleId = '83A43EBC-F36B-1410-298D-001E8C82BCAD' and SysUserId = '7f3b869f-34f3-4f20-ab4d-7480a5fdf647'

This is the code I'm using and using any of the two tables SysAdminUnitInRole or SysUserInRole, the response.collection.getCount() returns ALWAYS one record, whats cold be bad?

esUsuarioAdmin: function( callback, scope ) {
	var systemAdminId = '83A43EBC-F36B-1410-298D-001E8C82BCAD'; //select Id from SysAdminUnit where Name = 'System administrators'

	var select = Ext.create("Terrasoft.EntitySchemaQuery", {
		//rootSchemaName: "SysAdminUnitInRole", //"SysUserInRole",
		rootSchemaName: "SysUserInRole",
		rowCount: 1
	});

	select.addMacrosColumn(Terrasoft.QueryMacrosType.PRIMARY_COLUMN, "Id");
	select.addColumn("SysUser");
	select.addColumn("SysRole");
	//select.addColumn("SysAdminUnitId");
	//select.addColumn("SysAdminUnitRoleId");

	var filters = Ext.create("Terrasoft.FilterGroup");
	filters.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
	select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value));
	select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole", systemAdminId));
	//select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysAdminUnitId", Terrasoft.SysValue.CURRENT_USER.value));//"SysUser", Terrasoft.SysValue.CURRENT_USER.value));
	//select.filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysAdminUnitRoleId", systemAdminId)); //"SysRole", systemAdminId));
	select.filters = filters;

	select.execute(function(response) {
		if (response.success) {
			if (response.collection.getCount() > 0) {
				usuarioEsAdministrador = true;
				/*var esAdmin = usuarioEsAdministrador ? "es" : "no es";
				this.showInformationDialog( "Usted esta conectado con el Usuario "+Terrasoft.SysValue.CURRENT_USER.displayValue +"\n"+
								esAdmin + " miembro del Grupo Administradores",
				function() {
					// Implementar aqui el desbloqueo de campos
					},
					{ style: Terrasoft.MessageBoxStyles.RED },	// Valores permitidos BLUE y RED
					{ defaultButton: 0 }	// Por defecto OK y CANCEL: 0 Primer botón
				);*/
			}
		}

		// Configura Enabled en campos
		debugger;
		callback.call(scope);
	}, this);
},

 

Yeah. I've missed in spelling.

need to use

var filters = Ext.create("Terrasoft.FilterGroup");

filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;

filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value));

filters.addItem(select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "SysRole", systemAdminId));

select.filters = filters;

Try to debug in browser. This way you'll be able to resolve such issues in the future by yourself.

Thanks Mark, Really!!!, I didn't see the mistake!, I debuge the code, but don't see any errors, and the strange thing is that always returns 1 record, but always was the Supervisor record.

Thanks, now is working!

Regards

Show all comments