forked from DNNCommunity/DNN.Events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.ascx.cs
264 lines (233 loc) · 10.6 KB
/
Settings.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// 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.
//
#endregion
namespace DotNetNuke.Modules.Events
{
using System;
using System.Collections;
using System.Diagnostics;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Exceptions;
using global::Components;
[DNNtc.ModuleControlProperties("Settings", "Event Settings", DNNtc.ControlType.Admin, "https://github.com/DNNCommunity/DNN.Events/wiki", true, true)]
public partial class Settings : ModuleSettingsBase
{
#region Links, Buttons and Events
protected void cmdUpgrade_Click(object sender, EventArgs e)
{
var emSettings = EventModuleSettings.GetEventModuleSettings(this.ModuleId, this.LocalResourceFile);
var dummyRmid = emSettings.RecurDummy;
this.divUpgrade.Visible = false;
this.divRetry.Visible = false;
if (!string.IsNullOrEmpty(dummyRmid) &&
dummyRmid != "99999")
{
var objEventController = new EventController();
int dummyRmidInt = int.TryParse(dummyRmid, out dummyRmidInt) ? dummyRmidInt : 0;
var upgradeOk =
objEventController.UpgradeRecurringEventModule(this.ModuleId, dummyRmidInt,
emSettings.Maxrecurrences, this.LocalResourceFile);
var objEventCtl = new EventController();
objEventCtl.EventsUpgrade("04.01.00");
if (!upgradeOk)
{
this.divUpgrade.Visible = true;
this.divRetry.Visible = true;
}
}
}
#endregion
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[DebuggerStepThrough]
private void InitializeComponent()
{ }
private void Page_Init(object sender, EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
this.InitializeComponent();
}
#endregion
#region Private Data
#endregion
#region Help Methods
/// <summary>
/// Load current settings into the controls from the modulesettings
/// </summary>
/// <remarks></remarks>
public override void LoadSettings()
{
// Force full PostBack since these pass off to aspx page
if (AJAX.IsInstalled())
{
AJAX.RegisterPostBackControl(this.cmdUpgrade);
}
var emSettings = EventModuleSettings.GetEventModuleSettings(this.ModuleId, this.LocalResourceFile);
var dummyRmid = emSettings.RecurDummy;
this.divUpgrade.Visible = false;
this.divRetry.Visible = false;
if (!string.IsNullOrEmpty(dummyRmid) &&
dummyRmid != "99999")
{
this.divUpgrade.Visible = true;
}
}
/// <summary>
/// Take all settings and write them back to the database
/// </summary>
/// <remarks></remarks>
public override void UpdateSettings()
{
try
{
this.MakeModerator_Editor();
this.UpdateSubscriptions();
var emCacheKey = "EventsModuleTitle" + this.ModuleId;
DataCache.ClearCache(emCacheKey);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void MakeModerator_Editor()
{
try
{
bool blEditor;
var arrRoles = new ArrayList();
var arrUsers = new ArrayList();
var objPermission = default(ModulePermissionInfo);
var objPermissionController = new PermissionController();
var objModules = new ModuleController();
// Get existing module permissions
var objModule = objModules.GetModule(this.ModuleId, this.TabId);
var objModulePermissions2 = new ModulePermissionCollection();
foreach (ModulePermissionInfo perm in objModule.ModulePermissions)
{
if (perm.PermissionKey == "EVENTSMOD" && perm.AllowAccess ||
perm.PermissionKey == "EDIT" && perm.AllowAccess)
{
blEditor = false;
foreach (ModulePermissionInfo perm2 in objModule.ModulePermissions)
{
if (perm2.PermissionKey == "EVENTSEDT" &&
((perm.RoleID == perm2.RoleID) & (perm.RoleID >= 0) ||
(perm.UserID == perm2.UserID) & (perm.UserID >= 0)))
{
if (perm2.AllowAccess)
{
blEditor = true;
}
else
{
objModulePermissions2.Add(perm2);
}
}
}
if (blEditor == false)
{
if (perm.UserID >= 0)
{
arrUsers.Add(perm.UserID);
}
else
{
arrRoles.Add(perm.RoleID);
}
}
}
}
// Remove negative edit permissions where user is moderator
foreach (ModulePermissionInfo perm in objModulePermissions2)
{
objModule.ModulePermissions.Remove(perm);
}
var objEditPermissions =
objPermissionController.GetPermissionByCodeAndKey("EVENTS_MODULE", "EVENTSEDT");
var objEditPermission = (PermissionInfo) objEditPermissions[0];
foreach (int iRoleID in arrRoles)
{
// Add Edit Permission for Moderator Role
objPermission = new ModulePermissionInfo();
objPermission.RoleID = iRoleID;
objPermission.ModuleID = this.ModuleId;
objPermission.PermissionKey = objEditPermission.PermissionKey;
objPermission.PermissionName = objEditPermission.PermissionName;
objPermission.PermissionCode = objEditPermission.PermissionCode;
objPermission.PermissionID = objEditPermission.PermissionID;
objPermission.AllowAccess = true;
objModule.ModulePermissions.Add(objPermission);
}
foreach (int iUserID in arrUsers)
{
objPermission = new ModulePermissionInfo();
objPermission.UserID = iUserID;
objPermission.ModuleID = this.ModuleId;
objPermission.PermissionKey = objEditPermission.PermissionKey;
objPermission.PermissionName = objEditPermission.PermissionName;
objPermission.PermissionCode = objEditPermission.PermissionCode;
objPermission.PermissionID = objEditPermission.PermissionID;
objPermission.AllowAccess = true;
objModule.ModulePermissions.Add(objPermission);
}
ModulePermissionController.SaveModulePermissions(objModule);
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void UpdateSubscriptions()
{
var objCtlEventSubscriptions = new EventSubscriptionController();
var lstEventSubscriptions = default(ArrayList);
lstEventSubscriptions = objCtlEventSubscriptions.EventsSubscriptionGetModule(this.ModuleId);
if (lstEventSubscriptions.Count == 0)
{
return;
}
var objEventInfo = new EventInfoHelper(this.ModuleId, this.TabId, this.PortalId, null);
var lstusers = objEventInfo.GetEventModuleViewers();
var objEventSubscription = default(EventSubscriptionInfo);
foreach (EventSubscriptionInfo tempLoopVar_objEventSubscription in lstEventSubscriptions)
{
objEventSubscription = tempLoopVar_objEventSubscription;
if (!lstusers.Contains(objEventSubscription.UserID))
{
var objCtlUser = new UserController();
var objUser = objCtlUser.GetUser(this.PortalId, objEventSubscription.UserID);
if (ReferenceEquals(objUser, null) || !objUser.IsSuperUser)
{
objCtlEventSubscriptions.EventsSubscriptionDeleteUser(
objEventSubscription.UserID, this.ModuleId);
}
}
}
}
#endregion
}
}