Beispiel #1
0
/**
 * Sets the monitors of the specified issue
 *
 * <p>This functions performs access level checks and only performs operations which would
 * modify the existing monitors list.</p>
 *
 * @param integer $p_issue_id           The issue id to set the monitors for.
 * @param integer $p_requesting_user_id The user which requests the monitor change.
 * @param array   $p_monitors           An array of arrays with the <em>id</em> field set to the id
 *                                      of the users which should monitor this issue.
 * @return mixed
 */
function mci_issue_set_monitors($p_issue_id, $p_requesting_user_id, array $p_monitors)
{
    if (bug_is_readonly($p_issue_id)) {
        return mci_soap_fault_access_denied($p_requesting_user_id, 'Issue \'' . $p_issue_id . '\' is readonly');
    }
    # 1. get existing monitor ids
    $t_existing_monitor_ids = bug_get_monitors($p_issue_id);
    # 2. build new monitors ids
    $t_new_monitor_ids = array();
    foreach ($p_monitors as $t_monitor) {
        $t_monitor = SoapObjectsFactory::unwrapObject($t_monitor);
        $t_new_monitor_ids[] = $t_monitor['id'];
    }
    # 3. for each of the new monitor ids, add it if it does not already exist
    foreach ($t_new_monitor_ids as $t_user_id) {
        if ($p_requesting_user_id == $t_user_id) {
            if (!access_has_bug_level(config_get('monitor_bug_threshold'), $p_issue_id)) {
                continue;
            }
        } else {
            if (!access_has_bug_level(config_get('monitor_add_others_bug_threshold'), $p_issue_id)) {
                continue;
            }
        }
        if (in_array($t_user_id, $t_existing_monitor_ids)) {
            continue;
        }
        bug_monitor($p_issue_id, $t_user_id);
    }
    # 4. for each of the existing monitor ids, remove it if it is not found in the new monitor ids
    foreach ($t_existing_monitor_ids as $t_user_id) {
        if ($p_requesting_user_id == $t_user_id) {
            if (!access_has_bug_level(config_get('monitor_bug_threshold'), $p_issue_id)) {
                continue;
            }
        } else {
            if (!access_has_bug_level(config_get('monitor_delete_others_bug_threshold'), $p_issue_id)) {
                continue;
            }
        }
        if (in_array($t_user_id, $t_new_monitor_ids)) {
            continue;
        }
        bug_unmonitor($p_issue_id, $t_user_id);
    }
}
require_api('helper_api.php');
require_api('print_api.php');
require_api('user_api.php');
form_security_validate('bug_monitor_delete');
$f_bug_id = gpc_get_int('bug_id');
$t_bug = bug_get($f_bug_id, true);
$f_user_id = gpc_get_int('user_id', NO_USER);
$t_logged_in_user_id = auth_get_current_user_id();
if ($f_user_id === NO_USER) {
    $t_user_id = $t_logged_in_user_id;
} else {
    user_ensure_exists($f_user_id);
    $t_user_id = $f_user_id;
}
if (user_is_anonymous($t_user_id)) {
    trigger_error(ERROR_PROTECTED_ACCOUNT, E_USER_ERROR);
}
bug_ensure_exists($f_bug_id);
if ($t_bug->project_id != helper_get_current_project()) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}
if ($t_logged_in_user_id == $t_user_id) {
    access_ensure_bug_level(config_get('monitor_bug_threshold'), $f_bug_id);
} else {
    access_ensure_bug_level(config_get('monitor_delete_others_bug_threshold'), $f_bug_id);
}
bug_unmonitor($f_bug_id, $t_user_id);
form_security_purge('bug_monitor_delete');
print_successful_redirect_to_bug($f_bug_id);
/**
 * allows bug deletion :
 * delete the bug, bugtext, bugnote, and bugtexts selected
 * @param array p_bug_id integer representing bug id
 * @return bool (always true)
 * @access public
 */
function bug_delete($p_bug_id)
{
    $c_bug_id = (int) $p_bug_id;
    $t_bug_table = db_get_table('mantis_bug_table');
    $t_bug_text_table = db_get_table('mantis_bug_text_table');
    # call pre-deletion custom function
    helper_call_custom_function('issue_delete_validate', array($p_bug_id));
    # log deletion of bug
    history_log_event_special($p_bug_id, BUG_DELETED, bug_format_id($p_bug_id));
    email_bug_deleted($p_bug_id);
    # call post-deletion custom function.  We call this here to allow the custom function to access the details of the bug before
    # they are deleted from the database given it's id.  The other option would be to move this to the end of the function and
    # provide it with bug data rather than an id, but this will break backward compatibility.
    helper_call_custom_function('issue_delete_notify', array($p_bug_id));
    # Unmonitor bug for all users
    bug_unmonitor($p_bug_id, null);
    # Delete custom fields
    custom_field_delete_all_values($p_bug_id);
    # Delete bugnotes
    bugnote_delete_all($p_bug_id);
    # Delete all sponsorships
    sponsorship_delete_all($p_bug_id);
    # MASC RELATIONSHIP
    # we delete relationships even if the feature is currently off.
    relationship_delete_all($p_bug_id);
    # MASC RELATIONSHIP
    # Delete files
    file_delete_attachments($p_bug_id);
    # Detach tags
    tag_bug_detach_all($p_bug_id, false);
    # Delete the bug history
    history_delete($p_bug_id);
    # Delete bug info revisions
    bug_revision_delete($p_bug_id);
    # Delete the bugnote text
    $t_bug_text_id = bug_get_field($p_bug_id, 'bug_text_id');
    $query = "DELETE FROM {$t_bug_text_table}\n\t\t\t\t  WHERE id=" . db_param();
    db_query_bound($query, array($t_bug_text_id));
    # Delete the bug entry
    $query = "DELETE FROM {$t_bug_table}\n\t\t\t\t  WHERE id=" . db_param();
    db_query_bound($query, array($c_bug_id));
    bug_clear_cache($p_bug_id);
    bug_text_clear_cache($p_bug_id);
    # db_query errors on failure so:
    return true;
}
Beispiel #4
0
/**
 * Sets the monitors of the specified issue
 * 
 * <p>This functions performs access level checks and only performs operations which would
 * modify the existing monitors list.</p>
 * 
 * @param int $p_issue_id the issue id to set the monitors for
 * @param int $p_user_id the user which requests the monitor change
 * @param array $p_monitors An array of arrays with the <em>id</em> field set to the id 
 *  of the users which should monitor this issue.
 */
function mci_issue_set_monitors( $p_issue_id , $p_user_id, $p_monitors ) {
    
    $t_existing_monitors = bug_get_monitors( $p_issue_id );

    $t_monitors = array();
    foreach ( $p_monitors as $t_monitor ) 
        $t_monitors[] = $t_monitor['id'];
    
    foreach ( $t_monitors as $t_user_id ) {
        
    	if ( $p_user_id == $t_user_id ) {
    		if ( ! access_has_bug_level( config_get( 'monitor_bug_threshold' ), $p_issue_id ) )
    		    continue;
	    } else {
	    	if ( !access_has_bug_level( config_get( 'monitor_add_others_bug_threshold' ), $p_issue_id ) )
	    	    continue;
	    }
	        
       if ( in_array( $p_user_id, $t_existing_monitors) )
           continue;
	        
        bug_monitor( $p_issue_id, $t_user_id);
    }
    
    foreach ( $t_existing_monitors as $t_user_id ) {

    	if ( $p_user_id == $t_user_id ) {
    		if ( ! access_has_bug_level( config_get( 'monitor_bug_threshold' ), $p_issue_id ) )
    		    continue;
	    } else {
	    	if ( !access_has_bug_level( config_get( 'monitor_delete_others_bug_threshold' ), $p_issue_id ) )
	    	    continue;
	    }
        
        if ( in_array( $p_user_id, $t_monitors) )
            continue;
            
        bug_unmonitor( $p_issue_id, $t_user_id);
    }
}
Beispiel #5
0
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------
# $Id: bug_monitor.php,v 1.28.16.1 2007-10-13 22:32:42 giallu Exp $
# --------------------------------------------------------
# This file turns monitoring on or off for a bug for the current user
require_once 'core.php';
$t_core_path = config_get('core_path');
require_once $t_core_path . 'bug_api.php';
# helper_ensure_post();
$f_bug_id = gpc_get_int('bug_id');
$t_bug = bug_get($f_bug_id, true);
if ($t_bug->project_id != helper_get_current_project()) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}
$f_action = gpc_get_string('action');
access_ensure_bug_level(config_get('monitor_bug_threshold'), $f_bug_id);
if ('delete' == $f_action) {
    bug_unmonitor($f_bug_id, auth_get_current_user_id());
} else {
    # should be 'add' but we have to account for other values
    bug_monitor($f_bug_id, auth_get_current_user_id());
}
print_successful_redirect_to_bug($f_bug_id);
/**
 * Sets the monitors of the specified issue
 *
 * <p>This functions performs access level checks and only performs operations which would
 * modify the existing monitors list.</p>
 *
 * @param int $p_issue_id the issue id to set the monitors for
 * @param int $p_user_id the user which requests the monitor change
 * @param array $p_monitors An array of arrays with the <em>id</em> field set to the id
 *  of the users which should monitor this issue.
 */
function mci_issue_set_monitors($p_issue_id, $p_user_id, $p_monitors)
{
    if (bug_is_readonly($p_issue_id)) {
        return mci_soap_fault_access_denied($p_user_id, "Issue '{$p_issue_id}' is readonly");
    }
    $t_existing_monitors = bug_get_monitors($p_issue_id);
    $t_monitors = array();
    foreach ($p_monitors as $t_monitor) {
        $t_monitors[] = $t_monitor['id'];
    }
    foreach ($t_monitors as $t_user_id) {
        if ($p_user_id == $t_user_id) {
            if (!access_has_bug_level(config_get('monitor_bug_threshold'), $p_issue_id)) {
                continue;
            }
        } else {
            if (!access_has_bug_level(config_get('monitor_add_others_bug_threshold'), $p_issue_id)) {
                continue;
            }
        }
        if (in_array($p_user_id, $t_existing_monitors)) {
            continue;
        }
        bug_monitor($p_issue_id, $t_user_id);
    }
    foreach ($t_existing_monitors as $t_user_id) {
        if ($p_user_id == $t_user_id) {
            if (!access_has_bug_level(config_get('monitor_bug_threshold'), $p_issue_id)) {
                continue;
            }
        } else {
            if (!access_has_bug_level(config_get('monitor_delete_others_bug_threshold'), $p_issue_id)) {
                continue;
            }
        }
        if (in_array($p_user_id, $t_monitors)) {
            continue;
        }
        bug_unmonitor($p_issue_id, $t_user_id);
    }
}
Beispiel #7
0
function bug_delete($p_bug_id)
{
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_bug_table = config_get('mantis_bug_table');
    $t_bug_text_table = config_get('mantis_bug_text_table');
    # log deletion of bug
    history_log_event_special($p_bug_id, BUG_DELETED, bug_format_id($p_bug_id));
    email_bug_deleted($p_bug_id);
    # Unmonitor bug for all users
    bug_unmonitor($p_bug_id, null);
    # Delete custom fields
    custom_field_delete_all_values($p_bug_id);
    # Delete bugnotes
    bugnote_delete_all($p_bug_id);
    # Delete all sponsorships
    sponsorship_delete(sponsorship_get_all_ids($p_bug_id));
    # MASC RELATIONSHIP
    # we delete relationships even if the feature is currently off.
    relationship_delete_all($p_bug_id);
    # MASC RELATIONSHIP
    # Delete files
    file_delete_attachments($p_bug_id);
    # Delete the bug history
    history_delete($p_bug_id);
    # Delete the bugnote text
    $t_bug_text_id = bug_get_field($p_bug_id, 'bug_text_id');
    $query = "DELETE FROM {$t_bug_text_table}\n\t\t\t\t  WHERE id='{$t_bug_text_id}'";
    db_query($query);
    # Delete the bug entry
    $query = "DELETE FROM {$t_bug_table}\n\t\t\t\t  WHERE id='{$c_bug_id}'";
    db_query($query);
    bug_clear_cache($p_bug_id);
    bug_text_clear_cache($p_bug_id);
    # db_query() errors on failure so:
    return true;
}