Ejemplo n.º 1
0
		/// <summary>
		/// Creates a link to the profile page for a given user. Used
		/// in various places for other users to navigate to a persons
		/// profile page.
		/// </summary>
		/// <param name="user">The user to link to.</param>
		/// <returns>A formatted link that can be used in any HTML display</returns>
		public static string CreateProfileLink(ForumUser user)
		{
			string link;

			string profileLink = ForumApplication.Instance.GetLink(SharePointForumControls.ViewProfile, "userid={0}", user.UserId);
			link = String.Format("<a href=\"{0}\">{1}</a>", profileLink, user.Name);

			return link;
		}
Ejemplo n.º 2
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;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Loads the groups for user.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <param name="user">The user.</param>
		private static void LoadGroupsForUser(SharePointListItem listItem, ForumUser user)
		{
			string groupIds = listItem["Groups"];
			string delim = ";";
			char[] delimArray = delim.ToCharArray();
			string[] groupArray = groupIds.Split(delimArray);
			foreach (string s in groupArray)
			{
				int groupId = Convert.ToInt32(s);
				Group group = RepositoryRegistry.GroupRepository.FindById(groupId);
				user.Groups.Add(group);
			}
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Loads the share point info for user.
		/// </summary>
		/// <param name="user">The user.</param>
		private static void LoadSharePointInfoForUser(ForumUser user)
		{
			try
			{
				SPUser spCurrentUser = ForumApplication.Instance.SpWeb.SiteUsers.GetByID(user.UserId);
				if(null != spCurrentUser)
				{
					user.Name = spCurrentUser.Name;
					user.Email = spCurrentUser.Email;
				}
			}
			catch (Exception)
			{
			}
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Creates the dto.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public static SharePointListItem CreateDto(ForumUser user)
		{
			string[] values = {
				"Title", user.Name,
				"UserID", user.UserId.ToString(),
				"LastVisit", user.LastVisit.ToString(),
				"NumPosts", user.NumPosts.ToString(),
				"IsAdmin", user.IsAdmin.ToString(),
				"Groups", user.Id == 0
					? ForumApplication.Instance.GetDefaultGroupsForNewUser()
					: user.Groups.ToString(),
			};

			return new SharePointListItem(user.Id, values);
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Creates the domain object.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <returns></returns>
		public static ForumUser CreateDomainObject(SharePointListItem listItem)
		{
			ForumUser user = new ForumUser();

			user.Id = Convert.ToInt32(listItem.Id);
			user.LastVisit = Convert.ToDateTime(listItem["LastVisit"]);
			user.UserId = Convert.ToInt32(listItem["UserID"]);
			user.NumPosts = Convert.ToInt32(listItem["NumPosts"]);
			user.Joined = Convert.ToDateTime(listItem["Created"]);
			user.IsAdmin = Convert.ToBoolean(listItem["IsAdmin"]);

			LoadGroupsForUser(listItem, user);
			LoadSharePointInfoForUser(user);

			return user;
		}
Ejemplo n.º 7
0
		private void SaveControlValues()
		{
			userId = ValidInt(HttpContext.Current.Request.QueryString["id"]);
			user = RepositoryRegistry.ForumUserRepository.GetById(userId);

			user.IsAdmin = cbIsAdmin.Checked;

			foreach (object control in Controls)
			{
				if (control is TableRow)
				{
					TableRow row = control as TableRow;
					foreach (object o in row.Controls)
					{
						if (o is TableCell)
						{
							TableCell cell = o as TableCell;
							foreach (object control1 in cell.Controls)
							{
								if (control1 is CheckBox)
								{
									CheckBox cb = control1 as CheckBox;
									int id = Convert.ToInt32(cb.ID);
									if (id != 0)
									{
										Group group = RepositoryRegistry.GroupRepository.FindById(id);
										Group userGroup = user.Groups.Find(group.Id);
										if (cb.Checked)
										{
											if (userGroup == null)
												user.Groups.Add(group);
										}
										else
										{
											if (userGroup != null)
												user.Groups.Remove(userGroup);
										}
									}
								}
							}
						}
					}
				}
			}

			RepositoryRegistry.ForumUserRepository.Save(user);
		}
Ejemplo n.º 8
0
		public int Save(ForumUser user)
		{
			int userId;

			SharePointListItem listItem = UserMapper.CreateDto(user);

			if (user.Id == 0)
			{
				userId = Provider.AddListItem(ForumConstants.Lists_Users, listItem);
			}
			else
			{
				userId = Provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
			}

			return userId;
		}
Ejemplo n.º 9
0
		public int Save(ForumUser user)
		{
			int userId;

			SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
			SharePointListItem listItem = UserMapper.CreateDto(user);

			if (user.Id == 0)
			{
				userId = provider.AddListItem(ForumConstants.Lists_Users, listItem);
			}
			else
			{
				userId = provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
			}

			return userId;
		}
Ejemplo n.º 10
0
		private string FillUserInfoBox(ForumUser user)
		{
			StringBuilder sb = new StringBuilder();

			sb.AppendFormat("{0}: {1}<br>", this.WebPartParent.LoadResource("UserInfoBox.Joined"), user.Joined.ToShortDateString());
			sb.AppendFormat("{0}: {1}<br>", this.WebPartParent.LoadResource("UserInfoBox.Posts"), user.NumPosts);

			return sb.ToString();
		}
Ejemplo n.º 11
0
		public void UserShouldHaveAccess()
		{
			ForumUser user = new ForumUser();
			Category category = new Category("Test");
			Assert.AreEqual(true, category.HasAccess(user, Permission.Rights.Add));
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Indexes the of.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public int IndexOf(ForumUser user)
		{
			return List.IndexOf(user);
		}
Ejemplo n.º 13
0
		/// <summary>
		/// Determines whether [contains] [the specified user].
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns>
		/// 	<c>true</c> if [contains] [the specified user]; otherwise, <c>false</c>.
		/// </returns>
		public bool Contains(ForumUser user)
		{
			return List.Contains(user);
		}
Ejemplo n.º 14
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;
		}
Ejemplo n.º 15
0
		private void LoadControlValues()
		{
			userId = ValidInt(HttpContext.Current.Request.QueryString["id"]);
			user = RepositoryRegistry.ForumUserRepository.GetById(userId);
			cbIsAdmin.Checked = user.IsAdmin;
		}
Ejemplo n.º 16
0
		public int Save(ForumUser user)
		{
			return _dao.Save(user);
		}
Ejemplo n.º 17
0
		private void CreateUser(int id)
		{
			ForumUser user = new ForumUser();
			user.Name = ForumApplication.Instance.SpUser.Name;
			user.Id = id;
			user.UserId = ForumApplication.Instance.SpUser.ID;
			user.LastVisit = DateTime.Now;
			user.NumPosts = id == 1 ? 1 : 0;
			user.IsAdmin = id == 1 ? true : false;
			Save(user);
		}
Ejemplo n.º 18
0
		/// <summary>
		/// Adds the specified user.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public int Add(ForumUser user)
		{
			return List.Add(user);
		}