Field Permissions (hide / lock fields by usergroup)

Got something cool to share with AppGini users? Feel free to post it here!
User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-02 12:52

That's fine Buddy, this is probably because my code for color rows runs from hooks/footer-extras.php

Not a big deal.

Thanks Olaf.

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-03 09:12

Hi Olaf, hope you're well. Can you have a quick look to the video below and advise? Basically if I lock lookup field, then its fine, but if there are auto-fill fields on that lookup, then after locking the field it will no longer display anything in that field, but auto-fill fields still there. is your script suppose to do that? Thank You.

Arni.

https://youtu.be/3HeWYmaWOps

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-03 09:43

Hi aarlauskas,

strange, and not supposed to happen.
In my screenshot, you can see the page for the superadmin (nothing locked/hidden) and for a user where I locked the "Platz" field. In the bottom of the image, you see the autofilled values, that are depending on Platz.
I did try to change the Platz as superadmin, the depending fields were updated and all changes (Platz + depending) are reflected in the testUser (right side) correctly. I also tested with only Platz limited (removed another field from being hidden and unlocked ContainerCode) - no problems for the testUser.

So, something else seems to be wrong. We will figure it out. Maybe the page was actually not readily loaded when the locking occured. The AppGini Helper-function I am using here ( dv.ready(makeFieldReadonly); ) is, if I remember correct still in beta. I will inquire about this.

Can you reproduce this on a different page?
ec202003-02.png
ec202003-02.png (51.38 KiB) Viewed 18103 times
Olaf

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-03 13:36

no panic Mate, I'll try to upload on remote server instead of local in a min, If it works for you, then I'm sure it will work for me too. Just wanted to confirm, thats it. Thanks

Arni

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-03 14:04

Hi Arni,

the AG-Helper-function I use to make fields readonly (.readonly) is, as Jan said, currently unsupported. As it works (for me), let's see if it works for you, once online.

Olaf

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-03 14:43

Hi Olaf, all ok Mate, works fine online! Probably a glitch in Xampp.. Do apologise :oops:

Thanks. Arni.

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

Re: Field Permissions (hide / lock fields by usergroup)

Post by jsetzer » 2020-03-03 15:01

onoehring wrote:
2020-03-03 14:04
[...] the AG-Helper-function I use to make fields readonly (.readonly) is, as Jan said, currently unsupported. [...] Olaf
My name was used here and so I would like to clarify that the .readonly() function, which Olaf has based his solution on, is not officially contained in AppGini Helper Javascript Library. It is undocumented and not supported by us, I'm sorry.

This is for good reason, because there are hundreds of possible combinations and variations of datatypes, states and options. We cannot cover 100%. The function should work with most of the datatypes but definately not for all datatypes and variations.

Our customers can use our readonly()-function it at their own risk, but there will not be any support from us. So please don't blame me or the library for any given promises.

Kind regards,
Jan
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

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-03 15:37

Hi Jan, I can assure you, your name and Helper are crystal clear! :D but have to agree, Olaf's solution to Lock/Hide fields with simple GUI is 'Must Have' tool for some (definitely for me). Just love it.. definitely worth more than some of the plugins in my opinion.

Thanks.

Arni.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-03 16:57

Hi Jan,

if I stepped on your feet, I want to apologize. I meant no harm, but wanted to clear things here a little. I am sure we will find the reason why currently aarlauskas has a problem with the field permissions.

Olaf

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Field Permissions (hide / lock fields by usergroup)

Post by aarlauskas » 2020-03-03 17:37

Hi Olaf, as per my earlier post, all ok Buddy, no more questions. Many Thanks. Arni.
Hi Olaf, all ok Mate, works fine online! Probably a glitch in Xampp.. Do apologise :oops:

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-12 16:17

Hi,

just a quick update so you will know, that the waiting is worth it ;-)
I started working on hiding fields in table view.
Right now one ...
  • will see (to be user defined) a --X-- in the hidden column.
  • can not use filter to search for content in a hidden column (e.g. no results will be listed where the search term is in a hidden column)
  • can not use quick search to search for content in a hidden column (e.g. no results will be listed where the search term is in a hidden column)
  • can use CSV export but the hidden column will also contain --X-- only
Olaf

chrisagon
Posts: 18
Joined: 2016-10-13 19:38
Location: Paris, France
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by chrisagon » 2020-03-17 18:14

Hello,
I have a trouble with the step 2.3 with "before_update".
I don't understand where is initialized $myReturnValue to TRUE !
So it seems that the program doesn't execute the line

Code: Select all

$myReturnValue = check_BE_field_permissions( $data, $memberInfo,
            $_SESSION['field_permission_tablenam'], $_SESSION['field_permission_tableID'] );
and what could be the "return" 's value of the function ..._before_update ?
The consequence is we can not update the table where is implemented this function if we let

Code: Select all

return $myReturnValue;
.
If I replace by

Code: Select all

return true;
I can update my table.

So what is the use of this code ?
Chrisagon.

chrisagon
Posts: 18
Joined: 2016-10-13 19:38
Location: Paris, France
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by chrisagon » 2020-03-17 18:15

I try to update with this correction :

Code: Select all

    $myReturnValue = TRUE;
        //Field Permissions Code
    include("hooks/field_permission_functions.php");
    
But doesn't seems to be the solution.
:?
Chrisagon.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-18 08:03

Hi Chrisagon,

I try to answer, but i will immediately after this post, post a release for a new version.
Thanks for reporting your confusion. The reason is, the documentation was not correct at step 2.3 I changed it (in the new version) to be more precise:
Step 2.3a
Search for the ..._before_update function in that table.
Replace the return TRUE; with return $myReturnValue; at the end of the function:

Note: This new variable $myReturnValue will hold either the value TRUE or FALSE. If the variable is TRUE, the record can be saved (updated), if it’s FALSE the record will not be saved (updated). If you use any other variable name already for a similar purpose, you must adjust the name $myReturnValue to your own variable name – this is even more true for the next step 2.3b!
Step 2.3b
Search for the ..._before_update function in that table (you might like to do this also in the _before_insert function, but be sure to check if your application still allows adding new records).

Note: The tested variable $myReturnValue in the followin if statement will hold either the value TRUE or FALSE. If the variable is TRUE, the record can be saved (updated), if it’s FALSE the record will not be saved (updated).
If you use any other variable name already for a similar purpose, you must adjust the name $myReturnValue to your own variable name!

Add the following code above the return $myReturnValue; at the end of the function:

//Field-Permissions (Backend)
if ($myReturnValue === TRUE) {
$myReturnValue = check_BE_field_permissions($data, $memberInfo, $_SESSION['field_permission_tablenam'], $_SESSION['field_permission_tableID']);
}

return $myReturnValue;
To answer your question: as the description of the function says: If the it is return TRUE, the record will be updated. If It is return false, the update will fail. So my extension tests, if the record should be updated or an error should be shown to the user. This last behavior (show error to user) has been changed in the new (see below) version.

If you think your (first) code is not executed, you can check by opening field_permission_functions.php.php look for

Code: Select all

function check_BE_field_permissions(&$data, $memberInfo, $field_permission_tablenam, $field_permission_tableID)
{

	$myReturnValue = TRUE;
and add this after the $myReturnValue = TRUE; line:

Code: Select all

die('it does work');
exit;
When you try to update your record you should see that message (and nothing else in your browser anymore, you will need to remove the lines again).

So, now to the new version (next post).
Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-18 08:09

Hi,

I decided to release version 1.21, so Chrisagon can implement that already.
New:
  • Locked fields (more precise their field values) will be displayed as â–’â–’â–’â–’â–’â–’ in table view.
  • Users can not use filter to search for content in a hidden column (e.g. no results will be listed where the search term is in a hidden column)
  • Users can not use quick search to search for content in a hidden column (e.g. no results will be listed where the search term is in a hidden column)
  • Users can use CSV export but the hidden column will also contain â–’â–’â–’â–’â–’â–’ only
  • Added a new file which is implemented in Step 2.1 instead of adding lots of new codelines (to accomplish the above).
Updated:
  • In detail view I removed the "cheated" error message when the data is not as expected (changed HIDDEN or LOCKED fields). Instead, the original values for hidden and locked fields are read from the database before saving and replace the data of these fields coming from the client. So users might change a hidden field (in detailview), but after saving it's back to it's previous.
  • Documentation clarified (Step 2.3 now divided in a and b)
It looks like this (Kunde is a textfield, Bemerkung a textarea and Abteilung a lookup). I did not test with checkboxes/radiobuttons/image etc). If you have such fields, please post some feedback here.
field_permissions_tv_1.2.png
field_permissions_tv_1.2.png (17.25 KiB) Viewed 15590 times
Download 1.21
(because of file size, external link)
https://dl.olaf-noehring.de/?t=32602a4d ... 1f19f0c2bc

Olaf

chrisagon
Posts: 18
Joined: 2016-10-13 19:38
Location: Paris, France
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by chrisagon » 2020-03-19 16:56

Thank you for answering me so quickly!
I will try.
Chrisagon.

chrisagon
Posts: 18
Joined: 2016-10-13 19:38
Location: Paris, France
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by chrisagon » 2020-03-20 08:57

Sorry I have an error :

Code: Select all

Fatal error: Uncaught Error: Call to undefined function check_field_permission() in 
C:\wamp64\www\hrcv3\hooks\field_permission_table_init.php:42 Stack trace: #0 
C:\wamp64\www\hrcv3\hooks\missions.php(31): include() #1 
C:\wamp64\www\hrcv3\missions_view.php(177): missions_init(Object(DataList), Array, Array) #2 {main} thrown in 
C:\wamp64\www\hrcv3\hooks\field_permission_table_init.php on line 42
At line 31 in missions.php, I have added : include("hooks/field_permission_table_init.php");
In "missions_view.php" which is a generated file, at line 177 I have :

Code: Select all

	// hook: missions_init
	$render=TRUE;
	if(function_exists('missions_init')) {
		$args=array();
		$render=missions_init($x, getMemberInfo(), $args);
	}
May be it can help you.
Chrisagon.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-03-20 09:40

Hi,

the error tells us, that function check_field_permission is not known to the script.
Did you do step 2.1 of the docs?
Search for the ..._init function in that table.
Add this after the beginning of the function:

//Field Permissions Code
include("hooks/field_permission_table_init.php");
I can not know what missions... does for you.

Olaf

ckebbell
Veteran Member
Posts: 32
Joined: 2020-01-28 18:09

Re: Field Permissions (hide / lock fields by usergroup)

Post by ckebbell » 2020-07-08 13:19

Hi Olaf

Sorry to trouble you, it has been a long time! I have finally had time to implementing the test file you sent me (which creates a log file).

My Table Field selector is still not working :cry:
TableField.JPG
TableField.JPG (24.68 KiB) Viewed 8378 times
I have taken a screenshot of the app.log (which has 500+ rows of essentially the same thing!)
applog.JPG
applog.JPG (46.49 KiB) Viewed 8378 times
I am happy to send the app.log to you. I am using xampp on a local machine. I also checked phpmyadmin and nothing is showing in the tmptable
tmptablesfields.JPG
tmptablesfields.JPG (28.33 KiB) Viewed 8378 times
I don't know what else to do. I can try uploading to a remote host, in case it is a conflict with xampp?

ckebbell
Veteran Member
Posts: 32
Joined: 2020-01-28 18:09

Re: Field Permissions (hide / lock fields by usergroup)

Post by ckebbell » 2020-07-16 01:41

Hello again

So, I was trying this on my webserver instead of my local xampp, in case there was an issue.

Now I am getting different behaviour! When I miss out step 2 (editing the hooks / tablename.php of relevant tables) I can see a full list of all fields in the database in my dropdown. I can also save new entries to the db field permissions table. However the hiding field does not work (obviously, as I have not specieid any tables!) All the table fields appear in phpmyadmin in the tmp_tables_fields.

As soon as I enter anything into the hook file, I can no longer see any table fields in the db field permissions. And nothing appears in tmp_tables_fields in phpmyadmin.

The way I found this out, I had deleted my test app from the server, rebuilt it and uploaded again. I tried the Field Permissions but it wasn't working, so I was undoing all the code changes to revert. Then I realised that phpmyadmin had populated the table fields, so I checked what was happening.

Does anyone have any experience or clues that may help me solve why this does not work for me? My previous posts on this thread show that I am carrying out all steps, if someone could please help, this mod would be very useful for my company application.

Thank you all

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by onoehring » 2020-07-19 08:34

Hi,
Now I am getting different behaviour! When I miss out step 2 (editing the hooks / tablename.php of relevant tables) I can see a full list of all fields in the database in my dropdown. I can also save new entries to the db field permissions table. However the hiding field does not work (obviously, as I have not specieid any tables!) All the table fields appear in phpmyadmin in the tmp_tables_fields.
good.
As soon as I enter anything into the hook file, I can no longer see any table fields in the db field permissions. And nothing appears in tmp_tables_fields in phpmyadmin.
I assume all table/field/filenames are correct and have been double checked.
What do you mean by "enter anything" and what did you mean by " I can no longer see any table fields in the db field permissions"? Could you please post some screenshots?

Olaf

ckebbell
Veteran Member
Posts: 32
Joined: 2020-01-28 18:09

Re: Field Permissions (hide / lock fields by usergroup)

Post by ckebbell » 2020-07-20 00:02

Hi Olaf

Thank you so much for replying and sorry I was not clear!

So, when I carry out the installation steps, if I DO NOT carry out Step 2 (inserting the code into the hooks file) then I can see **all fields from all tables** in the Table Field Dropdown. I can also see all tablefields in tmp_tables_fields in phpmyadmin (732 rows). I can also create and save records into Db field permissions.

(I am unable to post the screenshot showing all fields in the dropdown for some reason - I will post this in a separate post)
tmp_tables.JPG
tmp_tables.JPG (50.61 KiB) Viewed 8260 times
hidden.JPG
hidden.JPG (27.49 KiB) Viewed 8260 times
** These entries in the table do NOT hide any fields though, as there is nothing in any hook file to trigger the hide **

Then I carry out Step 2 from the installation PDF (insert the code from steps 2a and 2b into a hook file, for example, into Quotes.php or into Jobs.php), I can no longer see the tablefields in an Add New Record:
TableField.JPG
TableField.JPG (24.68 KiB) Viewed 8260 times

I can see my existing records that I created in Db field permission as in the screenshot hidden.jpg above. But none of these fields are actually hidden from those groups.

Also, tmp_tables_fields is no longer populated. It is now empty showing an empty result set.
tmptablesfields.JPG
tmptablesfields.JPG (28.33 KiB) Viewed 8260 times
When I look at the app.log, it just shows the "tabnames"
applog.JPG
applog.JPG (46.49 KiB) Viewed 8260 times
Last edited by ckebbell on 2020-07-20 00:07, edited 2 times in total.

ckebbell
Veteran Member
Posts: 32
Joined: 2020-01-28 18:09

Re: Field Permissions (hide / lock fields by usergroup)

Post by ckebbell » 2020-07-20 00:05

Here is the screenshot showing that if I miss Step 2, all the fields show in the dropdown
allfields.JPG
allfields.JPG (43.25 KiB) Viewed 8258 times


Ionut Bocanet
Posts: 28
Joined: 2017-03-12 09:26
Contact:

Re: Field Permissions (hide / lock fields by usergroup)

Post by Ionut Bocanet » 2020-08-11 12:57

Hello Dear Sirs,

I am also interested about the solution of this error. You were able to find the cause of this error.

I have the same error :)
Best Regards,
Ionut Bocanet

Post Reply