PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Security/Rights.cs

#
C# | 388 lines | 131 code | 72 blank | 185 comment | 0 complexity | c6a26c32ceaa295c22568c67633d3ad1 MD5 | raw file
  1using System;
  2using System.Collections.ObjectModel;
  3using System.Collections.Generic;
  4using System.Linq;
  5using System.Text;
  6using System.Threading;
  7using System.Web;
  8using System.Web.Security;
  9using System.Diagnostics;
 10using System.Security;
 11
 12namespace BlogEngine.Core
 13{
 14
 15    /// <summary>
 16    /// Enum that represents rights or permissions that are used through out BlogEngine.
 17    /// </summary>
 18    /// <remarks>
 19    /// 
 20    /// Each Rights enum value is wrapped by an associated Right instance that contains information about roles/descriptions/etc.
 21    /// 
 22    /// When a Rights value is serialized to persistant storage, the enum's string name should be used in order to prevent
 23    /// conflicts with value changes due to new values being added(either through updates or customization).
 24    /// 
 25    /// Also, at the moment this doesn't nearly represent all the current possible actions. This is just a few
 26    /// test values to play with.
 27    /// 
 28    /// I'd recommend using a common word pattern when used. Ie: Create/Edit/Delete/Publish as prefixes. The names
 29    /// should be very specific to what they allow in order to avoid confusion. For example, don't use a name like
 30    /// "ViewPosts". Use something that also specifies the kinds of posts, like ViewPublicPosts, ViewPrivatePosts, or
 31    /// ViewUnpublishedPosts.
 32    /// 
 33    /// </remarks>
 34    public enum Rights
 35    {
 36
 37        /// <summary>
 38        /// Represents a user that has no rights or permissions. This flag should not be used in combination with any other flag.
 39        /// </summary>
 40        /// <remarks>
 41        /// 
 42        /// This value isn't meant for public consumption.
 43        /// 
 44        /// </remarks>
 45        None = 0,
 46
 47        #region Misc
 48
 49        /// <summary>
 50        /// A user is allowed to view exception messages.
 51        /// </summary>
 52        [RightDetails(Category = RightCategory.General)]
 53        ViewDetailedErrorMessages,
 54
 55        /// <summary>
 56        /// A user is allowed to access administration pages.
 57        /// Typically, a blog where self-registration is allowed
 58        /// would restrict this right from guest users.
 59        /// </summary>
 60        [RightDetails(Category = RightCategory.General)]
 61        AccessAdminPages,
 62
 63        /// <summary>
 64        /// A user is allowed to access admin settings pages.
 65        /// </summary>
 66        [RightDetails(Category = RightCategory.General)]
 67        AccessAdminSettingsPages,
 68
 69        /// <summary>
 70        /// A user is allowed to manage widgets.
 71        /// </summary>
 72        [RightDetails(Category = RightCategory.General)]
 73        ManageWidgets,
 74
 75        #endregion
 76
 77        #region "Comments"
 78
 79        /// <summary>
 80        /// A user is allowed to view comments on a post.
 81        /// </summary>
 82        [RightDetails(Category = RightCategory.Comments)]
 83        ViewPublicComments,
 84
 85        /// <summary>
 86        /// A user is allowed to view comments that have not been moderation yet.
 87        /// </summary>
 88        [RightDetails(Category = RightCategory.Comments)]
 89        ViewUnmoderatedComments,
 90
 91        /// <summary>
 92        /// A user is allowed to create and submit comments for posts or pages.
 93        /// </summary>
 94        [RightDetails(Category = RightCategory.Comments)]
 95        CreateComments,
 96
 97        /// <summary>
 98        /// User can approve, delete, or mark comments as spam.
 99        /// </summary>
100        [RightDetails(Category = RightCategory.Comments)]
101        ModerateComments,
102
103        #endregion
104
105 
106        #region Posts
107
108        /// <summary>
109        /// A user is allowed to view posts that are both published and public.
110        /// </summary>
111        [RightDetails(Category = RightCategory.Posts)]
112        ViewPublicPosts,
113
114        /// <summary>
115        /// A user is allowed to view unpublished posts.
116        /// </summary>
117        [RightDetails(Category = RightCategory.Posts)]
118        ViewUnpublishedPosts,
119
120        /// <summary>
121        /// A user is allowed to view non-public posts.
122        /// </summary>
123        // 11/6/2010 - commented out, we don't currently have "private" posts, just unpublished.
124        //[RightDetails(Category = RightCategory.Posts)]
125        //ViewPrivatePosts,
126
127        /// <summary>
128        /// A user can create new posts. 
129        /// </summary>
130        [RightDetails(Category = RightCategory.Posts)]
131        CreateNewPosts,
132
133        /// <summary>
134        /// A user can edit their own posts. 
135        /// </summary>
136        [RightDetails(Category = RightCategory.Posts)]
137        EditOwnPosts,
138
139        /// <summary>
140        /// A user can edit posts created by other users.
141        /// </summary>
142        [RightDetails(Category = RightCategory.Posts)]
143        EditOtherUsersPosts,
144
145        /// <summary>
146        /// A user can delete their own posts.
147        /// </summary>
148        [RightDetails(Category = RightCategory.Posts)]
149        DeleteOwnPosts,
150
151        /// <summary>
152        /// A user can delete posts created by other users.
153        /// </summary>
154        [RightDetails(Category = RightCategory.Posts)]
155        DeleteOtherUsersPosts,
156
157        /// <summary>
158        /// A user can set whether or not their own posts are published.
159        /// </summary>
160        [RightDetails(Category = RightCategory.Posts)]
161        PublishOwnPosts,
162
163        /// <summary>
164        /// A user can set whether or not another user's posts are published.
165        /// </summary>
166        [RightDetails(Category = RightCategory.Posts)]
167        PublishOtherUsersPosts,
168
169        #endregion
170
171        #region Pages
172        
173        /// <summary>
174        /// A user can view public, published pages.
175        /// </summary>
176        [RightDetails(Category = RightCategory.Pages)]
177        ViewPublicPages,
178
179        /// <summary>
180        /// A user can view unpublished pages.
181        /// </summary>
182        [RightDetails(Category = RightCategory.Pages)]
183        ViewUnpublishedPages,
184
185        /// <summary>
186        /// A user can create new pages.
187        /// </summary>
188        [RightDetails(Category = RightCategory.Pages)]
189        CreateNewPages,
190
191        /// <summary>
192        /// A user can edit pages they've created.
193        /// </summary>
194        [RightDetails(Category = RightCategory.Pages)]
195        EditOwnPages,
196
197        /// <summary>
198        /// A user can edit pages other users have created.
199        /// </summary>
200        [RightDetails(Category = RightCategory.Pages)]
201        EditOtherUsersPages,
202
203        /// <summary>
204        /// A user can delete pages they've created.
205        /// </summary>
206        [RightDetails(Category = RightCategory.Pages)]
207        DeleteOwnPages,
208
209        /// <summary>
210        /// A user can delete pages other users have created.
211        /// </summary>
212        [RightDetails(Category = RightCategory.Pages)]
213        DeleteOtherUsersPages,
214
215        /// <summary>
216        /// A user can set whether or not their own pages are published.
217        /// </summary>
218        [RightDetails(Category = RightCategory.Pages)]
219        PublishOwnPages,
220
221        /// <summary>
222        /// A user can set whether or not another user's pages are published.
223        /// </summary>
224        [RightDetails(Category = RightCategory.Pages)]
225        PublishOtherUsersPages,
226
227        #endregion
228
229        #region "Ratings"
230
231        /// <summary>
232        /// A user can view ratings on posts.
233        /// </summary>
234        [RightDetails(Category = RightCategory.Posts)]
235        ViewRatingsOnPosts,
236
237        /// <summary>
238        /// A user can submit ratings on posts.
239        /// </summary>
240        [RightDetails(Category = RightCategory.Posts)]
241        SubmitRatingsOnPosts,
242        #endregion
243
244        #region Roles
245
246        /// <summary>
247        /// A user can view roles.
248        /// </summary>
249        [RightDetails(Category = RightCategory.Roles)]
250        ViewRoles,
251
252        /// <summary>
253        /// A user can create new roles.
254        /// </summary>
255        [RightDetails(Category = RightCategory.Roles)]
256        CreateNewRoles,
257
258        /// <summary>
259        /// A user can edit existing roles.
260        /// </summary>
261        [RightDetails(Category = RightCategory.Roles)]
262        EditRoles,
263
264        /// <summary>
265        /// A user can delete existing roles.
266        /// </summary>
267        [RightDetails(Category = RightCategory.Roles)]
268        DeleteRoles,
269
270        /// <summary>
271        /// A user is allowed to edit their own roles.
272        /// </summary>
273        [RightDetails(Category = RightCategory.Roles)]
274        EditOwnRoles,
275
276        /// <summary>
277        /// A user is allowed to edit the roles of other users.
278        /// </summary>
279        [RightDetails(Category = RightCategory.Roles)]
280        EditOtherUsersRoles,
281
282        #endregion
283
284        #region Users
285
286        /// <summary>
287        /// A user is allowed to register/create a new account. 
288        /// </summary>
289        [RightDetails(Category = RightCategory.Users)]
290        CreateNewUsers,
291
292        /// <summary>
293        /// A user is allowed to delete their own account.
294        /// </summary>
295        [RightDetails(Category = RightCategory.Users)]
296        DeleteUserSelf,
297
298        /// <summary>
299        /// A user is allowed to delete accounts they do not own.
300        /// </summary>
301        [RightDetails(Category = RightCategory.Users)]
302        DeleteUsersOtherThanSelf,
303
304        /// <summary>
305        /// A user is allowed to edit their own account information.
306        /// </summary>
307        [RightDetails(Category = RightCategory.Users)]
308        EditOwnUser,
309
310        /// <summary>
311        /// A user is allowed to edit the account information of other users.
312        /// </summary>
313        [RightDetails(Category=RightCategory.Users)]
314        EditOtherUsers,
315
316        #endregion
317    }
318
319
320    /// <summary>
321    /// Attribute used to provide extra information about a Rights enum value.
322    /// </summary>
323    [AttributeUsage(AttributeTargets.Field, AllowMultiple=false, Inherited=false)]
324    public sealed class RightDetailsAttribute : Attribute
325    {
326        /// <summary>
327        /// Default constructor.
328        /// </summary>
329        public RightDetailsAttribute()
330        {
331
332        }
333
334        #region "Properties"
335
336        public string DescriptionResourceLabelKey { get; set; }
337        public string NameResourceLabelKey { get; set; }
338
339        /// <summary>
340        /// The category a Right is for.
341        /// </summary>
342        public RightCategory Category { get; set; }
343
344        #endregion
345
346    }
347
348    /// <summary>
349    /// Categories for Rights.
350    /// </summary>
351    public enum RightCategory
352    {
353        /// <summary>
354        /// No category
355        /// </summary>
356        None,
357
358        /// <summary>
359        /// General category
360        /// </summary>
361        General,
362
363        /// <summary>
364        /// Comments category
365        /// </summary>
366        Comments,
367
368        /// <summary>
369        /// Pages category
370        /// </summary>
371        Pages,
372
373        /// <summary>
374        /// Post category
375        /// </summary>
376        Posts,
377
378        /// <summary>
379        /// Users category
380        /// </summary>
381        Users,
382
383        /// <summary>
384        /// Roles
385        /// </summary>
386        Roles
387    }
388}