We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43592
    • 97 Posts
    Hi Modx Forum members!

    My question is in dependence to my precurser, but a little bit different.

    I'm bulding a website with user profiles and the Login module. I also know "ressource groups"

    What I need is a solution for assignin resources to users, so f.e. that a user can create several events, update and delete them.
    But what I dont want is that a user can update events of other users in the same user group.

    It would be best I could assign those ressources automatically by registering or activating the user (via the Login Module)

    Is there any idea or post around?

    Thanx a lot,
    Stefan

    This question has been answered by multiple community members. See the first response.

      • 43592
      • 97 Posts
      As I understood so far this is possible with the "default ressource group" plugin from Bob Ray and this tutorial.
      http://bobsguides.com/user-specific-pages.html

      Every User has to have different ressource groups and has to be in a different user group.
      First thing does the plugin.

      The missing link by reading those tuts is how can I create new user groups on the fly by registering users via the Login Module.
      Maybe a prehook within a script. I did no scripts at all in modx so far sad

      Any ideas?
      • discuss.answer
        • 3749
        • 24,544 Posts
        I think it's possible to do it as you describe with a plugin attached to OnUserActivate, or with a postHook on the Register snippet, but it might be easier to use NewsPublisher.

        You can set things up so that logged-in users will see an "Edit" button only on their own page. When they click on it, it will launch Notify to let them edit the page and you choose which Resource fields show up in the form. A big plus for this method is that you don't have to customize the Manager for those users or mess with the MODX permission system.

        The only catch is that you have to create the user's page using one of the methods above (plugin or PostHook) and set the 'createdby' field to the user's ID, but you'd probably want to create the page that way anyway.

        You can also send the user to their page directly after they log in by altering the Login snippet tag.

        The code for a plugin attached to OnUserActivate is fairly simple. This example (untested) should create a page with the username as a title under a particular folder in the Resource Tree:

        <?php
        $parent = 12; /* set this to the ID of the parent folder */
        $userId = $user->get('id');
        
        $page = $modx->newObject('modResource');
        $pagetitle = $user->get('username');
        $page->set('createdby', $userId);
        $page->set('pagetitle', $pagetitle);
        $page->set('alias', $page->cleanAlias($pagetitle));
        $page->save();



        If you'd rather use the user's full name, I think it will work to replace this line:

        $pagetitle = $user->get('username');


        with this:

        $profile = $user->getOne('Profile');
        $pagetitle = '';
        if ($profile) {
            $pagetitle = $profile->get('fullname');
        }
        /* Fall back to username if fullname is empty */
        if (empty($pagetitle)) {
            $pagetitle = $user->get('username');
        }
        


          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
          • 43592
          • 97 Posts
          Thank you Ray for your answer!

          I think I understood so far and I have an additional question to NewsPublisher to find out whats best practice for my site.

          As I see NewsPublisher works if you have a ressource with a bunch of fields/TV's which you edit via an "Edit button".

          What I need is a menu for users to add, update and delete two different sets of (template-)resources. I would like to have an overview with kind of Quickstart Buttons like them from the Bert Oost plugin but that "user-page" you describe on NewsPublisher maybe also a good solution if I can link on to or create different "types" of ressources.

          So my further question is when I have multiple ressources to create and work on for users:
          Like a blog with several entrys or events to list.
          I had listed this so far under a parent in the ressource tree and summed it up later with getressources in the frontend and so on.

          Is the NewsPublisher also good in that or is this plugin more isolated on one bunch of fields which I can update frequently via one "Edit Button"?


          Thanks a lot!
          Stefan [ed. note: sspind last edited this post 8 years, 1 month ago.]
            • 3749
            • 24,544 Posts
            NP will edit any and all resource fields and TVs of a resource. You pick which ones are shown.

            It will only let you edit one resource at at time, but it's possible to create a menu of resources with an edit button next to each one's pagetitle.
              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
              • 43592
              • 97 Posts
              This Newspublisher is a pretty handsome tool ..

              .. please let me ask some more questions:

              1) Newspublisher create ressource works fine so long but I cannot save or see any new ressource in the ressource-tree - parentid 39 by submitting it? Is there something missing?

                [[!NewsPublisher?&show=`pagetitle,Kursart,Leitung,Bundesland,Land,Straße,PLZ,Ort,Beginn,Ende,Kursbeitrag,Kursunterlagen,Kursbeschreibung`
                &template=`15`
                      &initdatepicker=`1`
                      &rtcontent=`1`
                      &rtsummary=`1`
                      &parentid=`39`
                      &published=`1`
                      &captions=`Bundesland:Angaben zum Kursort:<br><br>Bundesland:`
                ]]
              


              1) How can I grant access to several user groups in the "Members"-area and other user groups not? I did check the allow_modx_tags - box in "NewsPublisherEditor Policy" according to the documents but this cant be all?

              3) How can I list createdby-Ressources in the Login.Homepage for editing? It might by something with "getressources" on the Login.Homepage?
              I did already add the [[!NpEditThisButton? &np_edit_id=`[[+id]]`]] in my chunks for getressources

              Thanks in advance!
                • 3749
                • 24,544 Posts
                Thanks for the kind words.

                You should be able to see the resources in the tree either by reloading the Manager page, or (quicker) clicking on the refresh icon in the tree. If the resources are under a parent, you should be able to click on the refresh icon for just that folder.

                I don't understand question 1. Do you mean access to edit them in NewsPublisher, access to them in the Manager, or access to them in the front end?

                Setting allow_modx_tags has nothing to do with user access, and it's somewhat of a security vulnerability. It's no longer necessary as long as you use {{-style tags in the resource as you edit it in NewsPublisher. NP will translate any tags in the resource to that format when loading it and will translate them back to the standard MODX format when saving it.

                getResources will show resources created by a certain user. See the getResources docs, especially the &where property.





                  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
                  • 43592
                  • 97 Posts
                  Quote from: BobRay at Apr 06, 2016, 05:52 PM

                  I don't understand question 1. Do you mean access to edit them in NewsPublisher, access to them in the Manager, or access to them in the front end?

                  Dear Ray,
                  I mean access to create and edit them in the Login. - area with Newspublisher.
                  All Users who have access to the Login area are in the "Members"-group and this works already nicely.
                  Now I additionaly want to grant access to users of user group "Group3" or "Group4" to the Newspublisher to edit and create Ressources which are the same ressource group (Members). So users of other groups only may update their Profiles in the "Members" area.

                  Thanks in advance!!
                    • 43592
                    • 97 Posts
                    I think I solved the rights stuff by using the NewsPublisherEditor rights on the groups. (and remove the sessions;)

                    Still the Newspublisher button is not submitting. I did some simple jquery on it but this may not be the problem

                    $( document ).ready(function() {
                     $('#np_submit_button').val("Veranstaltung erstellen");
                     $('#newspublisherHeader').html("Veranstaltung erstellen");
                    });
                      • 3749
                      • 24,544 Posts
                      Remove the JS and see what happens.

                      Also, this code verifies that the form has been submitted:

                      $this->setPostback(isset($_POST['hidSubmit']) &&
                                  $_POST['hidSubmit'] == 'true');
                        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