change record owner non-admin

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

change record owner non-admin

Post by baudwalker » 2022-04-19 10:08

There are a number of groups, each maintain their own records. View; Edit: and Delete are all set to Owner.

There are also a few editors who edit the complete database. View; Edit: and Delete are set to All. If the editors update an entry the ownership remains with the original group. But if they create a record the editor group own the record.

Is it possible for the editor group to be able to set/re-set the owner.

There is a bulk change but that is only for the Admin.

Regards Barry

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

Re: change record owner non-admin

Post by jsetzer » 2022-04-19 11:00

Sure. You can use AppGini's set_record_owner() function in PHP.
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
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-20 23:50

OK, Thank you. I will attempt to implement that somehow.

regards Barry

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-21 01:24

Hi Jan,

I can't see how the " AppGini's set_record_owner()" can do as I want. My interpretation is that it forces the registration of a predetermined owner to that file.

What I require is a way that a group, other than the admin, can use the function "mass_change_owner" from within the "more drop down" without sharing all the admin rights.

Barry

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

Re: change record owner non-admin

Post by jsetzer » 2022-04-21 06:33

Is it possible for the editor group to be able to set/re-set the owner.
Yes, it is possible by using set_record_owner()-function in a server side PHP script.
... a group, other than the admin, can use the function "mass_change_owner" from within the "more drop down
You can create a custom "mass_change" function (AKA Batch Action) according to the docs here:
https://bigprof.com/appgini/help/advanc ... ch-actions

In your serverside code use set_record_owner()-function according to your needs.
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
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-21 07:59

Thanks Jan,

I will take a look at your suggestions.

I just thought there may have been a way of extending the existing "change owner" for the admin to and extra group. save reinventing the wheel so to speak.

Regards Barry

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-23 01:02

I an attempting to implement the admin batch action for changing ownership of one or several records. in the hooks/tablename.php I have added the following, and restrict it to a specific group.

Code: Select all

 function Members_batch_actions(&$args){
    $mi = getMemberInfo();
    if(in_array($mi['group'], array('editor'))){

    return array(
        array(
            'title' => 'Change Owner',
            'function' => 'mass_change_owner',
            'icon' => 'glyphicon glyphicon-user'
        )
    );
    }
This calls the function "mass_change_owner" from common.js.

All goes well. The title appears in the more dropdown only for the specific group. When the title is selected the modal pops up and looks exactly the same as it does with the admin, but it is not populated with the group/user information.

what am I missing?

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

Re: change record owner non-admin

Post by pbottcher » 2022-04-23 09:58

Hi,

you cannot use the mass_change_owner as a normal user. This requires admin privileges :o .

So what you can do is to create your own mass_change_owner for the user.
As you did already in your code. Change

Code: Select all

    return array(
        array(
            'title' => 'Change Owner',
            'function' => 'my_mass_change_owner',  // <---changed to my_mass_change_owner
            'icon' => 'glyphicon glyphicon-user'
        )
    );
Now lets add the own my_mass_change_owner function.

1, copy the code from the mass_change_owner function within the common.js to the hooks/Members-tv.js file.
2, rename the mass_change_owner function to my_mass_change_owner
within this code in the hooks/Members-tv.js file:
3, search for admin/pageEditOwnership.php in the update_record function (around line 58) and replace it with hooks/MypageEditOwnership.php
4, search for admin/getUsers.php in the populate_new_owner_dropdown function (around line 128) and replace it with hooks/MygetUsers.php
5, copy the admin/getUsers.php file to hooks/MygetUsers.php
6, edit hooks/MygetUsers.php and replace require("{$curr_dir}/incCommon.php"); with require("{$curr_dir}/../lib.php");
7, copy the admin/pageEditOwnership.php file to hooks/MypageEditOwnership.php
8, edit hooks/MypageEditOwnership.php and replace require("{$currDir}/incCommon.php"); with require("{$currDir}/../lib.php");

Now you should be able to use the new feature.

WARNING: This is a quick fix and you may need to add additional security in order to prevent unwanted people to call your new functions.
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
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-25 03:24

Works perfectly thank you.

I did copy and rename the files but I did not change incCommon.php to ../lib.php.

Thanks to you and Jan for taking the time to point my in the correct direction.

Barry

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-25 06:38

These two arrays work separately (ONE & TWO) or together (Three) but with (FOUR) I get the error "unexpected 'if' (T_IF) in ..."

What am I doing wrong in FOUR please?

Barry

ONE

Code: Select all


function Members_batch_actions(&$args){
    $mi = getMemberInfo();
    if(in_array($mi['group'], array('editor'))){

    return array(
        array(
            'title' => 'Change Owner',
            'function' => 'mass_change_owner',
            'icon' => 'glyphicon glyphicon-user'
        )
    );
    }
TWO

Code: Select all

function Members_batch_actions(&$args){

     return array(
                array(
        		'title'=> 'Renew Membership Year',
        		'function' => 'renew_membership_year',
        		'icon' => 'check',
        		)           	
        );
        }

  
THREE

Code: Select all

function Members_batch_actions(&$args){

     return array(
                array(
        		'title'=> 'Renew Membership Year',
        		'function' => 'renew_membership_year',
        		'icon' => 'check',
        		),           

                array(
                    'title' => 'Change Owner',
                    'function' => 'my_mass_change_owner',
                    'icon' => 'glyphicon glyphicon-user',
                    )             
        );
        }
FOUR

Code: Select all

function Members_batch_actions(&$args){

     return array(
                array(
        		'title'=> 'Renew Membership Year',
        		'function' => 'renew_membership_year',
        		'icon' => 'check',
        		),

            ($mi = getMemberInfo()
             if(in_array($mi['group'], array('editor'))){

                array(
                    	'title' => 'Change Owner',
                   	'function' => 'my_mass_change_owner',
                    	'icon' => 'glyphicon glyphicon-user',
                    	)
              }
        );
        }

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: change record owner non-admin

Post by baudwalker » 2022-04-25 07:07

OK got it working

Code: Select all


function Members_batch_actions(&$args){

     $mi = getMemberInfo();

     if(in_array($mi['group'], array('editor'))){

     return array(
                array(
        		'title'=> 'Renew Membership Year',
        		'function' => 'renew_membership_year',
        		'icon' => 'check',
        		),
                array(
                    	'title' => 'Change Owner',
                    	'function' => 'my_mass_change_owner',
                    	'icon' => 'glyphicon glyphicon-user',
                    	)
                );
              }else{
    return array(
               array(
                	'title'=> 'Renew Membership Year',
                	'function' => 'renew_membership_year',
                	'icon' => 'check',
                	)
                  );
              }

           }

Post Reply