english/administrator/components/com_users/models/group.php
/**
	 * Method to save the form data.
	 *
	 * @param	array	The form data.
	 * @return	boolean	True on success.
	 * @since	1.6
	 */
Method to save the form data.
@param       array   The form data.
@return      boolean True on success.
Method to save the form data . @param array The form data . @return boolean True on success .
public function save($data)
	{
		JPluginHelper::importPlugin('user');
		$parentSuperAdmin = JAccess::checkGroup($data['parent_id'], 'core.admin');
		$rules = JAccess::getAssetRules('root.1')->getData('core.admin');
		$groupSuperAdmin = $rules['core.admin']->allow($data['id']);
		if ($parentSuperAdmin === false) {
			$groupSuperAdmin = false;
		}
		elseif ($parentSuperAdmin === true) {
			$groupSuperAdmin = ($groupSuperAdmin === false) ? false : true;
		}
		$iAmSuperAdmin	= JFactory::getUser()->authorise('core.admin');
        if ((!$iAmSuperAdmin) && ($groupSuperAdmin)) {
        	try
        	{
				throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
        	}
			catch (Exception $e)
			{
				$this->setError($e->getMessage());
				return false;
			}
		}
		if ($iAmSuperAdmin) {
						$myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'), false);
			if (in_array($data['id'], $myGroups)) {
								$otherGroups = array_diff($myGroups, array($data['id']));
				$otherSuperAdmin = false;
				foreach ($otherGroups as $otherGroup) {
					$otherSuperAdmin = ($otherSuperAdmin) ? $otherSuperAdmin : JAccess::checkGroup($otherGroup, 'core.admin');
				}
				if ((!$otherSuperAdmin) && (!$groupSuperAdmin)) {
					try
					{
						throw new Exception(JText::_('JLIB_USER_ERROR_CANNOT_DEMOTE_SELF'));
					}
					catch (Exception $e)
					{
						$this->setError($e->getMessage());
						return false;
					}
				}
			}
		}
		return parent::save($data);
	}
public function save ( $ data ) { JPluginHelper :: importPlugin ( 'user' ) ; $ parentSuperAdmin = JAccess :: checkGroup ( $ data [ 'parent_id' ] , 'core.admin' ) ; $ rules = JAccess :: getAssetRules ( 'root.1' ) -> getData ( 'core.admin' ) ; $ groupSuperAdmin = $ rules [ 'core.admin' ] -> allow ( $ data [ 'id' ] ) ; if ( $ parentSuperAdmin === false ) { $ groupSuperAdmin = false ; } elseif ( $ parentSuperAdmin === true ) { $ groupSuperAdmin = ( $ groupSuperAdmin === false ) ? false : true ; } $ iAmSuperAdmin = JFactory :: getUser ( ) -> authorise ( 'core.admin' ) ; if ( ( ! $ iAmSuperAdmin ) && ( $ groupSuperAdmin ) ) { try { throw new Exception ( JText :: _ ( 'JLIB_USER_ERROR_NOT_SUPERADMIN' ) ) ; } catch ( Exception $ e ) { $ this -> setError ( $ e -> getMessage ( ) ) ; return false ; } } if ( $ iAmSuperAdmin ) { $ myGroups = JAccess :: getGroupsByUser ( JFactory :: getUser ( ) -> get ( 'id' ) , false ) ; if ( in_array ( $ data [ 'id' ] , $ myGroups ) ) { $ otherGroups = array_diff ( $ myGroups , array ( $ data [ 'id' ] ) ) ; $ otherSuperAdmin = false ; foreach ( $ otherGroups as $ otherGroup ) { $ otherSuperAdmin = ( $ otherSuperAdmin ) ? $ otherSuperAdmin : JAccess :: checkGroup ( $ otherGroup , 'core.admin' ) ; } if ( ( ! $ otherSuperAdmin ) && ( ! $ groupSuperAdmin ) ) { try { throw new Exception ( JText :: _ ( 'JLIB_USER_ERROR_CANNOT_DEMOTE_SELF' ) ) ; } catch ( Exception $ e ) { $ this -> setError ( $ e -> getMessage ( ) ) ; return false ; } } } } return parent :: save ( $ data ) ; }
Method to save the form data.
Method to save the form data .
// Include the content plugins for events. // Check the super admin permissions for group // We get the parent group permissions and then check the group permissions manually // We have to calculate the group permissions manually because we haven't saved the group yet // Get core.admin rules from the root asset // Get the value for the current group (will be true (allowed), false (denied), or null (inherit) // We only need to change the $groupSuperAdmin if the parent is true or false. Otherwise, the value set in the rule takes effect. // If parent is false (Denied), effective value will always be false // If parent is true (allowed), group is true unless explicitly set to false // Check for non-super admin trying to save with super admin group // Check for super-admin changing self to be non-super-admin // First, are we a super admin> // Next, are we a member of the current group?
 // Now, would we have super admin permissions without the current group?
 // If we would not otherwise have super admin permissions // and the current group does not have super admin permissions, throw an exception // Proceed with the save