예제 #1
0
 /**
  * Pre-save function to check for conflicting usernames and to make
  * sure some properties are set
  * 
  * @param boolean $is_new Whether this is a new user object
  */
 protected function _preSave($is_new)
 {
     parent::_preSave($is_new);
     $compare_user = self::getByUsername($this->getUsername());
     if ($compare_user instanceof TBGUser && $compare_user->getID() && $compare_user->getID() != $this->getID()) {
         throw new Exception(TBGContext::getI18n()->__('This username already exists'));
     }
     if ($is_new) {
         // In case the postsave event isn't processed we automatically enable the user
         // since we can't be sure that an activation email has been sent out
         $this->setEnabled();
         $this->setActivated();
     }
     if (!$this->_realname) {
         $this->_realname = $this->_username;
     }
     if (!$this->_buddyname) {
         $this->_buddyname = $this->_username;
     }
     if (is_object($this->_timezone)) {
         $this->_timezone = $this->_timezone->getName();
     }
     if ($is_new && $this->_group_id === null) {
         $this->setGroup(TBGSettings::getDefaultGroup());
     }
     if ($this->_deleted) {
         try {
             if ($this->getGroup() instanceof TBGGroup) {
                 $this->getGroup()->removeMember($this);
             }
         } catch (Exception $e) {
         }
         $this->_group_id = null;
         $this->_buddyname = $this->_username;
         $this->_username = '';
         TBGTeamMembersTable::getTable()->clearTeamsByUserID($this->getID());
         TBGClientMembersTable::getTable()->clearClientsByUserID($this->getID());
         TBGUserScopesTable::getTable()->clearUserScopes($this->getID());
     }
 }
예제 #2
0
 /**
  * Set issue poster
  * 
  * @param TBGIdentifiableClass $poster The user/team you want to have posted the issue
  */
 public function setPostedBy(TBGIdentifiableClass $poster)
 {
     $this->_addChangedProperty('_posted_by', $poster->getID());
 }
 /**
  * Set an identifiable field
  * 
  * @param TBGIdentifiableClass $identifiable
  * @param string $field
  */
 protected function _setIdentifiable(TBGIdentifiableClass $identifiable, $field)
 {
     $type_field = "{$field}_type";
     $this->{$field} = $identifiable;
     $this->{$type_field} = $identifiable->getType();
     $this->applyInitialPermissionSet($identifiable, $field);
 }
예제 #4
0
 public function removeAssignee(TBGIdentifiableClass $assignee)
 {
     $user_id = 0;
     $team_id = 0;
     if ($assignee instanceof TBGUser) {
         $user_id = $assignee->getID();
         TBGProjectAssignedUsersTable::getTable()->removeUserFromProject($this->getID(), $assignee->getID());
         foreach ($this->getAssignedUsers() as $user) {
             if ($user->getID() == $user_id) {
                 return;
             }
         }
     } else {
         $team_id = $assignee->getID();
         TBGProjectAssignedTeamsTable::getTable()->removeTeamFromProject($this->getID(), $assignee->getID());
         foreach ($this->getAssignedTeams() as $team) {
             if ($team->getID() == $team_id) {
                 return;
             }
         }
     }
     TBGContext::removeAllPermissionsForCombination($user_id, 0, $team_id, $this->getID());
 }