Page 1 of 1

Restrict Access to some fields in Detail View

Posted: 2020-06-22 14:23
by angus
Hello Board, I am trying to restrict access to allow only two groups to approve a record. I have checked the var dump and everything is coming through ok but the access is restricted for everyone and the two groups I want to allow also.

Can you help point me in the right direction?

Code: Select all

/* work out the group the person is in first and then restrict access to the approvals button for users */
                                $Group=sqlValue("Select table1.ID From membership_users Inner Join table2 On membership_users.memberID = table2.ID Inner Join table1 On table2.ID2 = table1.ID3 where membership_users.memberID='".$memberInfo['username']."'"); 
                                //var_dump($Group, $memberInfo); exit();
                                /* current user is not the allowed */
             if($memberInfo['group'] != $Group || $memberInfo['group'] !='FullAccess'){
                    $html .= <<<EOC
                                        <script>
                                              \$j(function(){
                                                                                                                                                                                  \$j('#Approval').select2('readonly', true),
                                                                                                                                                                                  \$j('#Notes').attr('readonly', true);
                                              })
                                        </script>
EOC;
             }


Re: Restrict Access to some fields in Detail View

Posted: 2020-06-22 17:45
by pbottcher
Hi,

it looks like you try to have an own group handling. Did you check the standard-group permissions for the user?

Maybe you can just add an alert inside your script to see if it is called.

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-22 19:26
by angus
Hi Pbottcher, to get round the restriction of appgini only allowing 1 person per group I made some adjustments. Everyone is on there own group. I then created a function to copy the record to the correct groups, all groups have correct permissions.

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-22 20:01
by jsetzer
... restriction of appgini only allowing 1 person per group ...
I guess you mean 1 group per person instead.

You can have (almost) unlimited users per group.

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-22 20:13
by angus
sorry what I meant was 1 record cant appear in more than one group. In my scenario I have 3 groups who need to be able to view/edit the record.

getting back to my main issue though (as I have the groups working, people can see what they should, people can edit what they should) I want to restrict access to certain fields to certain groups? Not sure why this doesnt work?

Code: Select all

/* work out the group the person is in first and then restrict access to the approvals button for users */
                                $Group=sqlValue("Select table1.ID From membership_users Inner Join table2 On membership_users.memberID = table2.ID Inner Join table1 On table2.ID2 = table1.ID3 where membership_users.memberID='".$memberInfo['username']."'"); 
                                //var_dump($Group, $memberInfo); exit();
                                /* current user is not the allowed */
             if($memberInfo['group'] != $Group || $memberInfo['group'] !='FullAccess'){
                    $html .= <<<EOC
                                        <script>
                                              \$j(function(){
                                                                                                                                                                                  \$j('#Approval').select2('readonly', true),
                                                                                                                                                                                  \$j('#Notes').attr('readonly', true);
                                              })
                                        </script>
EOC;
             }


Re: Restrict Access to some fields in Detail View

Posted: 2020-06-22 20:52
by pbottcher
did you put an alert in your function to see if is called?

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-23 07:19
by angus
Yes it does get called Pbottcher,

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-23 08:56
by angus
I should add if I have just one group in the restriction it works but does not work with 2 for some reason?

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-23 19:47
by pbottcher
So what is the logic to when the code shall be executed?

If the user is in a group not equal to $group or not equal to FullAccess?

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-23 20:13
by angus
thats right Pbottcher, it is in the hooks dv. user is in a group not equal to $group or not equal to FullAccess. I just not sure why its not working?

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-24 05:41
by pbottcher
Hi,

thanks for the information. So I guess it is a logic issue.

Try

Code: Select all

if($memberInfo['group'] != $Group && $memberInfo['group'] !='FullAccess'){
instead.

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-24 13:34
by onoehring
Hi Angus,

you may also want to take a look into my Column-Value-Based Fields Permission extension (see footer). With this you can hide records from users based on certain criteria (a value of some field). If your records get approved, this could mean, they get a different status in the column on which the permissions are based.

Olaf

Re: Restrict Access to some fields in Detail View

Posted: 2020-06-27 19:06
by angus
Pbottcher, it does seem to work with the AND but I admit it confuses me why this works to be honest.

Olaf, I was not aware of this, I will give it a go, thank you!