How? Make one field read-only for usergroup

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1201
Joined: 2019-05-21 22:42
Location: Germany
Contact:

How? Make one field read-only for usergroup

Post by onoehring » 2019-06-04 16:08

Hi,

I want to avoid that a regular user (not admin) can edit a certain field in a record (but the user must be allowed to edit other fields of the record).
How can I accomplish that?

Searching the forum for read only did not help me.

Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2019-06-04 17:32

Hi,

you would need to provide a little bit more information about your setting. There are a lot of posts about making a field read-only and it depends on the field you have. Is it a look_up field, text field, .... ?
Do you need to make it read-only when the record is already created, or only when it is updated?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 06:18

Hi pbötcher,

in the table are 3 fields at this time:
ID, Container, Place.
Of course, the admin (of super admin) should be able to edit the column container and place (ID is PK,autoincrement).
The regular user should not be able to edit the column Container, but only change the column Place of the entity Container.
I am not sure how to do this, as the regular user also needs the ability to edit the record (but only place).

Probably it would be useful, if the admin (super admin) can also add new records (meaning new Container and setting some Place). This I can do using the regular user-/group-setup permissions I think.

Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2019-06-05 06:55

Hi,

in the hooks/TABLENAME.php file you have a function TABLENAME_footer.

in the case section "detailview" or "tableview+detailview" depending on what you use put

Code: Select all

			case 'VIEW':
				if ($memberInfo['group'] != 'Admins') {
					$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
				}
				else $footer='';
				break;
TABLENAME is your TABLE and VIEW is either detailview or tableview+detailview
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 07:13

Hi pbötcher,
thank you a lot. I will try that. ... No, it did not work. Same for super admin and user of a different group.

I added/replaced to function tbl_Contain_footer

Code: Select all

			case 'detailview':
				//$footer='';
if ($memberInfo['group'] != 'Admins') {
	$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
}
else $footer='';
				break;

			case 'tableview+detailview':
				//$footer='';
if ($memberInfo['group'] != 'Admins') {
	$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
}
else $footer='';
				break;
Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2019-06-05 07:29

Hi, can you run the $j('#Container').attr('readonly','true') in the debug mode to see if it works.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 07:39

Hi,

yes, that works fine.
(I did change the ID to ContainerCode to match the fields)

$j('#ContainerCode').attr('readonly','true')

Of course, I changed that in your original suggestion as well.
Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2019-06-05 07:53

ok, so is it working now? in the code you posted you had #Container
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 08:03

Hi,
no, it's not working with this code (but when I enter your line in the console the field get's deactivated). I am posting the full function to make sure, I am in the correct place in the file.

Code: Select all

function tbl_Container_footer($contentType, $memberInfo, &$args){
		$footer='';

		switch($contentType){
			case 'tableview':
				//$footer='';
if ($memberInfo['group'] != 'Admins') {
	$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
				break;

			case 'detailview':
				//$footer='';
if ($memberInfo['group'] != 'Admins') {
	$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
				break;

			case 'tableview+detailview':
				//$footer='';
if ($memberInfo['group'] != 'Admins') {
	$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
				break;

			case 'print-tableview':
				$footer='';
				break;

			case 'print-detailview':
				$footer='';
				break;

			case 'filters':
				$footer='';
				break;
		}

		return $footer;
	}
Olaf


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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 08:31

Hi,
I added

Code: Select all

$footer='<!--TEST: '.$memberInfo['group'].' -->"
Diese Ausgabe erscheint aber nicht im generierten HTML Code der Seite.
Kann es sein, dass der (Hook) Code gar nicht ausgeführt wird? Wie kann ich das prüfen?

Olaf

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

Re: How? Make one field read-only for usergroup

Post by onoehring » 2019-06-05 08:46

Hi,

problem SOLVED.

a) the suggestion from pbötcher ( viewtopic.php?f=2&t=3036&p=10110#p10093 ) works fine. Thank you.

b) In the hooks folder there was a file tbl_container ... I renamed the table and I simply added his suggestion to the wrong hooks-file. My fault.

Olaf

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

Re: How? Make one field read-only for usergroup

Post by aarlauskas » 2021-11-06 21:07

Hi, how do you add additional fields to be read only in detail view? Also this seems to be only working for Text type of field. Anyway to deactivate lookup fields? Thanks

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: How? Make one field read-only for usergroup

Post by pfrumkin » 2021-11-08 16:58

Hi,

I am not clear on what you are asking.

Are the additional fields added to the table?

I would look at the tablename_dv hook. There, you can add criteria if the field is readonly for some and not others. If the field is readonly for all users, then another option is to put it in tablename-dv.js file. In either case, this approach requires JQuery coding. The JQuery code is something link
$j('#fieldname').attr('readonly',true);

Hope that helps. Good luck.

~Paul

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2021-11-08 21:51

Hi Arni,

for a lookup you need either to wait for the element to be created, which happens after the page is loaded.

An alternativ solution could be that you create a special template file for this case and use the _init hook to point in the needed case to that template.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by aarlauskas » 2021-11-09 19:52

Hi and thanks for the tips. The original Pascal's solution is good enough for what I need right now, all I want to know is how to lock two or three fields in detail view. The below code locks field 'Container'. If I want to lock 2x fields, 'Container' and 'Ship' for example, how to add 'ship' to this code? Tried some combinations but no luck :D

Code: Select all

$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1658
Joined: 2018-04-01 10:12

Re: How? Make one field read-only for usergroup

Post by pbottcher » 2021-11-10 21:20

Hi Arni,

just add the additional field with a comma sepatation.

e.g. $j('#Container, #FIELD2, #FIELD3').attr('readonly','true')
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

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

Re: How? Make one field read-only for usergroup

Post by aarlauskas » 2021-11-11 15:59

Brilliant! Thanks Pascal :D

miwalder
Posts: 10
Joined: 2013-02-11 20:36
Location: Switzerland
Contact:

Re: How? Make one field read-only for usergroup

Post by miwalder » 2024-07-12 08:42

Hi,
If data security is not important, you can hide or define fields read only with just CSS. You can add a usergroup where these rules should apply. Consider, that the hidden information is still accessible in the html source code. So it's not a column based security feature but a useful usability hack. See this howto to implement it in Appgini: https://forums.appgini.com/phpbb/viewto ... f=7&t=5416

Post Reply