Jump to content

Admin Actions Permissions issue and more


Recommended Posts

 

I thought I'd start a new threat for this issue, I don't like typing in the module's initial support threat too much, maybe the issue is just very specific to my stupidity and nothing of general interest. 

Run
Sorry, you do not have permission to use this action.

when trying to run my custom admin action.

In permissions, I gave the superuser all available permissions, and the guest user I gave permissions to

Run selected AdminActions actions
Run AdminActions restore feature

 in /admin/access/roles/edit/?id=37 and /admin/page/edit/?id=37 (don't know what's the difference)

as well as page edit permissions in the role settings and in the template settings relevant to the executed action (so I tried many things) but none of it works. "guest" however doesn't appear in the available roles dropdown in /admin/module/edit?name=ProcessAdminActions 

And the other issue is, not sure if it's related, I can run all actions, though not successfully, even in spite of not filling the required fields. I get an error like memory exhausted

I tried on localhost (MAMP) and remote web-server as well.

PW version 3.0.200
Admin Actions version 0.8.12
php version 7.2.34 (MAMP)
and php version 7.3.33 (world4you.com)

Link to comment
Share on other sites

Those permissions only allow access to see the Setup > Admin Actions menu. In the other thread I mentioned that you need to give roles access to each specific action. I am still not clear if you have done that or not.

I am referring to the interface below in the module's settings. Can you confirm you have given access to your custom action?

image.thumb.png.df3ffe02ffdd0274411b7d8aedb3f12f.png

  • Like 1
Link to comment
Share on other sites

yes I did that, as mentioned here: (that's the path to that page, for me at least)

2 hours ago, fruid said:

"guest" however doesn't appear in the available roles dropdown in /admin/module/edit?name=ProcessAdminActions 

 

Link to comment
Share on other sites

but I should say, that's not the issue, I don't need let alone want guests to be able to execute the action, I just read somewhere that that could help (?). I just need it to work for superuser.

Link to comment
Share on other sites

Sorry, I am a bit confused on what you're trying to do. For the admin the guest role won't have access at all anyway. But if you don't actually need that and you're only looking to get it to work for a superuser, then I am not sure what issue you are still having. Is it the error you noted about not having permission, or is it the out of memory error, or something else?

If it's the out of memory error, then that isn't related to this module, but rather then code in your custom action. You might be able to get away with a ini_set('memory_limit', '-1'), or you might need to build in a way to do the action in batches. It's impossible to know without seeing what your action code is doing.

  • Like 1
Link to comment
Share on other sites

it's two issues, not sure if related.

Issue #1

one is, I'm lacking permissions to execute a custom action. To find out if it's my code that's causing the problem, I tried something very simple first instead. 

class saveOrShow extends ProcessAdminActions {
        
    protected $title = 'saveOrShow';
    protected $description = 'save or show';
    protected $author = 'FRE:D';
    
    protected $executeButtonLabel = 'DARE';
    protected $icon = 'shopping-basket';

    protected function defineOptions() {
        return array(
            array(
                'name' => 'parentPage',
                'label' => 'Parent Page',
                'description' => 'The parent page of orders',
                'type' => 'pageListSelect',
                'required' => true
            ),
            array(
                'name' => 'saveOrShow',
                'label' => 'save or just show?',
                'type' => 'radios',
                'optionColumns' => 1,
                'options' => array(
                    '0' => 'show',
                    '1' => 'save'
                ),
                'value' => '0'
            )
        );
    }

    protected function executeAction($options) {  
      return ':D';
    }

} 

But that's just not allowed. I get

 648843611_Screenshot2022-09-03at23_36_08.png.3c387aeef8654ba5e8bf5a4cafdfdc4e.png

And here's the permissions settings pages:

731715133_Screenshot2022-09-03at23_30_56.png.65e979032d67da052062a6ede6615709.png831547558_Screenshot2022-09-03at23_31_08.png.65d4d93bdcd1d0733401078aeea59ec5.png

Screenshot 2022-09-03 at 23.32.30.png

Link to comment
Share on other sites

Hi @fruid - it's because of the lowercase "s" in your class name. If you change it to "class SaveOrShow" it will work as expected. You will need to re-save the module settings to clear the cache, but after that it will work.

  • Like 1
Link to comment
Share on other sites

yes, that solved the first issue actually.

And somehow this seems to have messed up all other actions too, because I was able to execute other actions even though they had required fields. So I got no error when submitting, but after that, the server loaded and loaded and then threw a "memory exhausted" error. Then I tried with a very small (2 lines) .csv file (which is the required field) but the result was the same: memory exhausted. All of that made no sense to me either Adrian.

But thankfully that's gone now because the unpopulated required field impedes the process. Maybe it was still worth mentioning? 

Anyways, thanks so far!

However, speaking of required fields, I have another question…

I have a dropdown field in my defineOptions method like so:

protected function defineOptions() {
	return array(
		array(
			'name' => 'content',
			'label' => 'Content type',
			'description' => 'What is this content for?',
			'type' => 'select',
			'required' => true,
			'options' => array(
				'0' => '',
				'1' => 'category1',
				'2' => 'category2',
				'3' => 'category3',
				'4' => 'category4',
				'5' => 'category5'
			),
			'value' => '0'
		),
	),
}

 but it would just ignore the required property, no errors when nothing is selected. What am I doing wrong?

And lastly, I'm wondering if it's possible to show content on the results screen? So far I can only show a message like $this->message("that's all I can do here");

Thanks a lot Adrian!

Link to comment
Share on other sites

Regarding the required field, you are not only setting a value, but the first empty option also has a value.

Try it like this:

array(
    'name' => 'content',
    'label' => 'Content type',
    'description' => 'What is this content for?',
    'type' => 'select',
    'required' => true,
    'options' => array(
        '' => 'Choose One',
        '1' => 'category1',
        '2' => 'category2',
        '3' => 'category3',
        '4' => 'category4',
        '5' => 'category5'
    )
)


Regarding the memory errors - I don't think that can be specifically related to this module.

As for outputting more content, so you output whatever you want by assigning the html to:
 

$this->output = 'my HTML output';

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I figured out what's with the memory exhausted problem. That is solely related to whether or not I do an automatic database backup or not. So I do have a work around, you know, just not do database backups. It might just have to do with the server, I will look into that, but it's not urgent.

Link to comment
Share on other sites

Regarding the DB backup - I need to switch that from using PW's backup methods to system backups, like Duplicator does: https://github.com/flydev-fr/Duplicator/blob/69d78a13bb77cc5b541e959e864480ad41a90a82/Classes/BackupDatabase.php#L159

Right now, I am not sure about the Repeater question - no time to investigate, but it might be an easy enough fix to support selecting repeater templates.

  • Like 1
Link to comment
Share on other sites

1 hour ago, adrian said:

but it might be an easy enough fix to support selecting repeater templates

not an easy fix for me. In the action options I can only select the field inside the repeater, not the repeater. Not sure why I would want that, but there's no easy way to get to the field's "parent" repeater. Also, I guess, the issue might be that you need to specify which one of the many repeaters – thus multiple repeater's subfields with the same name – to set the value for. 

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...