Issue #10730: Use crypto_api for generating nonces and improve hashing
[mantis/radio.git] / bug_relationship_delete.php
blobde2ba89153bc0d3f084d81e823b5aef942d6dc10
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * To delete a relationship we need to ensure that:
19 * - User not anomymous
20 * - Source bug exists and is not in read-only state (peer bug could not exist...)
21 * - User that update the source bug and at least view the destination bug
22 * - Relationship must exist
24 * @package MantisBT
25 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
26 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
27 * @author Marcello Scata' <marcelloscata at users.sourceforge.net> ITALY
28 * @link http://www.mantisbt.org
30 * @uses core.php
31 * @uses access_api.php
32 * @uses bug_api.php
33 * @uses config_api.php
34 * @uses constant_inc.php
35 * @uses email_api.php
36 * @uses error_api.php
37 * @uses form_api.php
38 * @uses gpc_api.php
39 * @uses helper_api.php
40 * @uses history_api.php
41 * @uses lang_api.php
42 * @uses print_api.php
43 * @uses relationship_api.php
46 require_once( 'core.php' );
47 require_api( 'access_api.php' );
48 require_api( 'bug_api.php' );
49 require_api( 'config_api.php' );
50 require_api( 'constant_inc.php' );
51 require_api( 'email_api.php' );
52 require_api( 'error_api.php' );
53 require_api( 'form_api.php' );
54 require_api( 'gpc_api.php' );
55 require_api( 'helper_api.php' );
56 require_api( 'history_api.php' );
57 require_api( 'lang_api.php' );
58 require_api( 'print_api.php' );
59 require_api( 'relationship_api.php' );
61 form_security_validate( 'bug_relationship_delete' );
63 $f_rel_id = gpc_get_int( 'rel_id' );
64 $f_bug_id = gpc_get_int( 'bug_id' );
66 $t_bug = bug_get( $f_bug_id, true );
67 if( $t_bug->project_id != helper_get_current_project() ) {
68 # in case the current project is not the same project of the bug we are viewing...
69 # ... override the current project. This to avoid problems with categories and handlers lists etc.
70 $g_project_override = $t_bug->project_id;
73 # user has access to update the bug...
74 access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
76 # bug is not read-only...
77 if ( bug_is_readonly( $f_bug_id ) ) {
78 error_parameters( $f_bug_id );
79 trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
82 # retrieve the destination bug of the relationship
83 $t_dest_bug_id = relationship_get_linked_bug_id( $f_rel_id, $f_bug_id );
85 # user can access to the related bug at least as viewer, if it's exist...
86 if ( bug_exists( $t_dest_bug_id )) {
87 if ( !access_has_bug_level( VIEWER, $t_dest_bug_id ) ) {
88 error_parameters( $t_dest_bug_id );
89 trigger_error( ERROR_RELATIONSHIP_ACCESS_LEVEL_TO_DEST_BUG_TOO_LOW, ERROR );
93 helper_ensure_confirmed( lang_get( 'delete_relationship_sure_msg' ), lang_get( 'delete_relationship_button' ) );
95 $t_bug_relationship_data = relationship_get( $f_rel_id );
96 $t_rel_type = $t_bug_relationship_data->type;
98 # delete relationship from the DB
99 relationship_delete( $f_rel_id );
101 # update bug last updated (just for the src bug)
102 bug_update_date( $f_bug_id );
104 # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug
105 if ($f_bug_id == $t_bug_relationship_data->src_bug_id) {
106 $t_bug_rel_type = $t_rel_type;
107 $t_dest_bug_rel_type = relationship_get_complementary_type( $t_rel_type );
108 } else {
109 $t_bug_rel_type = relationship_get_complementary_type( $t_rel_type );
110 $t_dest_bug_rel_type = $t_rel_type;
113 # send email and update the history for the src issue
114 history_log_event_special( $f_bug_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_bug_id );
115 email_relationship_deleted( $f_bug_id, $t_dest_bug_id, $t_bug_rel_type );
117 if ( bug_exists( $t_dest_bug_id )) {
118 # send email and update the history for the dest issue
119 history_log_event_special( $t_dest_bug_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $f_bug_id );
120 email_relationship_deleted( $t_dest_bug_id, $f_bug_id, $t_dest_bug_rel_type );
123 form_security_purge( 'bug_relationship_delete' );
125 print_header_redirect_view( $f_bug_id );