We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Can members delete their own individual posts, or can that only be done from the Manager?
      Todd
      • 3749
      • 24,544 Posts
      No, only from the Manager. I've thought about it from time to time, but was concerned about the security issues involved in letting people delete resources from the front end.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 42562
        • 1,145 Posts
        I used to want this feature but I reworked my project and had a rethink.

        Reason for wanting users to delete resources.

        First, I was using Articles (not anymore, hooray! I still use Quip and all existing comments).
        A user would create a resource, and would be stuck with that resource url forever...
        So I went on to provide the alias field for peeps to change if they ever wanted to rename their resource pagetitle - too cumbersome!

        But now, I use Collections as a mere container, which does nothing obsessive to alter the nature of the resource.

        Articles provided me with a nice relative system ..../blog1/friendlyurl.html, /blog2/friendlyurl.html
        So I use CustomUrls to achieve this.
        The benefit for me is that the urls are forced and updated each time a save is done.
        I keep the alias field unavailable.
        I tell users to name resources wisely from the start.
        When a user decides that a resource needs to be changed, well they can change the pagetitle, and the url is automatically updated.

        If they want that resource to be unpublished, not just renamed, I provided a neat means for them to click "Mark as Draft", and jQuery goes on to update the hidden pub_date field to a date in the next millenium. Of course they can un-mark this later (clears the value in the pub_date field).
        Or just provide that sneaky [[*published]] checkbox field.

        I see no reason (presently) a user would want to delete from the frontend. I don't provide fancy [[~12]] links, so there is no danger of a resource referenced wrongly. [ed. note: donshakespeare last edited this post 11 years, 9 months ago.]
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 42562
          • 1,145 Posts
          @todd.b On another note, the [[*deleted]] field can be exposed in the frontend via NewsPublisher.
          It provides the user with a checkbox. When you submit the form, NewsPublisher will not show the newly "published" file, because it has been marked for deletion, and the user will no longer have access to it unless you display the deleted file with something like getResource 's showDeleted

          After all this, it is left for the Sudo to annihilate that resource completely from the manager.

          I hope this helps.

          @BobRay, are there any security issues about this that I do not know about? It seems to work perfectly fine.
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 40088
            • 708 Posts
            @donshakespeare Previously I did experiment with [[*deleted]] but was unable to get it to work. I have a member page that lists all their resources and was attempting to add (essentially) a ‘delete’ button to each result, along with the NP ‘edit’ button.

            Also, I agree about the sudo delete, my members don't need that level of access, but it might be useful if they could remove posts from public view and the site admin can deal with permanently deleting them from the system.

            Though ... now that I think about it, perhaps if members had the option to un-publish their individual posts from the front that might be a better option than deleting. Is that possible? [ed. note: todd.b last edited this post 11 years, 9 months ago.]
              Todd
              • 42562
              • 1,145 Posts
              Allowing the user to delete from a list of resources is a bit risky in my opinion.
              But I guess a snippet together with your getResource call might work: one that would grab the +ID of a particular resource and set the [[*deleted]] field through the api.
              I might even look into this.

              On the other hand, exposing the [[*deleted]] field in NewsPublisher form works as expected.
              Here a user gets to open up the resource in question, and then proceed to delete it: lesser room for error on their part.
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                • 3749
                • 24,544 Posts
                The 'deleted' field should work, but so should the 'published' field. You can always change the caption to something like "Check this Box to unpublish/delete this page."

                In the case of the 'deleted' field, the resource is marked as deleted, but won't actually be removed until someone clicks on the garbage-collection icon above the Resource tree. Until then, it can always be un-deleted.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 42562
                  • 1,145 Posts
                  @todd.b this works for me, see if it is what you want.

                  In getResources call, add to your TPL, e.g deleteThis tpl
                  <a href="[[~[[+id]]]]">[[+pagetitle]]</a>
                  <form action="deleted.html" target="new" method="post">
                  <input type="hidden" value="[[+id]]" name="resourceToDelete" />
                  <input type="submit" value="Delete This resource" /></form>
                  <br/><br/>

                  In deleted.html, call this snippet, [[!resourceToDelete]] or call the snippet in the same page as the list, _SELF
                  <?php
                  if ($_POST["resourceToDelete"]) {//if this variable exists and has been sent via the form
                      $thisID = $_POST["resourceToDelete"];
                      $thisResource = $modx->getObject('modResource', $thisID);//pull out the particular resource
                      $userID = $modx->user->get('id');//get the user's id
                      //$createdBY = $thisResource->get('createdby'); //get the creator of this resource
                      $publishedBY = $thisResource->get('publishedby');//get the publisher of this resource
                      if ($publishedBY == $userID) {//do not delete anything whatsoever unless the user owns the resource
                          $thisResource->set('deleted', 1); //to undelete, set to 0
                          $thisResource->save();
                          echo "yayyy! you've done deleted your bank account";
                      }
                      else {
                          echo "Seriously, how did you get to this page, art thou a thief?";
                      }
                  }
                  

                  What if someone goes to deleted.html directly? Nothing is going to happen, but you can add more security with sessions, ACL and so forth.

                  For a more pleasanter experience, post the form with AJAX and have a success notification pop up, and you can add some cosmetics to the deleted resource title, grey out the button, or $(this).remove() them altogether.
                  http://api.jquery.com/jquery.post/
                  http://stackoverflow.com/questions/13212882/how-to-return-php-variables-on-success-ajax-jquery-post [ed. note: donshakespeare last edited this post 11 years, 9 months ago.]
                    TinymceWrapper: Complete back/frontend content solution.
                    Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                    5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                    • 40088
                    • 708 Posts
                    @donshakespeare Very nice. You are da Man.

                    A couple things:

                    1. When I paste the snippet into the Ace editor I get an error on line 13, "unexpected "="”.
                    2. My resource isn't being deleted. I get the success message but that's it.
                    Also. I tried to set the form to submit to itself (instead of redirecting) but that isn't working for me either.

                    The link to the AJAX stuff looks interesting. I might have to try that if/when I get this other stuff working.
                      Todd
                      • 42562
                      • 1,145 Posts
                      Sorry, I got carried away, I thought echo was a variable.
                      Remove the equal to sign after the echo.
                      echo = "Seriously, how..."

                      I have updated the code.
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.