From ee9de5f83f9f45e9b55a42a300fe6db24a0f1784 Mon Sep 17 00:00:00 2001
From: Chris Fitch <cfitch@redcom.com>
Date: Tue, 18 Aug 2009 14:48:37 -0400
Subject: [PATCH] Make 'delete' and 'make private' buttons configurable


diff --git a/bugnote_delete.php b/bugnote_delete.php
index 5b76f23..03ddd08 100644
--- a/bugnote_delete.php
+++ b/bugnote_delete.php
@@ -48,7 +48,7 @@
 	$t_user_id = auth_get_current_user_id();
 	$t_reporter_id = bugnote_get_field( $f_bugnote_id, 'reporter_id' );
 
-	if ( ( $t_user_id != $t_reporter_id ) || ( OFF == config_get( 'bugnote_allow_user_edit_delete' ) ) ) {
+	if ( ( $t_user_id != $t_reporter_id ) || ( OFF == config_get( 'bugnote_allow_user_delete' ) ) ) {
 		access_ensure_bugnote_level( config_get( 'delete_bugnote_threshold' ), $f_bugnote_id );
 	}
 
diff --git a/bugnote_edit_page.php b/bugnote_edit_page.php
index 68853f2..4ea44a8 100644
--- a/bugnote_edit_page.php
+++ b/bugnote_edit_page.php
@@ -57,7 +57,7 @@
 	$t_reporter_id = bugnote_get_field( $f_bugnote_id, 'reporter_id' );
 
 	if ( ( $t_user_id != $t_reporter_id ) ||
-	 	( OFF == config_get( 'bugnote_allow_user_edit_delete' ) ) ) {
+	 	( OFF == config_get( 'bugnote_allow_user_edit' ) ) ) {
 		access_ensure_bugnote_level( config_get( 'update_bugnote_threshold' ), $f_bugnote_id );
 	}
 
diff --git a/bugnote_update.php b/bugnote_update.php
index dd7e279..cdbfd26 100644
--- a/bugnote_update.php
+++ b/bugnote_update.php
@@ -41,7 +41,7 @@
 	$t_user_id = auth_get_current_user_id();
 	$t_reporter_id = bugnote_get_field( $f_bugnote_id, 'reporter_id' );
 
-	if ( ( $t_user_id != $t_reporter_id ) || ( OFF == config_get( 'bugnote_allow_user_edit_delete' ) )) {
+	if ( ( $t_user_id != $t_reporter_id ) || ( OFF == config_get( 'bugnote_allow_user_edit' ) )) {
 		access_ensure_bugnote_level( config_get( 'update_bugnote_threshold' ), $f_bugnote_id );
 	}
 
diff --git a/bugnote_view_inc.php b/bugnote_view_inc.php
index 6d8b95a..f3c9ab5 100644
--- a/bugnote_view_inc.php
+++ b/bugnote_view_inc.php
@@ -138,12 +138,24 @@ $num_notes = count( $t_bugnotes );
 			if ( !bug_is_readonly( $f_bug_id ) ) {
 				$t_can_edit_note = false;
 				$t_can_delete_note = false;
+				$t_can_make_note_priv = false;
 
-				# admins and the bugnote creator can edit/delete this bugnote
-				if ( ( access_has_bug_level( config_get( 'manage_project_threshold' ), $f_bug_id ) ) ||
-					( ( $t_bugnote->reporter_id == $t_user_id ) && ( ON == config_get( 'bugnote_allow_user_edit_delete' ) ) ) ) {
+				# admins can edit/delete this bugnote
+				if ( ( access_has_bug_level( config_get( 'manage_project_threshold' ), $f_bug_id ) ) ) {
 					$t_can_edit_note = true;
 					$t_can_delete_note = true;
+					$t_can_make_note_priv = true;
+				# bugnote creator might be able to edit/delete this bugnote
+				} else if ( $t_bugnote->reporter_id == $t_user_id ) {
+					if ( ON == config_get( 'bugnote_allow_user_edit' ) ) {
+						$t_can_edit_note = true;
+					}
+					if ( ON == config_get( 'bugnote_allow_user_delete' ) ) {
+						$t_can_delete_note = true;
+					}
+					if ( ON == config_get( 'bugnote_allow_user_make_priv' ) ) {
+						$t_can_make_note_priv = true;
+					}
 				}
 
 				# users above update_bugnote_threshold should be able to edit this bugnote
@@ -157,8 +169,8 @@ $num_notes = count( $t_bugnotes );
 					print_button( 'bugnote_delete.php?bugnote_id='.$t_bugnote->id, lang_get( 'delete_link' ) );
 				}
 
-				# users with access to both update and change view status (or the bugnote author) can change public/private status
-				if ( $t_can_edit_note || ( access_has_bug_level( config_get( 'update_bugnote_threshold' ), $f_bug_id ) &&
+				# users with access to both update and change view status (or the bugnote author if allowed) can change public/private status
+				if ( $t_can_make_note_priv || ( access_has_bug_level( config_get( 'update_bugnote_threshold' ), $f_bug_id ) &&
 					access_has_bug_level( config_get( 'change_view_status_threshold' ), $f_bug_id ) ) ) {
 					if ( VS_PRIVATE == $t_bugnote->view_state ) {
 						echo " ";
diff --git a/config_defaults_inc.php b/config_defaults_inc.php
index df10831..f0c812f 100644
--- a/config_defaults_inc.php
+++ b/config_defaults_inc.php
@@ -2409,10 +2409,22 @@
 	$g_delete_bugnote_threshold = '%delete_bug_threshold%';
 
 	/**
-	 * Are users allowed to change and delete their own bugnotes?
-	 * @global int $g_bugnote_allow_user_edit_delete
+	 * Are users allowed to change their own bugnotes?
+	 * @global int $g_bugnote_allow_user_edit
 	 */
-	$g_bugnote_allow_user_edit_delete = ON;
+	$g_bugnote_allow_user_edit = ON;
+
+	/**
+	 * Are users allowed to delete their own bugnotes?
+	 * @global int $g_bugnote_allow_user_delete
+	 */
+	$g_bugnote_allow_user_delete = ON;
+
+	/**
+	 * Are users allowed to change the view status of their own bugnotes?
+	 * @global int $g_bugnote_allow_user_make_priv
+	 */
+	$g_bugnote_allow_user_make_priv = ON;
 
 	/**
 	 * Move bug threshold
diff --git a/lang/strings_english.txt b/lang/strings_english.txt
index c65951d..8963b57 100644
--- a/lang/strings_english.txt
+++ b/lang/strings_english.txt
@@ -847,6 +847,8 @@ $s_allow_reporter_close = 'Allow Reporter to close Issue';
 $s_allow_reporter_reopen = 'Allow Reporter to re-open Issue';
 $s_set_status_assigned = 'Set status on assignment of Handler';
 $s_allow_user_edit = 'Allow user to edit their own issue notes';
+$s_allow_user_delete = 'Allow user to delete their own issue notes';
+$s_allow_user_make_priv = 'Allow user to make their own issue notes private';
 $s_limit_access = 'Limit reporter\'s access to their own issues';
 $s_submit_status = 'Status to which a new issue is set';
 $s_assigned_status = 'Status to set auto-assigned issues to';
diff --git a/manage_config_work_threshold_page.php b/manage_config_work_threshold_page.php
index aec9a8d..d531cc6 100644
--- a/manage_config_work_threshold_page.php
+++ b/manage_config_work_threshold_page.php
@@ -301,7 +301,9 @@
 	get_section_begin_mcwt( lang_get( 'notes' ) );
 	get_capability_row( lang_get( 'add_notes' ), 'add_bugnote_threshold' );
 	get_capability_row( lang_get( 'update_notes' ), 'update_bugnote_threshold' );
-    get_capability_boolean( lang_get( 'allow_user_edit' ), 'bugnote_allow_user_edit_delete' );
+    get_capability_boolean( lang_get( 'allow_user_edit' ), 'bugnote_allow_user_edit' );
+    get_capability_boolean( lang_get( 'allow_user_delete' ), 'bugnote_allow_user_delete' );
+    get_capability_boolean( lang_get( 'allow_user_make_priv' ), 'bugnote_allow_user_make_priv' );
 	get_capability_row( lang_get( 'delete_note' ), 'delete_bugnote_threshold' );
 	get_capability_row( lang_get( 'view_private_notes' ), 'private_bugnote_threshold' );
 	get_section_end();
diff --git a/manage_config_work_threshold_set.php b/manage_config_work_threshold_set.php
index bf6e87b..1dc4bd5 100644
--- a/manage_config_work_threshold_set.php
+++ b/manage_config_work_threshold_set.php
@@ -144,7 +144,9 @@
 	# Notes
 	set_capability_row( 'add_bugnote_threshold' );
 	set_capability_row( 'update_bugnote_threshold' );
-    set_capability_boolean( 'bugnote_allow_user_edit_delete' );
+    set_capability_boolean( 'bugnote_allow_user_edit' );
+    set_capability_boolean( 'bugnote_allow_user_delete' );
+    set_capability_boolean( 'bugnote_allow_user_make_priv' );
 	set_capability_row( 'delete_bugnote_threshold' );
 	set_capability_row( 'private_bugnote_threshold' );
 
-- 
1.6.0.4

