Permalink
Browse files

Adds premoderation

  • Loading branch information...
1 parent 2b95da2 commit 4a6921fbebda4cbb8070834698713c6d21cbe778 @linc linc committed Aug 29, 2012
@@ -890,6 +890,13 @@ public function Comment($Comment) {
if ($Spam)
return SPAM;
+ // Check for approval
+ $ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
+ if ($ApprovalRequired) {
+ LogModel::Insert('Moderate', 'ActivityComment', $Comment);
+ return UNAPPROVED;
+ }
+
$ID = $this->SQL->Insert('ActivityComment', $Comment);
if ($ID) {
@@ -1156,9 +1163,17 @@ public function Save($Data, $Preference = FALSE, $Options = array()) {
TouchValue('DateUpdated', $Activity, $Activity['DateInserted']);
if (GetValue('CheckSpam', $Options)) {
- $Spam = SpamModel::IsSpam('Activity', $Activity);
+ // Check for spam
+ $Spam = SpamModel::IsSpam('Activity', $Activity);
if ($Spam)
return SPAM;
+
+ // Check for approval
+ $ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
+ if ($ApprovalRequired) {
+ LogModel::Insert('Moderate', 'Activity', $Comment);
+ return UNAPPROVED;
+ }
}
$ActivityID = $this->SQL->Insert('Activity', $Activity);
@@ -283,6 +283,7 @@ public static function Insert($Operation, $RecordType, $Data, $Options = array()
'InsertIPAddress' => $InsertIPAddress,
'DateInserted' => Gdn_Format::ToDateTime(),
'ParentRecordID' => $ParentRecordID,
+ 'CategoryID' => self::_LogValue($Data, 'CategoryID'),
'OtherUserIDs' => implode(',', GetValue('OtherUserIDs', $Options, array())),
'Data' => serialize($Data)
);
@@ -591,6 +591,7 @@
->Column('OtherUserIDs', 'varchar(255)', NULL)
->Column('DateUpdated', 'datetime', NULL)
->Column('ParentRecordID', 'int', NULL, 'index')
+ ->Column('CategoryID', 'int', NULL, 'key')
->Column('Data', 'mediumtext', NULL) // the data from the record.
->Column('CountGroup', 'int', NULL)
->Engine('InnoDB')
@@ -183,8 +183,8 @@ public function Discussion($CategoryID = '') {
if ($DraftID > 0)
$this->DraftModel->Delete($DraftID);
}
- if ($DiscussionID == SPAM) {
- $this->StatusMessage = T('Your post has been flagged for moderation.');
+ if ($DiscussionID == SPAM || $DiscussionID == UNAPPROVED) {
+ $this->StatusMessage = T('DiscussionRequiresApprovalStatus', 'Your discussion will appear after it is approved.');
$this->Render('Spam');
return;
}
@@ -507,8 +507,8 @@ public function Comment($DiscussionID = '') {
$this->EventArguments['Discussion'] = $Discussion;
$this->EventArguments['Comment'] = $Comment;
$this->FireEvent('AfterCommentSave');
- } elseif ($CommentID === SPAM) {
- $this->StatusMessage = T('Your post has been flagged for moderation.');
+ } elseif ($CommentID === SPAM || $CommentID === UNAPPROVED) {
+ $this->StatusMessage = T('CommentRequiresApprovalStatus', 'Your comment will appear after it is approved.');
}
$this->Form->SetValidationResults($this->CommentModel->ValidationResults());
@@ -785,19 +785,25 @@ public function Save($FormPostValues) {
if (!GetValue('Format', $Fields))
$Fields['Format'] = Gdn::Config('Garden.InputFormatter', '');
- // Check for spam.
+ // Check for spam
$Spam = SpamModel::IsSpam('Comment', $Fields);
-
- if (!$Spam) {
- $CommentID = $this->SQL->Insert($this->Name, $Fields);
- $this->EventArguments['CommentID'] = $CommentID;
- // IsNewDiscussion is passed when the first comment for new discussions are created.
- $this->EventArguments['IsNewDiscussion'] = GetValue('IsNewDiscussion', $FormPostValues);
-
- $this->FireEvent('AfterSaveComment');
- } else {
+ if ($Spam)
return SPAM;
+
+ // Check for approval
+ $ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
+ if ($ApprovalRequired) {
+ LogModel::Insert('Moderate', 'Comment', $Fields);
+ return UNAPPROVED;
}
+
+ // Create comment
+ $CommentID = $this->SQL->Insert($this->Name, $Fields);
+ $this->EventArguments['CommentID'] = $CommentID;
+
+ // IsNewDiscussion is passed when the first comment for new discussions are created.
+ $this->EventArguments['IsNewDiscussion'] = GetValue('IsNewDiscussion', $FormPostValues);
+ $this->FireEvent('AfterSaveComment');
}
}
}
@@ -1272,34 +1272,40 @@ public function Save($FormPostValues) {
// Inserting.
if (!GetValue('Format', $Fields))
$Fields['Format'] = C('Garden.InputFormatter', '');
-
- // Check for spam.
- $Spam = SpamModel::IsSpam('Discussion', $Fields);
// Clear the cache if necessary.
if (GetValue('Announce', $Fields)) {
$CacheKeys = array('Announcements');
$this->SQL->Cache($CacheKeys);
}
-
- if (!$Spam) {
- $DiscussionID = $this->SQL->Insert($this->Name, $Fields);
- $Fields['DiscussionID'] = $DiscussionID;
-
- // Update the cache.
- if ($DiscussionID && Gdn::Cache()->ActiveEnabled()) {
- $CategoryCache = array(
- 'LastDiscussionID' => $DiscussionID,
- 'LastCommentID' => NULL,
- 'LastTitle' => Gdn_Format::Text($Fields['Name']), // kluge so JoinUsers doesn't wipe this out.
- 'LastUserID' => $Fields['InsertUserID'],
- 'LastDateInserted' => $Fields['DateInserted'],
- 'LastUrl' => DiscussionUrl($Fields)
- );
- CategoryModel::SetCache($Fields['CategoryID'], $CategoryCache);
- }
- } else {
+
+ // Check for spam
+ $Spam = SpamModel::IsSpam('Discussion', $Fields);
+ if ($Spam)
return SPAM;
+
+ // Check for approval
+ $ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
+ if ($ApprovalRequired) {
+ LogModel::Insert('Moderate', 'Discussion', $Fields);
+ return UNAPPROVED;
+ }
+
+ // Create discussion
+ $DiscussionID = $this->SQL->Insert($this->Name, $Fields);
+ $Fields['DiscussionID'] = $DiscussionID;
+
+ // Update the cache.
+ if ($DiscussionID && Gdn::Cache()->ActiveEnabled()) {
+ $CategoryCache = array(
+ 'LastDiscussionID' => $DiscussionID,
+ 'LastCommentID' => NULL,
+ 'LastTitle' => Gdn_Format::Text($Fields['Name']), // kluge so JoinUsers doesn't wipe this out.
+ 'LastUserID' => $Fields['InsertUserID'],
+ 'LastDateInserted' => $Fields['DateInserted'],
+ 'LastUrl' => DiscussionUrl($Fields)
+ );
+ CategoryModel::SetCache($Fields['CategoryID'], $CategoryCache);
}
// Assign the new DiscussionID to the comment before saving.
@@ -248,7 +248,8 @@
// Define some global vanilla permissions.
$PermissionModel->Define(array(
'Vanilla.Settings.Manage',
- 'Vanilla.Categories.Manage'
+ 'Vanilla.Categories.Manage',
+ 'Vanilla.Approval.Require'
));
// Define some permissions for the Vanilla categories.
@@ -5,7 +5,11 @@
?>
<div class="Info">
<?php
-echo '<div>', T("Your post will appear once it's been approved."), '</div>';
+if ($this->RequestMethod == 'discussion')
+ $Message = T('DiscussionRequiresApproval', "Your discussion will appear after it is approved.");
+else
+ $Message = T('CommentRequiresApproval', "Your comment will appear after it is approved.");
+echo '<div>', $Message, '</div>';
if ($this->Data('DiscussionUrl'))
echo '<div>', sprintf(T('Click <a href="%s">here</a> to go back to the discussion.'), Url($this->Data('DiscussionUrl'))), '</div>';
View
@@ -59,5 +59,6 @@
define('E_USER_DEPRECATED', E_USER_WARNING);
define('SPAM', 'SPAM');
+define('UNAPPROVED', 'UNAPPROVED');
define('VANILLA_CONSTANTS', TRUE);
@@ -397,6 +397,15 @@ function CheckPermission($PermissionName) {
}
}
+// Negative permission check
+if (!function_exists('CheckRestriction')) {
+ function CheckRestriction($PermissionName) {
+ $Result = Gdn::Session()->CheckPermission($PermissionName);
+ $Unrestricted = Gdn::Session()->CheckPermission('Garden.Admin.Only');
+ return $Result && !$Unrestricted;
+ }
+}
+
// Smarty sux
if (!function_exists('MultiCheckPermission')) {
function MultiCheckPermission($PermissionName) {

0 comments on commit 4a6921f

Please sign in to comment.