PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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