Results 1 to 5 of 5

Thread: Assigning a Role Automatically to all new users

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Assigning a Role Automatically to all new users

    Hi,

    This seems like a basic feature that should be included but how can I assign a user to a role or role to a user automatically when I create a user or import them.

    I seems that when a user is create they should have the most restrictive access rights to start with.

    Is this something that I can do easily?

    Rgds
    Chris

  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: Assigning a Role Automatically to all new users

    Hi Chris

    You may create a logic_hook before_save for module Users.

    The logic_hook class may looks like that one:

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

    class 
    UserLogicHook {
        function 
    addInProfile(&$focus$event$arguments) {
            
    $query "SELECT id FROM users WHERE id = '{$focus->id}'";
            
    $result $focus->db->query($querytrue);

            if(
    $focus->db->getRowCount($result) == 0) {
                
    $query "SELECT id FROM acl_roles WHERE name = '<RoleName>'";
                
    $result $focus->db->query($querytrue);

                if(
    $focus->db->getRowCount($result) == 1) {
                    
    $row $focus->db->fetchByAssoc($result);
                    
    $focus->load_relationship('aclroles');
                    
    $focus->aclroles->add($row['id']);
        
                    require_once(
    'modules/ACL/install_actions.php');
                } else {
                    
    sugar_die("Role '<RoleName>' does not exist! Contact the system administrator");
                }
            }
        }
    }
    ?>
    Obviously you need to replace the <RoleName> by the desired Role Name.

    Regards
    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
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Assigning a Role Automatically to all new users

    Thanks, I will give it a go and see how I get on.

    Rgds
    Chris

  4. #4
    wramirez is offline Junior Member
    Join Date
    Feb 2009
    Posts
    3

    Lightbulb Re: Assigning a Role Automatically to all new users

    Hi, I was reading this post and it looks exactly like what I need.
    What I'd like to know is what file exactly do I need to add this code to?
    Thanks.

    -Waldo

  5. #5
    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: Assigning a Role Automatically to all new users

    Quote Originally Posted by wramirez View Post
    Hi, I was reading this post and it looks exactly like what I need.
    What I'd like to know is what file exactly do I need to add this code to?
    Thanks.

    -Waldo
    custom/modules/Users/UserLogicHook.php

    This file will be invoked by the logic hook.
    Please refer to sugarwiki to understand how to configure a logic hook.

    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. Assigning records to other Users
    By malcolmh in forum Feature Requests
    Replies: 2
    Last Post: 2006-12-20, 07:07 PM
  2. Emails - Assigning Users - Purpose?
    By yorkylad in forum Help
    Replies: 3
    Last Post: 2006-09-19, 12:13 PM
  3. Problem assigning a role to user
    By dshao in forum Help
    Replies: 3
    Last Post: 2006-03-29, 04:56 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
  •