"Filtering" data for certain employees

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
sblasic
Veteran Member
Posts: 53
Joined: 2021-02-22 15:55

"Filtering" data for certain employees

Post by sblasic » 2022-12-01 10:37

Hi guys!

I want to disable employees from being able to view the complete customer database.

Employees should only be able to view customer data from the region they cover.

In the client data table there is a column: region - this data would be used to show certain employees - depending on the geographical region they cover - data for certain regions only.

For example:
Bob can only view customer data from the region A. Susan can view customer data from regions B and C. Tom can view data from regions A (same as Bob) and the region F, and so on...

Since the number of employees is small (15), the assignment of the region that an employee can view can be coded manually.
If this can be made to be automatic according to the employee's data - even better.

Is it possible to do this and does anyone have a "plug-in" that could serve this purpose?

Thanks in advance for your help!

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: "Filtering" data for certain employees

Post by jsetzer » 2022-12-01 11:14

You may have a look here:
viewtopic.php?p=20456#p20457

That article is about filering by date, but you can modify the conditions according to your needs.

Just replace the $conditions-definition (an array holding 1..n SQL statements for your WHERE-part):

Code: Select all

  $conditions = [
    "datediff(now(), `TABLENAME`.`modified_on`) < 7"
  ];
I don't know your table names nor column names, but the middle part of the code (see other article) could look something like this:

Code: Select all

// ... see other article
if (!getLoggedAdmin()) {
	switch (getLoggedMemberID()) {
		case 'Bob':
			$conditions = ["`customers`.`region` IN ('A')"];
			break;
		case 'Susan':
			$conditions = ["`customers`.`region` IN ('B', 'C')"];
			break;
		case 'Tom':
			$conditions = ["`customers`.`region` IN ('A', 'F')"];
			break;
		default:
			$conditions = ["1=2"]; // this will never be true. Other users will not see customers
			break;
	}
}
// ...rest of the code
  
I think this is good readable. I know it could be coded differently for better code-maintenance but this should just give you a start.

Of course, instead of harcoding the regions, you can fetch that information from a different database table or from somewhere else.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply