Skip to content

Commit

Permalink
Update bug_is_readonly to take a bug object
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis committed Sep 8, 2013
1 parent cf8893a commit 33bf8ed
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 38 deletions.
5 changes: 3 additions & 2 deletions bug_actiongroup_add_note_inc.php
Expand Up @@ -104,9 +104,10 @@ function action_add_note_validate( $p_bug_id ) {
}

$t_add_bugnote_threshold = config_get( 'add_bugnote_threshold' );
$t_bug_id = $p_bug_id;

if ( bug_is_readonly( $t_bug_id ) ) {
$t_bug = bug_get( $p_bug_id );

if ( bug_is_readonly( $t_bug ) ) {
return _( 'Issue is readonly.' );
}

Expand Down
4 changes: 3 additions & 1 deletion bug_actiongroup_update_product_build_inc.php
Expand Up @@ -68,7 +68,9 @@ function action_update_product_build_print_fields() {
function action_update_product_build_validate( $p_bug_id ) {
$t_bug_id = (int)$p_bug_id;

if ( bug_is_readonly( $t_bug_id ) ) {
$t_bug = bug_get( $t_bug_id );

if ( bug_is_readonly( $t_bug ) ) {
return _( 'Issue is readonly.' );
}

Expand Down
3 changes: 2 additions & 1 deletion bug_actiongroup_update_severity_inc.php
Expand Up @@ -74,7 +74,8 @@ function action_update_severity_validate( $p_bug_id ) {
$t_update_severity_threshold = config_get( 'update_bug_threshold' );
$t_bug_id = $p_bug_id;

if ( bug_is_readonly( $t_bug_id ) ) {
$t_bug = bug_get( $t_bug_id );
if ( bug_is_readonly( $t_bug ) ) {
return _( 'Issue is readonly.' );
}

Expand Down
4 changes: 3 additions & 1 deletion bug_relationship_add.php
Expand Up @@ -74,8 +74,10 @@
# the related bug exists...
bug_ensure_exists( $f_dest_bug_id );

$t_bug = bug_get( $f_src_bug_id );

# bug is not read-only...
if ( bug_is_readonly( $f_src_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_src_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bug_relationship_delete.php
Expand Up @@ -68,7 +68,7 @@
access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );

# bug is not read-only...
if ( bug_is_readonly( $f_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bug_reminder.php
Expand Up @@ -62,7 +62,7 @@

MantisContext::SetProject( $t_bug->project_id );

if ( bug_is_readonly( $f_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bug_reminder_page.php
Expand Up @@ -52,7 +52,7 @@

MantisContext::SetProject( $t_bug->project_id );

if ( bug_is_readonly( $f_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_bug_id );
}

Expand Down
3 changes: 2 additions & 1 deletion bug_report_page.php
Expand Up @@ -85,8 +85,9 @@
# master bug exists...
bug_ensure_exists( $f_master_bug_id );

$t_bug = bug_get( $f_master_bug_id );
# master bug is not read-only...
if ( bug_is_readonly( $f_master_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_master_bug_id );
}

Expand Down
3 changes: 2 additions & 1 deletion bug_sponsorship_list_view_inc.php
Expand Up @@ -54,12 +54,13 @@
#
# Determine whether the sponsorship section should be shown.
#
$t_bug = bug_get( $f_bug_id );

if ( ( config_get( 'enable_sponsorship' ) == ON ) && ( access_has_bug_level( config_get( 'view_sponsorship_total_threshold' ), $f_bug_id ) ) ) {
$t_sponsorship_ids = sponsorship_get_all_ids( $f_bug_id );

$t_sponsorships_exist = count( $t_sponsorship_ids ) > 0;
$t_can_sponsor = !bug_is_readonly( $f_bug_id ) && !user_is_anonymous( auth_get_current_user_id() );
$t_can_sponsor = !bug_is_readonly( $t_bug ) && !user_is_anonymous( auth_get_current_user_id() );

$t_show_sponsorships = $t_sponsorships_exist || $t_can_sponsor;
} else {
Expand Down
2 changes: 1 addition & 1 deletion bug_update.php
Expand Up @@ -74,7 +74,7 @@

# Check if the bug is in a read-only state and whether the current user has
# permission to update read-only bugs.
if ( bug_is_readonly( $f_bug_id ) ) {
if ( bug_is_readonly( $f_existing_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bug_update_page.php
Expand Up @@ -74,7 +74,7 @@

MantisContext::SetProject( $t_bug->project_id );

if ( bug_is_readonly( $f_bug_id ) ) {
if ( bug_is_readonly( $tpl_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $f_bug_id );
}

Expand Down
4 changes: 2 additions & 2 deletions bug_view_inc.php
Expand Up @@ -145,7 +145,7 @@
$tpl_history_link = '';
}

$tpl_show_reminder_link = !user_is_anonymous( auth_get_current_user_id() ) && !bug_is_readonly( $f_bug_id ) &&
$tpl_show_reminder_link = !user_is_anonymous( auth_get_current_user_id() ) && !bug_is_readonly( $tpl_bug ) &&
access_has_bug_level( config_get( 'bug_reminder_threshold' ), $f_bug_id );
$tpl_bug_reminder_link = 'bug_reminder_page.php?bug_id=' . $f_bug_id;

Expand Down Expand Up @@ -189,7 +189,7 @@
$tpl_show_monitor_box = !$tpl_force_readonly;
$tpl_show_relationships_box = !$tpl_force_readonly;
$tpl_show_sponsorships_box = config_get( 'enable_sponsorship' ) && access_has_bug_level( config_get( 'view_sponsorship_total_threshold' ), $f_bug_id );
$tpl_show_upload_form = !$tpl_force_readonly && !bug_is_readonly( $f_bug_id );
$tpl_show_upload_form = !$tpl_force_readonly && !bug_is_readonly( $tpl_bug );
$tpl_show_history = $f_history;
$tpl_show_profiles = config_get( 'enable_profiles' );
$tpl_show_platform = $tpl_show_profiles && in_array( 'platform', $t_fields );
Expand Down
2 changes: 1 addition & 1 deletion bugnote_add.php
Expand Up @@ -56,7 +56,7 @@

MantisContext::SetProject( $t_bug->project_id );

if ( bug_is_readonly( $t_bug->id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $t_bug->id );
}

Expand Down
4 changes: 3 additions & 1 deletion bugnote_add_inc.php
Expand Up @@ -48,8 +48,10 @@
require_api( 'helper_api.php' );
require_api( 'html_api.php' );

$t_bug = bug_get( $f_bug_id );

?>
<?php if ( ( !bug_is_readonly( $f_bug_id ) ) &&
<?php if ( ( !bug_is_readonly( $t_bug ) ) &&
( access_has_bug_level( config_get( 'add_bugnote_threshold' ), $f_bug_id ) ) ) { ?>
<?php # Bugnote Add Form BEGIN ?>
<a id="addbugnote"></a> <br />
Expand Down
2 changes: 1 addition & 1 deletion bugnote_edit_page.php
Expand Up @@ -83,7 +83,7 @@
}

# Check if the bug is readonly
if ( bug_is_readonly( $t_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $t_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bugnote_set_view_state.php
Expand Up @@ -62,7 +62,7 @@

# Check if the bug is readonly
$t_bug_id = bugnote_get_field( $f_bugnote_id, 'bug_id' );
if ( bug_is_readonly( $t_bug_id ) ) {
if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $t_bug_id );
}

Expand Down
4 changes: 3 additions & 1 deletion bugnote_update.php
Expand Up @@ -67,7 +67,9 @@

# Check if the bug is readonly
$t_bug_id = bugnote_get_field( $f_bugnote_id, 'bug_id' );
if ( bug_is_readonly( $t_bug_id ) ) {
$t_bug = bug_get( $t_bug_id );

if ( bug_is_readonly( $t_bug ) ) {
throw new MantisBT\Exception\Issue\IssueReadOnly( $t_bug_id );
}

Expand Down
2 changes: 1 addition & 1 deletion bugnote_view_inc.php
Expand Up @@ -184,7 +184,7 @@
<br /><div class="small bugnote-buttons">
<?php
# bug must be open to be editable
if ( !bug_is_readonly( $f_bug_id ) ) {
if ( !bug_is_readonly( $t_bug ) ) {

# check if the user can edit this bugnote
if ( $t_user_id == $t_bugnote->reporter_id ) {
Expand Down
8 changes: 4 additions & 4 deletions core/bug_api.php
Expand Up @@ -217,19 +217,19 @@ function bug_is_user_handler( $p_bug_id, $p_user_id ) {
* Check if the bug is readonly and shouldn't be modified
* For a bug to be readonly the status has to be >= bug_readonly_status_threshold and
* current user access level < update_readonly_bug_threshold.
* @param int $p_bug_id integer representing bug id
* @param MantisBug $p_bug MantisBug Object
* @return bool
* @access public
* @uses access_api.php
* @uses config_api.php
*/
function bug_is_readonly( $p_bug_id ) {
$t_status = bug_get_field( $p_bug_id, 'status' );
function bug_is_readonly( MantisBug $p_bug ) {
$t_status = $p_bug->status;
if( $t_status < config_get( 'bug_readonly_status_threshold' ) ) {
return false;
}

if( access_has_bug_level( config_get( 'update_readonly_bug_threshold' ), $p_bug_id ) ) {
if( access_has_bug_level( config_get( 'update_readonly_bug_threshold' ), $p_bug->id ) ) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion core/columns_api.php
Expand Up @@ -1024,7 +1024,7 @@ function print_column_plugin( $p_column_object, $p_bug, $p_columns_target = COLU
function print_column_edit( $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
echo '<td class="column-edit">';

if( !bug_is_readonly( $p_bug->id ) && access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug->id ) ) {
if( !bug_is_readonly( $p_bug ) && access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug->id ) ) {
echo '<a href="' . string_get_bug_update_url( $p_bug->id ) . '">';
echo '<img width="16" height="16" src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/update.png' );
echo '" alt="' . _( 'Edit' ) . '"';
Expand Down
3 changes: 2 additions & 1 deletion core/file_api.php
Expand Up @@ -163,7 +163,8 @@ function file_can_download_bug_attachments( $p_bug_id, $p_uploader_user_id = nul
* @return bool
*/
function file_can_delete_bug_attachments( $p_bug_id, $p_uploader_user_id = null ) {
if( bug_is_readonly( $p_bug_id ) ) {
$t_bug = bug_get( $p_bug_id );
if( bug_is_readonly( $t_bug ) ) {
return false;
}
$t_uploaded_by_me = auth_get_current_user_id() === $p_uploader_user_id;
Expand Down
13 changes: 6 additions & 7 deletions core/html_api.php
Expand Up @@ -1593,11 +1593,10 @@ function html_button_bug_delete( $p_bug ) {
* @return null
*/
function html_buttons_view_bug_page( $p_bug ) {
$p_bug_id = $p_bug->id;

$t_resolved = config_get( 'bug_resolved_status_threshold' );
$t_status = bug_get_field( $p_bug_id, 'status' );
$t_readonly = bug_is_readonly( $p_bug_id );
$t_status = $p_bug->status );
$t_readonly = bug_is_readonly( $p_bug );
$t_sticky = config_get( 'set_bug_sticky_threshold' );

echo '<table><tr class="vcenter">';
Expand All @@ -1623,7 +1622,7 @@ function html_buttons_view_bug_page( $p_bug ) {
# MONITOR/UNMONITOR button
if( !user_is_anonymous( auth_get_current_user_id() ) ) {
echo '<td class="center">';
if( user_is_monitoring_bug( auth_get_current_user_id(), $p_bug_id ) ) {
if( user_is_monitoring_bug( auth_get_current_user_id(), $p_bug->id ) ) {
html_button_bug_unmonitor( $p_bug );
} else {
html_button_bug_monitor( $p_bug );
Expand All @@ -1632,9 +1631,9 @@ function html_buttons_view_bug_page( $p_bug ) {
}

# STICK/UNSTICK button
if ( access_has_bug_level( $t_sticky, $p_bug_id ) ) {
if ( access_has_bug_level( $t_sticky, $p_bug->id ) ) {
echo '<td class="center">';
if ( !bug_get_field( $p_bug_id, 'sticky' ) ) {
if ( !$p_bug->sticky ) {
html_button_bug_stick( $p_bug );
} else {
html_button_bug_unstick( $p_bug );
Expand Down Expand Up @@ -1668,7 +1667,7 @@ function html_buttons_view_bug_page( $p_bug ) {
html_button_bug_delete( $p_bug );
echo '</td>';

helper_call_custom_function( 'print_bug_view_page_custom_buttons', array( $p_bug_id ) );
helper_call_custom_function( 'print_bug_view_page_custom_buttons', array( $p_bug->id ) );

echo '</tr></table>';
}
Expand Down
10 changes: 6 additions & 4 deletions core/relationship_api.php
Expand Up @@ -618,7 +618,8 @@ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false,
}

# add delete link if bug not read only and user has access level
if( !bug_is_readonly( $p_bug_id ) && !user_is_anonymous( auth_get_current_user_id() ) && ( $p_html_preview == false ) ) {
$t_bug2 = bug_get( $p_bug_id );
if( !bug_is_readonly( $t_bug2 ) && !user_is_anonymous( auth_get_current_user_id() ) && ( $p_html_preview == false ) ) {
if( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug_id ) ) {
$t_relationship_info .= ' [<a class="small" href="bug_relationship_delete.php?bug_id=' . $p_bug_id . '&amp;rel_id=' . $p_relationship->id . htmlspecialchars( form_security_param( 'bug_relationship_delete' ) ) . '">' . _( 'Delete' ) . '</a>]';
}
Expand Down Expand Up @@ -761,6 +762,7 @@ function relationship_list_box( $p_default_rel_type = -1, $p_select_name = "rel_
* @return null
*/
function relationship_view_box( $p_bug_id ) {
$t_bug = bug_get( $p_bug_id );
?>
<br/>

Expand All @@ -782,10 +784,10 @@ function relationship_view_box( $p_bug_id ) {
</tr>
<?php
# bug not read-only and user authenticated
if( !bug_is_readonly( $p_bug_id ) ) {
if( !bug_is_readonly( $p_bug ) ) {

# user access level at least updater
if( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug_id ) ) {
if( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug->id ) ) {
?>
<tr class="row-1">
<th class="category"><?php echo _( 'New relationship' )?></th>
Expand All @@ -803,7 +805,7 @@ function relationship_view_box( $p_bug_id ) {
}
?>
<tr>
<td colspan="2"><?php echo relationship_get_summary_html( $p_bug_id )?></td>
<td colspan="2"><?php echo relationship_get_summary_html( $p_bug->id )?></td>
</tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion my_view_inc.php
Expand Up @@ -251,7 +251,7 @@

echo '<br />';

if( !bug_is_readonly( $t_bug->id ) && access_has_bug_level( config_get( 'update_bug_threshold' ), $t_bug->id ) ) {
if( !bug_is_readonly( $t_bug ) && access_has_bug_level( config_get( 'update_bug_threshold' ), $t_bug->id ) ) {
echo '<a class="edit" href="' . string_get_bug_update_url( $t_bug->id ) . '"><img src="' . helper_mantis_url( 'themes/' . config_get( 'theme' ) . '/images/update.png' ) . '" alt="' . _( 'Edit' ) . '" /></a>';
}

Expand Down

0 comments on commit 33bf8ed

Please sign in to comment.