Created
November 19, 2013 18:54
-
-
Save sugarhqi/7550486 to your computer and use it in GitHub Desktop.
Bug65792: Add the ability to allow the option of Default Team to be set to Private upon User import/creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
/********************************************************************************* | |
* The contents of this file are subject to the SugarCRM Master Subscription | |
* Agreement (""License"") which can be viewed at | |
* http://www.sugarcrm.com/crm/master-subscription-agreement | |
* By installing or using this file, You have unconditionally agreed to the | |
* terms and conditions of the License, and You may not use this file except in | |
* compliance with the License. Under the terms of the license, You shall not, | |
* among other things: 1) sublicense, resell, rent, lease, redistribute, assign | |
* or otherwise transfer Your rights to the Software, and 2) use the Software | |
* for timesharing or service bureau purposes such as hosting the Software for | |
* commercial gain and/or for the benefit of a third party. Use of the Software | |
* may be subject to applicable fees and any use of the Software without first | |
* paying applicable fees is strictly prohibited. You do not have the right to | |
* remove SugarCRM copyrights from the source code or user interface. | |
* | |
* All copies of the Covered Code must include on each user interface screen: | |
* (i) the ""Powered by SugarCRM"" logo and | |
* (ii) the SugarCRM copyright notice | |
* in the same form as they appear in the distribution. See full license for | |
* requirements. | |
* | |
* Your Warranty, Limitations of liability and Indemnity are expressly stated | |
* in the License. Please refer to the License for the specific language | |
* governing these rights and limitations under the License. Portions created | |
* by SugarCRM are Copyright (C) 2004-2012 SugarCRM, Inc.; All Rights Reserved. | |
********************************************************************************/ | |
require_once('modules/Teams/Team.php'); | |
class DefaultTeam | |
{ | |
/** | |
* This method creates the private team for a new user and makes it default. | |
* Uncomment line 46, 47 to add this user to the global team. | |
*/ | |
public function new_user_created(&$user, $event, $arguments) | |
{ | |
// new user only | |
if ($user->module_dir == 'Users' && empty($user->teams)) { | |
global $current_language, $dictionary; | |
$mod_strings = return_module_language($current_language, 'Users'); | |
$team = new Team(); | |
$team->field_defs = $dictionary[$team->object_name]['fields']; | |
// uncomment the following two lines to add the user to the global team. | |
//$team->retrieve($team->global_team); | |
//$team->add_user_to_team($user->id); | |
// create private team | |
$team_id = $user->getPrivateTeamID(); | |
if (empty($team_id)) { | |
Team::set_team_name_from_user($team, $user); | |
$description = "{$mod_strings['LBL_PRIVATE_TEAM_FOR']} {$user->user_name}"; | |
$team_id = $team->create_team($user->first_name, $description, create_guid(), 1, $user->last_name, $user->id); | |
} | |
$team->retrieve($team_id); | |
$team->add_user_to_team($user->id); | |
$user->default_team = $team->id; | |
$user->team_id = $team->id; | |
// set $user->teams | |
$user->load_relationship('teams'); | |
$user->teams->replace(array($team->id), array(), false); | |
// tell TeamSetLink::save() not to add assigned_user's private team | |
$GLOBALS['sugar_config']['disable_team_access_check'] = true; | |
// tell User::save() not to do this again | |
$user->team_exists = true; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Do not store anything in this file that is not part of the array or the hook version. This file will | |
// be automatically rebuilt in the future. | |
$hook_version = 1; | |
$hook_array = array(); | |
// position, file, function | |
$hook_array['before_save'] = array(); | |
$hook_array['before_save'][] = array(1, 'new_user_created', 'custom/modules/Users/DefaultTeam.php', 'DefaultTeam', 'new_user_created'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment