Browse Source

Add some extra reinforcements for deleting locked topics and posts within them (fixes #1379)

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 10 years ago
parent
commit
8dd13177d6
2 changed files with 21 additions and 2 deletions
  1. 12 0
      Sources/Display.php
  2. 9 2
      Sources/RemoveTopic.php

+ 12 - 0
Sources/Display.php

@@ -1097,6 +1097,12 @@ function Display()
 		$context['can_move'] &= count($boards_allowed) > 1;
 	}
 
+	// If a topic is locked, you can't remove it unless it's yours and you locked it or you can lock_any
+	if ($topicinfo['locked'])
+	{
+		$context['can_delete'] &= (($topicinfo['locked'] == 1 && $context['user']['started']) || allowedTo('lock_any'));
+	}
+
 	// Cleanup all the permissions with extra stuff...
 	$context['can_mark_notify'] = !$context['user']['is_guest'];
 	$context['calendar_post'] &= !empty($modSettings['cal_enabled']);
@@ -1268,6 +1274,12 @@ function prepareDisplayContext($reset = false)
 	// Are you allowed to remove at least a single reply?
 	$context['can_remove_post'] |= allowedTo('delete_own') && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()) && $message['id_member'] == $user_info['id'];
 
+	// If the topic is locked, you might not be able to delete the post...
+	if ($context['is_locked'])
+	{
+		$context['can_remove_post'] &= ($context['user']['started'] && $context['is_locked'] == 1) || allowedTo('lock_any');
+	}
+
 	// If it couldn't load, or the user was a guest.... someday may be done with a guest table.
 	if (!loadMemberContext($message['id_member'], true))
 	{

+ 9 - 2
Sources/RemoveTopic.php

@@ -43,7 +43,7 @@ function RemoveTopic2()
 	removeDeleteConcurrence();
 
 	$request = $smcFunc['db_query']('', '
-		SELECT t.id_member_started, ms.subject, t.approved
+		SELECT t.id_member_started, ms.subject, t.approved, t.locked
 		FROM {db_prefix}topics AS t
 			INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
 		WHERE t.id_topic = {int:current_topic}
@@ -52,7 +52,7 @@ function RemoveTopic2()
 			'current_topic' => $topic,
 		)
 	);
-	list ($starter, $subject, $approved) = $smcFunc['db_fetch_row']($request);
+	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
 
 	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
@@ -64,6 +64,13 @@ function RemoveTopic2()
 	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
 		isAllowedTo('approve_posts');
 
+	// Ok, we got that far, but is it locked?
+	if ($locked)
+	{
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
+			fatal_lang_error('cannot_remove_locked', 'user');
+	}
+
 	// Notify people that this topic has been removed.
 	sendNotifications($topic, 'remove');