예제 #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;
		}
예제 #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;
		}
예제 #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);
			}
		}
예제 #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)
			{
			}
		}
예제 #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);
		}
예제 #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;
		}
예제 #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);
		}
예제 #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;
		}
예제 #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;
		}
예제 #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();
		}
예제 #11
0
		public void UserShouldHaveAccess()
		{
			ForumUser user = new ForumUser();
			Category category = new Category("Test");
			Assert.AreEqual(true, category.HasAccess(user, Permission.Rights.Add));
		}
예제 #12
0
		/// <summary>
		/// Indexes the of.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public int IndexOf(ForumUser user)
		{
			return List.IndexOf(user);
		}
예제 #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);
		}
예제 #14
0
파일: Forum.cs 프로젝트: bsimser/spforums
		/// <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;
		}
예제 #15
0
		private void LoadControlValues()
		{
			userId = ValidInt(HttpContext.Current.Request.QueryString["id"]);
			user = RepositoryRegistry.ForumUserRepository.GetById(userId);
			cbIsAdmin.Checked = user.IsAdmin;
		}
예제 #16
0
		public int Save(ForumUser user)
		{
			return _dao.Save(user);
		}
예제 #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);
		}
예제 #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);
		}