Nico Knoll Posted January 11, 2012 Share Posted January 11, 2012 Here it is: The delete link in the page list Download: https://github.com/N...ocessPageDelete 3 Link to comment Share on other sites More sharing options...
ryan Posted January 12, 2012 Share Posted January 12, 2012 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(). Link to comment Share on other sites More sharing options...
transpix Posted January 17, 2012 Share Posted January 17, 2012 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? Link to comment Share on other sites More sharing options...
transpix Posted January 17, 2012 Share Posted January 17, 2012 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}"); Link to comment Share on other sites More sharing options...
ryan Posted January 17, 2012 Share Posted January 17, 2012 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. Link to comment Share on other sites More sharing options...
onjegolders Posted April 9, 2012 Share Posted April 9, 2012 Thanks for this, is there anyway of adding a JS popup to confirm delete? Link to comment Share on other sites More sharing options...
Nico Knoll Posted April 9, 2012 Author Share Posted April 9, 2012 New version is uploaded. I added the popup confirmation and integrated transpix's improvements. Link to comment Share on other sites More sharing options...
onjegolders Posted April 9, 2012 Share Posted April 9, 2012 Thanks Nico! Will try it out in the morning Link to comment Share on other sites More sharing options...
onjegolders Posted April 11, 2012 Share Posted April 11, 2012 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 Link to comment Share on other sites More sharing options...
Nico Knoll Posted April 11, 2012 Author Share Posted April 11, 2012 Which Browser, which OS (Mac/Windows/Linux)? Is Javascript activated? Link to comment Share on other sites More sharing options...
onjegolders Posted April 11, 2012 Share Posted April 11, 2012 Sorry, tried on OSX and Windows, both with JS. Can I give you any more info? It works great for me as a superuser. Link to comment Share on other sites More sharing options...
Nico Knoll Posted April 11, 2012 Author Share Posted April 11, 2012 So it's only not working for not superusers? Which permissions are the normal users having? Link to comment Share on other sites More sharing options...
onjegolders Posted April 12, 2012 Share Posted April 12, 2012 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) Link to comment Share on other sites More sharing options...
Nico Knoll Posted April 12, 2012 Author Share Posted April 12, 2012 Yeah, but could you look at "permissions" -> "roles" which rights the user groups are exactly have? Link to comment Share on other sites More sharing options...
apeisa Posted April 12, 2012 Share Posted April 12, 2012 Nico: not tested, but probably just adding 'permission' => "page-delete" To your getModuleInfo might do the job. Link to comment Share on other sites More sharing options...
Nico Knoll Posted April 12, 2012 Author Share Posted April 12, 2012 @apeisa OK, I added it and uploaded the new version. Maybe it'll work Link to comment Share on other sites More sharing options...
Marty Walker Posted April 18, 2012 Share Posted April 18, 2012 What a great time saver. Thanks Nico! Link to comment Share on other sites More sharing options...
Marty Walker Posted May 5, 2012 Share Posted May 5, 2012 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> Link to comment Share on other sites More sharing options...
Nico Knoll Posted May 5, 2012 Author Share Posted May 5, 2012 Well, I guess I forgot to insert a command to check if you are in the backend. Will add it today Link to comment Share on other sites More sharing options...
Soma Posted August 1, 2012 Share Posted August 1, 2012 On 5/5/2012 at 7:42 AM, Nico said: 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. 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. Link to comment Share on other sites More sharing options...
ryan Posted August 1, 2012 Share Posted August 1, 2012 And would be nice to have Nico add this and his other modules to the directory too (when you have time, of course). Link to comment Share on other sites More sharing options...
Nico Knoll Posted August 8, 2012 Author Share Posted August 8, 2012 I added the check and added the module to the directory (http://modules.processwire.com/modules/process-page-delete/) 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 15, 2012 Share Posted October 15, 2012 Just found this one. Thanks Nico, this is very useful. Link to comment Share on other sites More sharing options...
Radek Posted March 16, 2013 Share Posted March 16, 2013 Hi, just tested this module in demo mode $config->demo = true; In demo mode is possible delete(move to trash) pages. Nico please make update to deny deleting pages in demo mode. Thanks 1 Link to comment Share on other sites More sharing options...
Nico Knoll Posted March 17, 2013 Author Share Posted March 17, 2013 Should be fixed. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now