22
22
23
23
namespace DotNetNuke . Modules . ActiveForums . Controllers
24
24
{
25
- using DotNetNuke . Data ;
26
- using DotNetNuke . Entities . Portals ;
27
- using DotNetNuke . Entities . Users ;
28
- using DotNetNuke . Services . Journal ;
29
- using DotNetNuke . Services . Log . EventLog ;
30
- using DotNetNuke . Services . Social . Notifications ;
31
- using DotNetNuke . UI . UserControls ;
32
25
using System ;
33
26
using System . Linq ;
34
27
using System . Text ;
35
28
using System . Threading ;
36
29
using System . Web ;
37
30
31
+ using DotNetNuke . Data ;
32
+ using DotNetNuke . Entities . Portals ;
33
+ using DotNetNuke . Entities . Users ;
34
+ using DotNetNuke . Services . Journal ;
35
+ using DotNetNuke . Services . Log . EventLog ;
36
+
38
37
internal class ForumUserController : DotNetNuke . Modules . ActiveForums . Controllers . RepositoryControllerBase < DotNetNuke . Modules . ActiveForums . Entities . ForumUserInfo >
39
38
{
40
39
private readonly int moduleId = - 1 ;
@@ -227,7 +226,7 @@ public bool GetUserIsSuperUser(int portalId, int moduleId, int userId)
227
226
return this . GetByUserId ( portalId , userId ) . IsSuperUser ;
228
227
}
229
228
230
- private struct JournalContentForUser
229
+ private class JournalContentForUser
231
230
{
232
231
internal int ForumId { get ; set ; }
233
232
@@ -250,28 +249,29 @@ internal static void BanUser(int portalId, int tabId, int moduleId, string modul
250
249
string sSubject = string . Empty ;
251
250
if ( replyId > 0 )
252
251
{
253
- DotNetNuke . Modules . ActiveForums . Entities . ReplyInfo reply = new DotNetNuke . Modules . ActiveForums . Controllers . ReplyController ( moduleId ) . GetById ( replyId ) ;
252
+ var reply = new DotNetNuke . Modules . ActiveForums . Controllers . ReplyController ( moduleId ) . GetById ( replyId ) ;
254
253
sBody = reply . Content . Body ;
255
254
sSubject = reply . Content . Subject ;
256
255
authorName = reply . Author . DisplayName ;
257
256
}
258
257
else
259
258
{
260
- DotNetNuke . Modules . ActiveForums . Entities . TopicInfo topic = new DotNetNuke . Modules . ActiveForums . Controllers . TopicController ( moduleId ) . GetById ( topicId ) ;
259
+ var topic = new DotNetNuke . Modules . ActiveForums . Controllers . TopicController ( moduleId ) . GetById ( topicId ) ;
261
260
sBody = topic . Content . Body ;
262
261
sSubject = topic . Content . Subject ;
263
262
authorName = topic . Author . DisplayName ;
264
263
}
264
+
265
265
string notificationSubject = Utilities . GetSharedResource ( "[RESX:BanAlertSubject]" ) ;
266
- notificationSubject = notificationSubject . Replace ( "[Username]" , bannedUser . Username ) ;
267
- notificationSubject = notificationSubject . Replace ( "[DisplayName]" , bannedUser . DisplayName ) ;
266
+ notificationSubject = notificationSubject . Replace ( "[Username]" , bannedUser == null ? string . Concat ( Utilities . GetSharedResource ( "[RESX:DeletedUser]" ) , "(" , authorId , ")" ) : bannedUser . Username ) ;
267
+ notificationSubject = notificationSubject . Replace ( "[DisplayName]" , bannedUser == null ? string . Concat ( Utilities . GetSharedResource ( "[RESX:DeletedUser]" ) , "(" , authorId , ")" ) : bannedUser . DisplayName ) ;
268
268
notificationSubject = notificationSubject . Replace ( "[BannedBy]" , bannedBy . DisplayName ) ;
269
269
string body = Utilities . GetSharedResource ( "[RESX:BanAlertBody]" ) ;
270
270
body = body . Replace ( "[Subject]" , sSubject ) ;
271
271
272
- StringBuilder postsRemoved = new StringBuilder ( ) ;
272
+ var postsRemoved = new StringBuilder ( ) ;
273
273
274
- var contentForBannedUser = DataContext . Instance ( ) . ExecuteQuery < JournalContentForUser > ( System . Data . CommandType . StoredProcedure , "{databaseOwner}{objectQualifier}activeforums_Content_GetJournalKeysForUser" , bannedUser . UserID , moduleId ) . ToList ( ) ;
274
+ var contentForBannedUser = DataContext . Instance ( ) . ExecuteQuery < JournalContentForUser > ( System . Data . CommandType . StoredProcedure , "{databaseOwner}{objectQualifier}activeforums_Content_GetJournalKeysForUser" , authorId , moduleId ) . ToList ( ) ;
275
275
string objectKey ;
276
276
contentForBannedUser . ForEach ( c =>
277
277
{
@@ -280,31 +280,39 @@ internal static void BanUser(int portalId, int tabId, int moduleId, string modul
280
280
{
281
281
JournalController . Instance . DeleteJournalItemByKey ( portalId , objectKey ) ;
282
282
}
283
+
283
284
postsRemoved . AppendLine ( $ "{ Utilities . GetUserFriendlyDateTimeString ( c . DateUpdated , moduleId , bannedBy ) } \t { c . Subject } ") ;
284
285
DotNetNuke . Modules . ActiveForums . Controllers . ModerationController . RemoveModerationNotifications ( tabId , moduleId , c . ForumId , c . TopicId , c . ReplyId ) ;
285
286
} ) ;
286
287
body = body . Replace ( "[PostsRemoved]" , postsRemoved . ToString ( ) ) ;
287
288
288
- Notification notification = new Notification ( ) ;
289
- notification . NotificationTypeID = NotificationsController . Instance . GetNotificationType ( Globals . BanUserNotificationType ) . NotificationTypeId ;
290
- notification . Subject = notificationSubject ;
291
- notification . Body = body ;
292
- notification . IncludeDismissAction = true ;
293
- notification . SenderUserID = bannedBy . UserID ;
294
- notification . Context = DotNetNuke . Modules . ActiveForums . Controllers . ModerationController . BuildNotificationContextKey ( tabId , moduleId , forumId , topicId , replyId ) ;
289
+ var notification = new DotNetNuke . Services . Social . Notifications . Notification
290
+ {
291
+ NotificationTypeID = DotNetNuke . Services . Social . Notifications . NotificationsController . Instance . GetNotificationType ( Globals . BanUserNotificationType ) . NotificationTypeId ,
292
+ Subject = notificationSubject ,
293
+ Body = body ,
294
+ IncludeDismissAction = true ,
295
+ SenderUserID = bannedBy . UserID ,
296
+ Context = DotNetNuke . Modules . ActiveForums . Controllers . ModerationController . BuildNotificationContextKey ( tabId , moduleId , forumId , topicId , replyId ) ,
297
+ } ;
295
298
296
299
var modRoles = DotNetNuke . Modules . ActiveForums . Controllers . ModerationController . GetModeratorRoles ( portalId , moduleId , forumId ) ;
297
- NotificationsController . Instance . SendNotification ( notification , portalId , modRoles , null ) ;
300
+ DotNetNuke . Services . Social . Notifications . NotificationsController . Instance . SendNotification ( notification , portalId , modRoles , null ) ;
298
301
299
302
var log = new DotNetNuke . Services . Log . EventLog . LogInfo { LogTypeKey = DotNetNuke . Abstractions . Logging . EventLogType . ADMIN_ALERT . ToString ( ) } ;
300
303
log . LogProperties . Add ( new LogDetailInfo ( "Module" , moduleTitle ) ) ;
301
- string userBannedMsg = String . Format ( Utilities . GetSharedResource ( "[RESX:UserBanned]" ) , bannedUser . Username ) ;
304
+ string userBannedMsg = string . Format ( Utilities . GetSharedResource ( "[RESX:UserBanned]" ) , bannedUser == null ? string . Concat ( Utilities . GetSharedResource ( "[RESX:DeletedUser]" ) , "(" , authorId , ")" ) : bannedUser . Username ) ;
302
305
log . AddProperty ( "Message" , userBannedMsg ) ;
303
306
DotNetNuke . Services . Log . EventLog . LogController . Instance . AddLog ( log ) ;
304
307
305
- DotNetNuke . Modules . ActiveForums . DataProvider . Instance ( ) . Topics_Delete_For_User ( moduleId : moduleId , userId : bannedUser . UserID , delBehavior : SettingsBase . GetModuleSettings ( moduleId ) . DeleteBehavior ) ;
306
- bannedUser . Membership . Approved = false ;
307
- DotNetNuke . Entities . Users . UserController . UpdateUser ( portalId : portalId , user : bannedUser , loggedAction : true ) ;
308
+ DotNetNuke . Modules . ActiveForums . DataProvider . Instance ( ) . Topics_Delete_For_User ( moduleId : moduleId , userId : authorId , delBehavior : SettingsBase . GetModuleSettings ( moduleId ) . DeleteBehavior ) ;
309
+
310
+ if ( bannedUser != null )
311
+ {
312
+ bannedUser . Membership . Approved = false ;
313
+ DotNetNuke . Entities . Users . UserController . UpdateUser ( portalId : portalId , user : bannedUser , loggedAction : true ) ;
314
+ }
315
+
308
316
DataCache . ClearAllCache ( moduleId ) ;
309
317
}
310
318
}
0 commit comments