コード例 #1
0
ファイル: GalleryPage.cs プロジェクト: Jiyuu/galleryserverpro
        /// <summary>
        /// Gets the highest-level album the current user can view. Guaranteed to not return null. If a user does not have permission to 
        /// view any objects, this function returns a virtual album with no objects and automatically assigns the <see cref="ClientMessage" /> 
        /// property to <see cref="MessageType.NoAuthorizedAlbumForUser" />, which will cause a message to be displayed to the user.
        /// </summary>
        /// <returns>Returns an IAlbum representing the highest-level album the current user can view.</returns>
        private IAlbum GetHighestAlbumUserCanView()
        {
            var galleryObjectSearcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions()
                                                                                                                            {
                                                                                                                                GalleryId = GalleryId,
                                                                                                                                SearchType = GalleryObjectSearchType.HighestAlbumUserCanView,
                                                                                                                                Roles = RoleController.GetGalleryServerRolesForUser(),
                                                                                                                                IsUserAuthenticated = Utils.IsAuthenticated,
                                                                                                                                Filter = GalleryObjectType.Album
                                                                                                                            });

            var album = galleryObjectSearcher.FindOne();

            var tempAlbum = album as IAlbum;

            if (album != null && tempAlbum == null)
            {
                throw new WebException(String.Format(CultureInfo.InvariantCulture, "A gallery object search for {0} returned an object that couldn't be cast to IAlbum. It was a {1}.", GalleryObjectSearchType.HighestAlbumUserCanView, album.GetType()));
            }

            if (album == null)
            {
                // Create virtual album so that page has something to bind to.
                tempAlbum = Factory.CreateEmptyAlbumInstance(GalleryId);
                tempAlbum.IsVirtualAlbum = true;
                tempAlbum.VirtualAlbumType = VirtualAlbumType.Root;
                tempAlbum.Title = Resources.GalleryServerPro.Site_Virtual_Album_Title;
                tempAlbum.Caption = String.Empty;

                if (Array.IndexOf(new[] { PageId.login, PageId.recoverpassword, PageId.createaccount }, PageId) < 0)
                {
                    ClientMessage = GetMessageOptions(MessageType.NoAuthorizedAlbumForUser);
                }
            }

            return tempAlbum;
        }
コード例 #2
0
ファイル: Factory.cs プロジェクト: Jiyuu/galleryserverpro
		/// <summary>
		/// Return all top-level albums in the specified <paramref name = "galleryId">gallery</paramref> where the <paramref name = "roles" /> 
		/// provide view permission to the album. If more than one album is found, they are wrapped in a virtual container 
		/// album where the <see cref="IAlbum.IsVirtualAlbum" /> property is set to true. If the roles do not provide permission to any
		/// objects in the gallery, then a virtual album is returned where <see cref="IAlbum.IsVirtualAlbum" />=<c>true</c> and 
		/// <see cref="IGalleryObject.Id" />=<see cref="Int32.MinValue" />. Returns null if no matching albums are found.
		/// </summary>
		/// <param name="galleryId">The gallery ID.</param>
		/// <param name="roles">The roles belonging to a user.</param>
		/// <param name="isAuthenticated">Indicates whether the user belonging to the <paramref name="roles" /> is authenticated.</param>
		/// <returns>
		/// Returns an <see cref="IAlbum" /> that is or contains the top-level album(s) that the <paramref name = "roles" />
		/// provide view permission for. Returns null if no matching albums are found.
		/// </returns>
		public static IAlbum LoadRootAlbum(int galleryId, IGalleryServerRoleCollection roles, bool isAuthenticated)
		{
			var galleryObjectSearcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions()
			{
				GalleryId = galleryId,
				SearchType = GalleryObjectSearchType.HighestAlbumUserCanView,
				Roles = roles,
				IsUserAuthenticated = isAuthenticated,
				Filter = GalleryObjectType.Album
			});

			return galleryObjectSearcher.FindOne() as IAlbum;
		}