Exemplo n.º 1
0
		public int SavePermissions(int groupId, int forumId, Permission permission)
		{
			string[] fieldNames = {"GroupID", "ForumID"};
			string[] fieldValues = {groupId.ToString(), forumId.ToString()};
			SharePointListItem listItem = Provider.GetListItemByField(ForumConstants.Lists_ForumAccess, fieldNames, fieldValues);

			int rc = 0;
			if (listItem == null)
			{
				string[] values = {
									  "Title", permission.ToString(),
									  "GroupID", groupId.ToString(),
									  "ForumID", forumId.ToString(),
				};

				listItem = new SharePointListItem(0, values);
				rc = Provider.AddListItem(ForumConstants.Lists_ForumAccess, listItem);
			}
			else
			{
				listItem["Title"] = permission.ToString();
				rc = Provider.UpdateListItem(ForumConstants.Lists_ForumAccess, listItem);
			}

			return rc;
		}
		protected override void CreateAdminChildControls()
		{
			CreateControls();

			forumId = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
			groupId = ValidInt(HttpContext.Current.Request.QueryString["group"]);

			Forum forum = RepositoryRegistry.ForumRepository.GetById(forumId);
			Group group = RepositoryRegistry.GroupRepository.FindById(groupId);
			Permission perms = forum.Permissions[groupId] as Permission;
			if (perms == null)
				perms = new Permission();

//			string permissionLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForumPermissions, "forum={0}", forum.Id);
			ParentLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForumPermissions, "forum={0}", forumId);

			AddBoxHeader(String.Format("Manage Permissions for \"{0}\" Group in Forum \"{1}\"", group.Name, forum.Name), false, 2);

			Controls.Add(CreateTableRow("Read", chkRead, perms.HasPermission(Permission.Rights.Read)));
			Controls.Add(CreateTableRow("Add", chkAdd, perms.HasPermission(Permission.Rights.Add)));
			Controls.Add(CreateTableRow("Edit", chkEdit, perms.HasPermission(Permission.Rights.Edit)));
			Controls.Add(CreateTableRow("Reply", chkReply, perms.HasPermission(Permission.Rights.Reply)));
			Controls.Add(CreateTableRow("Delete", chkDelete, perms.HasPermission(Permission.Rights.Delete)));
			Controls.Add(CreateButtonRow(btnSubmit, btnCancel));

			CloseBox();
		}
Exemplo n.º 3
0
		public Hashtable GetPermissionsForForum(int id)
		{
			Hashtable permissions = new Hashtable();
			SharePointListDescriptor listItems = Provider.GetListItemsByField(ForumConstants.Lists_ForumAccess, "ForumID", id.ToString());
			foreach (SharePointListItem listItem in listItems.SharePointListItems)
			{
				Permission perm = new Permission(listItem["Title"]);
				permissions.Add(Convert.ToInt32(listItem["GroupID"]), perm);
			}
			return permissions;
		}
Exemplo n.º 4
0
		/// <summary>
		/// Determines whether the specified user has access 
		/// to any forum in the category.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <param name="right">The right.</param>
		/// <returns>
		/// 	<c>true</c> if the specified user has access; otherwise, <c>false</c>.
		/// </returns>
		public bool HasAccess(ForumUser user, Permission.Rights right)
		{
			foreach (Forum forum in Forums)
			{
				if (forum.HasAccess(user, right))
				{
					return true;
				}
			}

			return false;
		}
Exemplo n.º 5
0
		private void DisplayGroups(Group group, Forum forum)
		{
			Controls.Add(new LiteralControl("<tr class=\"ms-alternating\">"));

			Controls.Add(new LiteralControl("<td>&nbsp;</td>"));

			Controls.Add(new LiteralControl(string.Format("<td>{0}</td>", group.Name)));

			string editLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForumGroupPermissions, "forum={0}&group={1}", forum.Id, group.Id);
			Controls.Add(new LiteralControl(string.Format("<td align=center><a href=\"{0}\">Edit</a></td>", editLink)));

			string permissionDisplay = "None";
			foreach (DictionaryEntry permission in forum.Permissions)
			{
				if (Convert.ToInt32(permission.Key) == group.Id)
				{
					Permission perm = new Permission(permission.Value.ToString());
					permissionDisplay = perm.DisplayString;
				}
			}
			Controls.Add(new LiteralControl(string.Format("<td align=center>{0}</td>", permissionDisplay)));

			Controls.Add(new LiteralControl("</tr>"));
		}
Exemplo n.º 6
0
		public override void AddSampleData()
		{
			if (ListExists)
			{
				Permission perm = new Permission();
				string[] values = new string[6];

				perm.SetPermission(Permission.Rights.Read, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "1";
				values[4] = "GroupID";
				values[5] = "1"; // reader
				AddListValues(values);

				perm.SetPermission(Permission.Rights.Read, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "0"; // default (non-existant) forum
				values[4] = "GroupID";
				values[5] = "1"; // reader
				AddListValues(values);

				perm.SetPermission(Permission.Rights.Add, true);
				perm.SetPermission(Permission.Rights.Edit, true);
				perm.SetPermission(Permission.Rights.Reply, true);
				perm.SetPermission(Permission.Rights.Delete, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "1";
				values[4] = "GroupID";
				values[5] = "2"; // contributor
				AddListValues(values);

				perm.SetPermission(Permission.Rights.Add, true);
				perm.SetPermission(Permission.Rights.Edit, true);
				perm.SetPermission(Permission.Rights.Reply, true);
				perm.SetPermission(Permission.Rights.Delete, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "0"; // default forum
				values[4] = "GroupID";
				values[5] = "2"; // contributor
				AddListValues(values);

				perm.SetPermission(Permission.Rights.Admin, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "1";
				values[4] = "GroupID";
				values[5] = "3"; // administrator
				AddListValues(values);

				perm.SetPermission(Permission.Rights.Admin, true);
				values[0] = "Title";
				values[1] = perm.ToString();
				values[2] = "ForumID";
				values[3] = "0"; // default forum
				values[4] = "GroupID";
				values[5] = "3"; // administrator
				AddListValues(values);
			}
		}
Exemplo n.º 7
0
		/// <summary>
		/// Determines whether the specified user has access.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <param name="rights">The rights.</param>
		/// <returns>
		/// 	<c>true</c> if the specified user has access; otherwise, <c>false</c>.
		/// </returns>
		public bool HasAccess(ForumUser user, Permission.Rights rights)
		{
			foreach (Group userGroup in user.Groups)
			{
				Permission perm = Permissions[userGroup.Id] as Permission;
				if (perm != null)
				{
					if (perm.HasPermission(rights))
						return true;
				}
			}

			return false;
		}
Exemplo n.º 8
0
		public int SavePermissions(int groupId, int forumId, Permission permission)
		{
			return _dao.SavePermissions(groupId, forumId, permission);
		}
Exemplo n.º 9
0
		private void SetupDefaultPermissions(int newId)
		{
			Hashtable permissions = GetPermissionsForForum(DEFAULT_FORUM_ID);
			GroupCollection groups = RepositoryRegistry.GroupRepository.GetAll();
			foreach (Group group in groups)
			{
				Permission perms = permissions[group.Id] as Permission;
				if (perms == null)
					perms = new Permission();
				SavePermissions(group.Id, newId, perms);
			}
		}
Exemplo n.º 10
0
		private void btnSubmit_Click(object sender, EventArgs e)
		{
			Forum forum = RepositoryRegistry.ForumRepository.GetById(forumId);
			Permission perms = forum.Permissions[groupId] as Permission;
			if (perms == null)
				perms = new Permission();

			perms.SetPermission(Permission.Rights.Read, chkRead.Checked);
			perms.SetPermission(Permission.Rights.Add, chkAdd.Checked);
			perms.SetPermission(Permission.Rights.Edit, chkEdit.Checked);
			perms.SetPermission(Permission.Rights.Reply, chkReply.Checked);
			perms.SetPermission(Permission.Rights.Delete, chkDelete.Checked);

			RepositoryRegistry.ForumRepository.SavePermissions(groupId, forumId, perms);

			RedirectToParent();
		}