Results 1 to 6 of 6

Thread: Trigger for Default Team and Default Role

  1. #1
    whitty is offline Member
    Join Date
    Sep 2007
    Posts
    5

    Default Trigger for Default Team and Default Role

    Hi,

    I have recently installed SugarCRM 5.0 and am not very happy that there is no default role or default team to be specified for a new user. We use LDAP integration so it is increasingly difficult to keep track over who has what permissions. I have done some research and created the following trigger to set new users into my default role and would also like to change the default team for users to Global. Here is the trigger:

    delimiter |
    CREATE TRIGGER sugarcrm.new_user BEFORE INSERT ON sugarcrm.users
    FOR EACH ROW
    BEGIN
    set NEW.default_team=1;
    insert into sugarcrm.acl_roles_users values (uuid(), '198f140b-78bd-a24c-4074-48b748f172ab', NEW.id, current_timestamp, 0);
    end |

    The insert statement works and creates the user with out default role, however the set statement doesn't work for some reason. Has anyone accomplished this successfully or know what i am doing wrong?

    Thanks,

    Terry

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Trigger for Default Team and Default Role

    Hi Terry

    You can add two new rows into config table whose can specify the default team and default role.
    You can also create a logic_hook before save into Users module to assign the just created user to the default team and role.

    You can retrieve the default team and default role this way:

    PHP Code:
            require_once('modules/Administration/Administration.php');
            
    $administration = new Administration();
            
    $administration->retrieveSettings('MySettings'); 
    Just changing the MySettings by the category name you created.
    Let me know if you have any doubt

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    whitty is offline Member
    Join Date
    Sep 2007
    Posts
    5

    Default Re: Trigger for Default Team and Default Role

    Hi Andre,

    I'm not sure if I understand what you mean?
    I basically just want the easiest way to accomplish setting a default role and the default team of global.
    I have never done any php modification so I would need step-by-step instructions if at all possible.

    I am using Sugar Professional as well.

    Regards,

    Terry

  4. #4
    whitty is offline Member
    Join Date
    Sep 2007
    Posts
    5

    Default Re: Trigger for Default Team and Default Role

    Anyone figured out how to do this yet?

  5. #5
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Trigger for Default Team and Default Role

    In my installation the table users does not have a column "default_team".

    Is this a PRO or ENT feature?
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  6. #6
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Trigger for Default Team and Default Role

    Hi Kuske

    The default_team as Team module itself is a PRO/ENT feature.

    Hi Terry

    Run this sql script into your database using phpMyAdmin:

    HTML Code:
    INSERT INTO config (category, name, value) VALUES ('MySettings', 'default_team', 'id_of_team');
    INSERT INTO config (category, name, value) VALUES ('MySettings', 'default_role', 'id_of_role');
    Create the file custom/modules/Users/logic_hooks.php with this content:

    PHP Code:
    $hook_version 1;
    $hook_array = Array();

    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(1'setTeamRole''custom/modules/Users/UserHook.php','UserHook''setTeamRole'); 
    Create the file custom/modules/Users/UserHook.php with this content:

    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    UserHook {
        function 
    setTeamRole(&$focus$event$arguments) {
            global 
    $current_user;
            
            if(
    $focus->id == $current_user->id) {
                
    $query "SELECT * FROM users WHERE id = '{$focus->id}'";
                
    $result $focus->db->query($querytrue);

                if(
    $focus->db->getRowCount($result) == 0) {
                    require_once(
    'modules/Administration/Administration.php');

                    
    $administration = new Administration();
                    
    $administration->retrieveSettings('MySettings');
                    
    $default_team $administratin->settings['MySettings_default_team'];
                    
    $default_role $administratin->settings['MySettings_default_role'];
                    
    $focus->default_team $default_team;
                    
    $focus->load_relationship('teams');
                    
    $focus->teams->add($default_team);
                    
    $focus->load_relationship('aclroles');
                    
    $focus->aclroles->add($default_role);
                }
            }
        }

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Teams Open Source
    By dtokeefe in forum Downloads
    Replies: 191
    Last Post: 2010-04-07, 01:01 PM
  2. How to set default team?
    By Walling in forum Help
    Replies: 13
    Last Post: 2008-08-07, 10:42 PM
  3. Replies: 1
    Last Post: 2008-05-06, 07:47 AM
  4. Employee->User Conversion fails to create default team
    By richardk@idealogical.com in forum Help
    Replies: 0
    Last Post: 2006-07-26, 07:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •