Setting User privileges set Editor Datatables
Setting User privileges set Editor Datatables

Hi ,
Now that my data-tables are almost ready. I have already created a user login portal, where users can login based on Username and Password given
Now, I am trying to set privileges for each user to read/write/ only specific data from database. This is very important for my project as there is some important financial information which only few people can view.
For example:
1) User-1: **can read data from all tables in database.
**2) User-2: Can only read few columns from each table in database.
3) User-3: can read all data and able to edit some data.
Please provide some ideas how can I proceeded with this as this is extremely important for my project.
Your suggestions will be highly appreciated
This question has accepted answers - jump to:
Answers
Does your Users table incorporate access levels?
This thread should help, it's asking the same thing.
Cheers,
Colin
@tangerine can you please elaborate?
Just to give an idea , for the basic login system, I am reading username and password from data inputted in database and compare it against the user input (POST method).
Then I am saving the username in SESSION Variable and use it across other tables to give basic access rights , which allows a user to edit or only read from table
for example sessionId reads the information from current session and if it matches some value which in my case is abc , it will allow to edit the information otherwise no.
I want to extend this to hide columns and check if this is the right way of doing it? Thanks
@colin
Thank you.
I followed the same example. However, I am not able to understand how to logic behind hiding the data (columns) from server-side and then sending the data to client. based on user roles.
If I am not wrong, if we do it from client side (hide the columns) the data will be still accessible using the developer tool->XHR response.
Thank you
Yep, the thread I pointed you towards was for the editing aspect - i.e. when to permit the Edit and New buttons to appear.
To hide specific columns, you're correct, if it's sent, it's visible in the payload. There, you would need to do something like first interrogate the server to see what columns the user would have access to, then when initialising the table, base it upon that information. It would need to be a two step process.
Colin
@collin Thank you very much.
I was able to hide the column data from server-side using:
It works perfect. However, when retrieving the data from client side, it shows this message
Requested unknown parameter 'admins.first_name' for row 0, column 2
From the client side I tired to fit it in if statement using :
This doesn't seem to be working right.
Can you please give me an idea how can i ignore this error based on dynamically hiding some columns based on
$_SESSION['privileges']
variableThat's because you've probably initialised the table for more columns than what you received. My idea above was to query the server before any initialisation, get the columns that can be viewed, and then initialise the table with that information. Hope that makes sense,
Colin
@colin
it does make sense. But irrespective of the query results, for the returned data, wouldn't I need to initialise all the columns anyway? And in that case when the result for any column is set to false , it will still show the same error?
For user 'abc' it needs to display all column but for user 'def' it needs to hide few. In both cases data table needs to be intilized with all possible columns.
or is there a way to create columns dynamically?
I would really appreciate, if you can give me a very simple example?
Thank you
@colin please ignore my previous comment, I am sure it doesn't make much sense, sorry
**I managed to make it work using below code
**
before initialling the table i used (xhr) as this would be called after every ajax load :
Excellent, glad it's all working.
Colin
That would do it - nice one. The downside to this method is that if anyone takes a look at the code on the client-side, they will see that you are just hiding columns that they shouldn't be able to see. While they don't have any data in them, so the damage is minimal, it still does indicate to them that there is more than they can see.
Typically when doing this kind of thing, I have PHP generate both the HTML and the Javascript for the user's access rights. For example if the general user has access to 4 columns, both the HTML and JS will reflect that. If an admin has access to 6 columns, likewise the HTML and JS will be built for that case.
I don't think we have an example of that process anywhere, but it would be a good one for a blog post sometime.
Allan
@colin and @allan
Thank you. Yes, that is true but as you mentioned, damage is minimal. I would take your suggestion and make php script according to user priviliges.
Also, with the above method, it is important to note , from server side return the hidden column to null
otherwise , it will display the same error
Requested unknown parameter 'admins.first_name' for row 0, column 2
I hope this is the right way to do it.
Yes, that's a perfectly valid way of doing it.
Allan