Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: Ban User feature for Admins & Moderators #257

Merged
merged 13 commits into from
Sep 22, 2023
Merged
9 changes: 6 additions & 3 deletions Dnn.CommunityForums/App_LocalResources/Messages.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="[RESX:Email:Failed].Text" xml:space="preserve">
<value>We were unable to send your message. Please try again later.</value>
</data>
<data name="[RESX:Email:Sent].Text" xml:space="preserve">
<value>You message has been sent.</value>
<value>Your message has been sent.</value>
</data>
<data name="[RESX:Reply:Deleted].Text" xml:space="preserve">
<value>The reply has been deleted.</value>
Expand All @@ -147,4 +147,7 @@
<data name="[RESX:Topic:Submit].Text" xml:space="preserve">
<value>Your topic has been submitted.</value>
</data>
<data name="[RESX:User:Banned].Text" xml:space="preserve">
<value>User's content has been removed and the user has been unauthorized.</value>
</data>
</root>
12 changes: 9 additions & 3 deletions Dnn.CommunityForums/App_LocalResources/SharedResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@
<data name="[RESX:Attachments:Error].Text" xml:space="preserve">
<value>A server error has occured.</value>
</data>
<data name="[RESX:Confirm:Delete].Text" xml:space="preserve">
<data name="[RESX:Confirm:Delete].Text" xml:space="preserve">
<value>Are you sure you wish to delete this item?</value>
</data>
<data name="[RESX:Locked:Note].Text" xml:space="preserve">
Expand Down Expand Up @@ -846,8 +846,11 @@
<data name="[RESX:Approve].Text" xml:space="preserve">
<value>Approve</value>
</data>
<data name="[RESX:Delete].Text" xml:space="preserve">
<data name="[RESX:Delete].Text" xml:space="preserve">
<value>Delete</value>
</data>
<data name="[RESX:Ban].Text" xml:space="preserve">
<value>Ban</value>
</data>
<data name="[RESX:Edit].Text" xml:space="preserve">
<value>Edit</value>
Expand Down Expand Up @@ -1042,8 +1045,11 @@ From,
<data name="[RESX:Reason].Text" xml:space="preserve">
<value>Reason</value>
</data>
<data name="[RESX:ReportContent].Text" xml:space="preserve">
<data name="[RESX:ReportContent].Text" xml:space="preserve">
<value>Report Content</value>
</data>
<data name="[RESX:BanUser].Text" xml:space="preserve">
<value>Ban User (Remove Content and Unauthorize User)</value>
</data>
<data name="[RESX:Error:FloodControl].Text" xml:space="preserve">
<value>You must wait at least {0} seconds between posts</value>
Expand Down
39 changes: 39 additions & 0 deletions Dnn.CommunityForums/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Community Forums
// Copyright (c) 2013-2021
// by DNN Community
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
//
using System.Diagnostics.Contracts;

namespace DotNetNuke.Modules.ActiveForums.Controllers
{
internal static class UserController
{
internal static void BanUser(int PortalId, int ModuleId, int UserId)
{
if (UserId > -1)
{
DataProvider.Instance().Topics_Delete_For_User(ModuleId: ModuleId, UserId: UserId, DelBehavior: SettingsBase.GetModuleSettings(ModuleId).DeleteBehavior);
DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserById(portalId: PortalId, userId: UserId);
user.Membership.Approved = false;
DotNetNuke.Entities.Users.UserController.UpdateUser(portalId: PortalId, user: user, loggedAction: true);
DataCache.CacheClearPrefix(ModuleId, string.Format("AF-FV-{0}-{1}", PortalId, ModuleId));
}
}
}
}
20 changes: 19 additions & 1 deletion Dnn.CommunityForums/CustomControls/UserControls/TopicView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class TopicView : ForumBase
private bool _bModDelete;
private bool _bModEdit;
private bool _bModMove;
private bool _bModUser;
private bool _bModLock = false;
private bool _bModPin = false;
private bool _bAllowRSS;
Expand Down Expand Up @@ -365,6 +366,7 @@ private void LoadData(int pageId)
_bModMove = Permissions.HasPerm(_drSecurity["CanModMove"].ToString(), ForumUser.UserRoles);
_bModPin = Permissions.HasPerm(_drSecurity["CanModPin"].ToString(), ForumUser.UserRoles);
_bModLock = Permissions.HasPerm(_drSecurity["CanModLock"].ToString(), ForumUser.UserRoles);
_bModUser = Permissions.HasPerm(_drSecurity["CanModUser"].ToString(), ForumUser.UserRoles);

_isTrusted = Utilities.IsTrusted((int)ForumInfo.DefaultTrustValue, ForumUser.TrustLevel, Permissions.HasPerm(ForumInfo.Security.Trust, ForumUser.UserRoles));

Expand Down Expand Up @@ -878,6 +880,7 @@ private string ParseControls(string sOutput)
sbOutput.Replace("[ACTIONS:REPLY]", string.Empty);
sbOutput.Replace("[ACTIONS:ANSWER]", string.Empty);
sbOutput.Replace("[ACTIONS:ALERT]", string.Empty);
sbOutput.Replace("[ACTIONS:BAN]", string.Empty);
sbOutput.Replace("[ACTIONS:MOVE]", string.Empty);
sbOutput.Replace("[RESX:SortPosts]:", string.Empty);
sbOutput.Append("<img src=\""+Page.ResolveUrl(DotNetNuke.Modules.ActiveForums.Globals.ModuleImagesPath+"spacer.gif")+"\" width=\"800\" height=\"1\" runat=\"server\" alt=\"---\" />");
Expand Down Expand Up @@ -1370,6 +1373,22 @@ private string ParseContent(DataRow dr, string tempate, int rowcount)
sbOutput.Replace("[ACTIONS:DELETE]", string.Empty);
}

if ((ForumUser.IsAdmin || ForumUser.IsSuperUser || _bModUser) && (authorId != UserId) && (!author.IsSuperUser) && (!author.IsAdmin))
{
var banParams = new List<string> { ParamKeys.ViewType + "=modban", ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + topicId, ParamKeys.ReplyId + "=" + replyId, ParamKeys.UserId + "=" + authorId };
if (_useListActions)
{
sbOutput.Replace("[ACTIONS:BAN]", "<li onclick=\"window.location.href='" + Utilities.NavigateUrl(TabId, "", banParams) + "';\" title=\"[RESX:Ban]\"><i class=\"fa fa-ban fa-fw fa-blue\"></i>&nbsp;[RESX:Ban]</li>");
}
else
{
sbOutput.Replace("[ACTIONS:BAN]", "<a class=\"af-actions\" href=\"" + Utilities.NavigateUrl(TabId, "", banParams) + "\" tooltip=\"Deletes all posts for this user and unauthorizes the user.\" title=\"[RESX:Ban]\"><i class=\"fa fa-ban fa-fw fa-blue\"></i>&nbsp;[RESX:Ban]</a>");
}
}
else
{
sbOutput.Replace("[ACTIONS:BAN]", string.Empty);
}
// Edit Action
if (_bModEdit || (_bEdit && authorId == UserId && (_editInterval == 0 || SimulateDateDiff.DateDiff(SimulateDateDiff.DateInterval.Minute, dateCreated, DateTime.UtcNow) < _editInterval)))
{
Expand Down Expand Up @@ -1538,7 +1557,6 @@ private string ParseContent(DataRow dr, string tempate, int rowcount)
sbOutput.Replace("[POLLRESULTS]", string.Empty);
}
}

// Mod Alert
//var alertParams = new[] { ParamKeys.ViewType + "=modreport", ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + topicId, ParamKeys.ReplyId + "=" + postId };
var alertParams = new List<string> { ParamKeys.ViewType + "=modreport", ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + topicId, ParamKeys.ReplyId + "=" + postId };
Expand Down
11 changes: 11 additions & 0 deletions Dnn.CommunityForums/DnnCommunityForums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<Content Include="controls\af_attach.ascx">
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="controls\af_modban.ascx">
<SubType>ASPXCodeBehind</SubType>
</Content>
<Content Include="controls\af_polls.ascx" />
<Content Include="controls\af_pollvote.ascx" />
<Content Include="controls\af_sendto.ascx">
Expand Down Expand Up @@ -903,6 +906,7 @@
<Compile Include="Controllers\SubscriptionController.cs" />
<Compile Include="Controllers\TopicController.cs" />
<Compile Include="Controllers\UrlController.cs" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="Entities\Like.cs" />
<Compile Include="Controllers\LikeController.cs" />
<Compile Include="class\ParamBuilder.cs" />
Expand All @@ -911,6 +915,13 @@
<Compile Include="class\WhatsNewModuleSettings.cs" />
<Compile Include="components\Topics\TopicsController.cs" />
<Compile Include="Constants\SEOConstants.cs" />
<Compile Include="controls\af_modban.ascx.cs">
<DependentUpon>af_modban.ascx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="controls\af_modban.ascx.designer.cs">
<DependentUpon>af_modban.ascx</DependentUpon>
</Compile>
<Compile Include="Controllers\TokenController.cs" />
<Compile Include="controls\af_topicscripts.ascx.cs">
<DependentUpon>af_topicscripts.ascx</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ public override void Topics_Delete(int ForumId, int TopicId, int DelBehavior)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "activeforums_Topics_Delete", ForumId, TopicId, DelBehavior, true);
}
public override void Topics_Delete_For_User(int ModuleId, int UserId, int DelBehavior)
{
SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "activeforums_Topics_Delete_For_User", ModuleId, UserId, DelBehavior);
}
public override IDataReader Topics_Get(int PortalId, int ModuleId, int TopicId, int ForumId, int UserId, bool WithSecurity)
{
return (IDataReader)(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "activeforums_Topics_Get", PortalId, ModuleId, TopicId, ForumId, UserId, WithSecurity));
Expand Down
1 change: 1 addition & 0 deletions Dnn.CommunityForums/class/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public static new DataProvider Instance()
#region Topics
public abstract int Topics_AddRating(int TopicId, int UserID, int Rating, string Comments, string IPAddress);
public abstract void Topics_Delete(int ForumId, int TopicId, int DelBehavior);
public abstract void Topics_Delete_For_User(int ModuleId, int UserId, int DelBehavior);
public abstract IDataReader Topics_Get(int PortalId, int ModuleId, int TopicId, int ForumId, int UserId, bool WithSecurity);
public abstract int Topics_GetRating(int TopicId);
public abstract IDataReader Topics_List(int ForumId, int PortalId, int ModuleId);
Expand Down
40 changes: 40 additions & 0 deletions Dnn.CommunityForums/class/ForumBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ForumBase : SettingsBase
private int? _topicId; // = -1;
private int? _replyId;
private int? _quoteId;
private int? _userId;
private bool? _jumpToLastPost;
private string _defaultView = Views.ForumView;
private int _defaultForumViewTemplateId = -1;
Expand Down Expand Up @@ -363,6 +364,45 @@ public int ForumId
_forumId = value;
}
}
public int UserId
{
get
{
// If the id has already been set, return it.
if (_userId.HasValue)
return _userId.Value;

// Set out default value
_userId = -1;

// If there is an id in the query string, parse it
var queryUserId = Request.QueryString[ParamKeys.UserId];
if (!string.IsNullOrWhiteSpace(queryUserId))
{
// Try to parse the id, if it doesn't work, return the default value.
int parsedUserId;
_userId = int.TryParse(queryUserId, out parsedUserId) ? parsedUserId : 0;
}

// If we don't have a user id at this point, try and pull it from "userid" in the query string
if (_userId < 1)
{
queryUserId = Request.QueryString["userid"];
if (!string.IsNullOrWhiteSpace(queryUserId))
{
// Try to parse the id, if it doesn't work, return the default value.
int parsedUserId;
_userId = int.TryParse(queryUserId, out parsedUserId) ? parsedUserId : 0;
}
}

return _userId.Value;
}
set
{
_userId = value;
}
}

public int ForumGroupId
{
Expand Down
8 changes: 5 additions & 3 deletions Dnn.CommunityForums/class/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public enum ConfirmActions
MessageDeleted,
SendToComplete,
SendToFailed,
AlertSent
AlertSent,
UserBanned
}

#endregion
Expand Down Expand Up @@ -302,8 +303,9 @@ public class ParamKeys
public const string ContentJumpId = "afc";
public const string ConfirmActionId = "afca";
public const string Tags = "aftg";
public const string FirstNewPost = "afnp";
}
public const string FirstNewPost = "afnp";
public const string UserId = "afu";
}

public class Views
{
Expand Down
1 change: 1 addition & 0 deletions Dnn.CommunityForums/class/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ internal static string ParseTokenConfig(int moduleId, string template, string gr
template = template.Replace("[PARAMKEYS:VIEWTYPE]", ParamKeys.ViewType);
template = template.Replace("[PARAMKEYS:QUOTEID]", ParamKeys.QuoteId);
template = template.Replace("[PARAMKEYS:REPLYID]", ParamKeys.ReplyId);
template = template.Replace("[PARAMKEYS:USERID]", ParamKeys.UserId);
template = template.Replace("[VIEWS:TOPICS]", Views.Topics);
template = template.Replace("[VIEWS:TOPIC]", Views.Topic);
template = template.Replace("[PAGEID]", config.PageId.ToString());
Expand Down
6 changes: 5 additions & 1 deletion Dnn.CommunityForums/config/defaultgroupforums.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<modlock value="true" />
<modpin value="true" />
<modmove value="true" />
<moduser value="true" />
</security>
<security type="groupmember">
<view value="true" />
Expand All @@ -36,6 +37,7 @@
<modlock value="false" />
<modpin value="false" />
<modmove value="false" />
<moduser value="false" />
</security>
<security type="registereduser">
<view value="true" />
Expand All @@ -54,6 +56,7 @@
<modlock value="false" />
<modpin value="false" />
<modmove value="false" />
<moduser value="false" />
</security>
<security type="anon">
<view value="true" />
Expand All @@ -71,7 +74,8 @@
<moddelete value="false" />
<modlock value="false" />
<modpin value="false" />
<modmove value="false" />
<modmove value="false" />
<moduser value="false" />
</security>
</forum>
</defaultforums>
18 changes: 11 additions & 7 deletions Dnn.CommunityForums/config/tokens.config
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
<token group="*" name="[ACTIONS:REPLY]">
<value><![CDATA[[AF:SECURITY:REPLY]<af:imagebutton runat='server' cssclass='ambuttonsm' PostBack='false' PageId='[PAGEID]' Params='[PARAMKEYS:VIEWTYPE]=post,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[TOPICID],[PARAMKEYS:REPLYID]=[POSTID]' text='[RESX:Reply]' SpriteCSS='aficon aficonreply aficonleft' AuthRoles='[REPLYROLES]' UserRoles='[USERROLES]' />[/AF:SECURITY:REPLY]]]></value>
</token>
<token group="*" name="[ACTIONS:ALERT]">
<value><![CDATA[<af:imagebutton runat='server' cssclass='ambuttonsm' PostBack='false' PageId='[PAGEID]' Params='[PARAMKEYS:VIEWTYPE]=modreport,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[TOPICID],[PARAMKEYS:REPLYID]=[POSTID]' text='[RESX:Alert]' SpriteCSS='aficon aficonalert aficonleft' AuthRoles='[REPLYROLES]' UserRoles='[USERROLES]' />]]></value>
</token>
<token group="*" name="[ACTIONS:MOVE]">
<value><![CDATA[[AF:SECURITY:MOVE]<af:link runat="server" PageId="[PAGEID]" title="[RESX:MoveTopic]" Params="[PARAMKEYS:VIEWTYPE]=modmovetopic,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[POSTID]" text="<img src='[THEMEPATH]/images/topic_move.gif' border='0' style='vertical-align:middle;' />" AuthRoles="[MODMOVE]" cssclass="afactionbtn" />[/AF:SECURITY:MOVE]]]></value>
<token group="*" name="[ACTIONS:ALERT]">
<value><![CDATA[<af:imagebutton runat='server' cssclass='ambuttonsm' PostBack='false' PageId='[PAGEID]' Params='[PARAMKEYS:VIEWTYPE]=modreport,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[TOPICID],[PARAMKEYS:REPLYID]=[POSTID]' text='[RESX:Alert]' SpriteCSS='aficon aficonalert aficonleft' AuthRoles='[REPLYROLES]' UserRoles='[USERROLES]' />]]></value>
</token>
<token group="*" name="[ACTIONS:BAN]">
<value><![CDATA[[AF:SECURITY:USER]<af:imagebutton runat='server' cssclass='ambuttonsm' PostBack='false' PageId='[PAGEID]' Params='[PARAMKEYS:VIEWTYPE]=modban,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[TOPICID],[PARAMKEYS:REPLYID]=[POSTID],[PARAMKEYS:USERID]=[USERID]' text='[RESX:Ban]' SpriteCSS='aficon aficonalert aficonleft' NotAuthText='' AuthRoles='[MODUSER]' /[/AF:SECURITY:USER]>]]></value>
</token>
<token group="*" name="[ACTIONS:MOVE]">
<value><![CDATA[[AF:SECURITY:MOVE]<af:link runat="server" PageId="[PAGEID]" title="[RESX:MoveTopic]" Params="[PARAMKEYS:VIEWTYPE]=modmovetopic,[PARAMKEYS:FORUMID]=[FORUMID],[PARAMKEYS:TOPICID]=[POSTID]" text="<img src='[THEMEPATH]topic_move.gif' border='0' style='vertical-align:middle;' />" AuthRoles="[MODMOVE]" cssclass="afactionbtn" />[/AF:SECURITY:MOVE]]]></value>
</token>
<token group="*" name="[ACTIONS:LOCK]">
<value><![CDATA[[AF:SECURITY:LOCK]<af:link runat="server" NavigateUrl="javascript:if(confirm('[RESX:Confirm:Lock]')){af_cbaction('modlock,[POSTID]');};" title="[RESX:LockTopic]" text="<img src='[THEMEPATH]images/topic_lock.gif' border='0' style='vertical-align:middle;' />" AuthRoles="[MODLOCK]" cssclass="afactionbtn" />[/AF:SECURITY:LOCK]]]></value>
Expand Down Expand Up @@ -99,7 +102,7 @@
</token>
<token group="topic" name="[AF:CONTROL:TOPICACTIONS]" permissions="">
<value>
<![CDATA[<ul>[ACTIONS:DELETE][ACTIONS:EDIT][ACTIONS:QUOTE][ACTIONS:REPLY][ACTIONS:ALERT][ACTIONS:PIN][ACTIONS:LOCK][ACTIONS:MOVE]</ul>]]>
<![CDATA[<ul>[ACTIONS:DELETE][ACTIONS:EDIT][ACTIONS:QUOTE][ACTIONS:REPLY][ACTIONS:ALERT][ACTIONS:BAN][ACTIONS:PIN][ACTIONS:LOCK][ACTIONS:MOVE]</ul>]]>
</value>
</token>
<token group="topic" name="[AF:CONTROL:POSTACTIONS]" permissions="">
Expand All @@ -109,7 +112,8 @@
[ACTIONS:EDIT]
[ACTIONS:QUOTE]
[ACTIONS:REPLY]
[ACTIONS:ALERT]</ul>]]>
[ACTIONS:ALERT]
[ACTIONS:BAN]</ul>]]>
</value>
</token>
</tokens>
Loading