How can I obtain $current_user  information through my after_ui_frame logic hook in  Sugarcrm 7.1.5?

I am currently trying to get functionality developed on Sugarcrm 6.7 working on Sugarcrm 7.1.5. I am using an after_ui_frame logic hook to trigger a function in a custom class which is currently located in custom/includes. In this function I use the global $current_user to check whether the user is still logged in (check whether the user_hash is available) and to obtain the eapmBean from a connecter which contains login information. However, the $current_user global does not contain an user id or name that is required.  So my question is how to solve this problem; is the way to obtain current user information changed or is there a problem with my approach?

Also in Sugarcrm 6.7 I used the $_SESSION variable to store additional information about an external login performed to another system. However, this variable is not initialized anymore. So I'm wondering whether it is still used in Sugarcrm or that I can use other strategies to add information to a users' session.

Your help is greatly appreciated!

  • I have done some extra research: In classes like for example the Lead class of the Leads module the current_user global shows the information for the currently logged in user. I use the  after_ui_frame Application hook on all modules (so in the custom/modules/logic_hooks.php file), so therefore I have to use the $current_user global because this type of logic hooks do not supply the $bean variable. So now it looks to me that this current_user global is somehow protected more or I'm now outside some required context.
    So I'm hoping that someone has the answer for me. Thanks in advance!
  • You know, that this logic_hook is only applicable for modules in backward compatibility mode? (see developer guide)
    So perhaps you should change the design of your custom code to work in a view which is added in a custom layout. In the js-controler of such a view you could get the current user info by calling the new REST function GET .../me , or directly from the js-controler by 

    App.api.call('read', App.api.buildURL('/me'), null,    {    success: _.bind(function(o) {                        console.log(o);                }, this)    }  );

    This call writes to the console log something like:

    object {current_user: Object}

    1. current_user: Object
      1. _hash: "05c73cd06156759d9935b8ad9ec52a19"
      2. acl: Object
      3. full_name: "Harald Kuske"
      4. id: "1"
      5. is_manager: true
      6. is_password_expired: false
      7. is_top_level_manager: true
      8. module_list: Array[24]
      9. my_teams: Array[10]
      10. password_expired_message: ""
      11. picture: "b8c00ca6-ce49-0c13-5d09-528cfd143c80"
      12. preferences: Object
      13. reports_to_id: ""
      14. reports_to_name: ""
      15. show_wizard: false
      16. type: "admin"
      17. user_name: "admin"
      18. __proto__: Object
    2. __proto__: Object
      ...
    Just try it in the Debugger of Chrome or Firefox.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Thanks for your reply! So does that mean that eventually these hooks are not used anymore? Because then functionality will be lost.

    So I made a workaround by extending some views and include the script files there. So then I can just call the CurrentUser API for the correct information.
  • Yes, that is the right direction for Sugar 7

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • Works but after a little fiddling around, it appears you can access the current user without making a GET call to the db.  Open a chrome developer tools window and type into the console:
    console.log(App.user); 
    And you'll get the current user; App.user.attributeshas the info.  I verified this is also the case within a controller via "app" which is true.  So you can access it via the global object "App" or in the passed variable in the controller "app".  If this is not the correct way to get the current user, please let me know.  --edit-- I posted this comment before reading your title.  I just remember the answer and quickly came back to comment, so I'm sure I'm pointing out the obvious.  :-)  So the real question is: is this a satisfying way to retrieve the current user without an API call to the db?