Jump to content


Photo

ProcessPageDelete

Module

  • Please log in to reply
24 replies to this topic

#1 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 11 January 2012 - 04:16 PM

Here it is: The delete link in the page list :)

Download:
https://github.com/N...ocessPageDelete

#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3124

  • LocationAtlanta, GA

Posted 12 January 2012 - 11:50 AM

Nice job Nico!

Just a couple suggestions:

Get rid of this line in the code below, you don't need it. It's also not very safe because it will load any page named trash in the site, so if someone has another page named trash anywhere in the site, your API call might load it instead of the one you want. That could be solved by prepending a '/' to the beginning, but you won't even need this line so just delete it:
$trash = $this->pages->get('name=trash'); // delete this

You are currently doing this:
$page->parent = $trash;

Instead, it's preferable to use the API function (which is why you won't need $trash anymore):
$this->pages->trash($page);

For security, in your execute() function, you should add this immediately after retrieving the $page:
if(!$page->deleteable()) throw new WirePermissionException("You don't have access to delete that page");

You are already performing this check in your function that adds the action to PageList, which is good. But it's not providing any security unless you also perform the permission check in your execute function().

#3 transpix

transpix

    Jr. Member

  • Members
  • PipPip
  • 10 posts
  • 0

  • LocationBarnstaple, Devon. UK

Posted 16 January 2012 - 11:30 PM

Finally found time to add this to my site!

After making the changes suggested I was getting the following error after clicking delete;

Can't save page 1323: /trash/1323_test_page/: Chosen parent '/trash/' already has a page named '1323_test_page'

The page was still moved to trash though. I removed the following line and that fixed the error;

$page->save();

I didn't try the module before making the changes, but I guess the change to;

$this->pages->trash($page);

calls the save page method anyway?

#4 transpix

transpix

    Jr. Member

  • Members
  • PipPip
  • 10 posts
  • 0

  • LocationBarnstaple, Devon. UK

Posted 16 January 2012 - 11:39 PM

I just made one other little tweak so that the pages tree opens up at the level of the page you just deleted.

After the page deleted exception;

if(!$page->deleteable()) throw new WirePermissionException("You don't have access to delete that page");

I added the following to get the parent id;

$parent_id = $page->parent_id;

...and then altered the redirect to;

$this->session->redirect("../?open={$parent_id}");


#5 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3124

  • LocationAtlanta, GA

Posted 17 January 2012 - 08:28 AM

Nico, Transpix -- it's correct that you don't need the save() if you are already using $pages->trash($page). that's because the trash() function already performs the save for you.

#6 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 805 posts
  • 212

  • LocationMidlands, UK

Posted 09 April 2012 - 05:58 AM

Thanks for this, is there anyway of adding a JS popup to confirm delete?

#7 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 09 April 2012 - 08:07 AM

New version is uploaded.

I added the popup confirmation and integrated transpix's improvements.

#8 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 805 posts
  • 212

  • LocationMidlands, UK

Posted 09 April 2012 - 03:59 PM

Thanks Nico! Will try it out in the morning

#9 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 805 posts
  • 212

  • LocationMidlands, UK

Posted 11 April 2012 - 08:33 AM

My users are having problems deleting. It just returns them to main admin page and says that they are logged in? The traditional method of edit then delete works for them however. Any ideas? Thanks Nico

#10 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 11 April 2012 - 08:51 AM

Which Browser, which OS (Mac/Windows/Linux)? Is Javascript activated?

#11 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 805 posts
  • 212

  • LocationMidlands, UK

Posted 11 April 2012 - 09:33 AM

Sorry, tried on OSX and Windows, both with JS.
Can I give you any more info?
It works great for me as a superuser.

#12 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 11 April 2012 - 05:32 PM

So it's only not working for not superusers? Which permissions are the normal users having?

#13 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 805 posts
  • 212

  • LocationMidlands, UK

Posted 12 April 2012 - 03:28 AM

No sorry, it's working for superusers but editors (which is the only other group I have) cannot delete, but they can delete from within the entry (edit->delete)

#14 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 12 April 2012 - 02:00 PM

Yeah, but could you look at "permissions" -> "roles" which rights the user groups are exactly have?

#15 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,526 posts
  • 855

  • LocationVihti, Finland

Posted 12 April 2012 - 02:03 PM

Nico: not tested, but probably just adding

'permission' => "page-delete"

To your getModuleInfo might do the job.

#16 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 12 April 2012 - 02:16 PM

@apeisa OK, I added it and uploaded the new version. Maybe it'll work :)

#17 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 335 posts
  • 155

  • LocationKatoomba, AU

Posted 18 April 2012 - 01:39 AM

What a great time saver. Thanks Nico!

#18 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 335 posts
  • 155

  • LocationKatoomba, AU

Posted 05 May 2012 - 01:56 AM

Hi Nico,

Is there any reason why the javascript below is being inserted into my templates?

Regards
Marty

<script type="text/javascript">
  $(document).ready(function() {
   $("li.PageListActiondelete a").live("click", function(el){
    if(!confirm("Are you sure?")) { return false; }
   });
  });
  </script>


#19 Nico Knoll

Nico Knoll

    The Boss.

  • Members
  • PipPipPipPipPip
  • 644 posts
  • 236

  • LocationBerlin, Germany

Posted 05 May 2012 - 02:42 AM

Well, I guess I forgot to insert a command to check if you are in the backend. Will add it today ;)

#20 Soma

Soma

    Hero Member

  • Moderators
  • 3,205 posts
  • 1757

  • LocationSH, Switzerland

Posted 01 August 2012 - 11:43 AM

Well, I guess I forgot to insert a command to check if you are in the backend. Will add it today ;)


Have you added the check already? Creating modules means also maintaining them, continue to fix stuff. :D

Edit: I also would suggest to name the module "PageListActionDelete". So it's a little more clear its extending the actions on the page list.
Also before I forget it, would be nice to have it translateable too. ;)

@somartist | modules created | support me, flattr my work flattr.com






Also tagged with one or more of these keywords: Module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users