private TreeView GenerateTreeview()
        {
            var tvOptions = new Entity.TreeViewOptions()
            {
                AlbumId                     = _albumId,
                SelectedAlbumIds            = _albumIdsToSelect,
                NumberOfLevels              = _numberOfLevels,
                EnableCheckboxPlugin        = _showCheckbox,
                IncludeAlbum                = _includeAlbum,
                NavigateUrl                 = _navigateUrl,
                RequiredSecurityPermissions = _securityAction,
                RootNodesPrefix             = RootNodesPrefix,
                Galleries                   = (_albumId > 0 ? null : _galleries)
            };

            return(AlbumTreeViewBuilder.GetAlbumsAsTreeView(tvOptions));
        }
Example #2
0
        private string GetAlbumTreeDataAsJson()
        {
            var tvOptions = new Entity.TreeViewOptions()
            {
                SelectedAlbumIds = (GetAlbumId() > int.MinValue ? new IntegerCollection(new int[] { GetAlbumId() }) : new IntegerCollection()),
                NavigateUrl = GalleryControl.TreeViewNavigateUrl ?? Utils.GetCurrentPageUrl(),
                EnableCheckboxPlugin = false,
                RequiredSecurityPermissions = SecurityActions.ViewAlbumOrMediaObject,
                RootAlbumPrefix = String.Empty,
                Galleries = new GalleryCollection() { Factory.LoadGallery(GalleryId) }
            };

            Entity.TreeView tv = AlbumTreeViewBuilder.GetAlbumsAsTreeView(tvOptions);

            return tv.ToJson().JsEncode();
        }
Example #3
0
        /// <summary>
        /// Gets a role entity corresponding to <paramref name="roleName" />. If the role does not exist, an instance with 
        /// a set of default values is returned that can be used to create a new role. The instance can be serialized to JSON and
        /// subsequently used in the browser as a data object. A <see cref="GallerySecurityException" /> is thrown if the current
        /// user doesn't have permission to view the role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <returns>Returns an <see cref="Entity.Role" /> instance.</returns>
        /// <exception cref="GallerySecurityException">Thrown when the current user does not have permission to view the role.</exception>
        public static Entity.Role GetRoleEntity(string roleName)
        {
            var role = Factory.LoadGalleryServerRole(roleName, true);

            // Throw exception if user can't view role. Note that GSP doesn't differentiate between permission to view and permission to
            // edit, so we use the UserCanEditRole function, even though we are just getting a role, not editing it.
            if (role != null && !UserCanViewRole(role))
                throw new GallerySecurityException("Insufficient permission to view role.");

            Entity.Role r = new Entity.Role();
            Entity.Permissions p = new Entity.Permissions();

            if (role != null)
            {
                r.Name = role.RoleName;
                r.IsNew = false;
                r.IsOwner = (IsRoleAnAlbumOwnerRole(r.Name) || IsRoleAnAlbumOwnerTemplateRole(r.Name));
                p.ViewAlbumOrMediaObject = role.AllowViewAlbumOrMediaObject;
                p.ViewOriginalMediaObject = role.AllowViewOriginalImage;
                p.AddChildAlbum = role.AllowAddChildAlbum;
                p.AddMediaObject = role.AllowAddMediaObject;
                p.EditAlbum = role.AllowEditAlbum;
                p.EditMediaObject = role.AllowEditMediaObject;
                p.DeleteAlbum = false; // This permission exists only in the context of a particular album and not as a stand-alone permission
                p.DeleteChildAlbum = role.AllowDeleteChildAlbum;
                p.DeleteMediaObject = role.AllowDeleteMediaObject;
                p.Synchronize = role.AllowSynchronize;
                p.AdministerGallery = role.AllowAdministerGallery;
                p.AdministerSite = role.AllowAdministerSite;
                p.HideWatermark = role.HideWatermark;
            }
            else
            {
                r.IsNew = true;
            }

            r.Permissions = p;
            IIntegerCollection rootAlbumIds = (role != null ? role.RootAlbumIds : new IntegerCollection());

            Entity.TreeViewOptions tvOptions = new Entity.TreeViewOptions()
            {
                EnableCheckboxPlugin = true,
                RequiredSecurityPermissions = SecurityActions.AdministerSite | SecurityActions.AdministerGallery,
                Galleries = Factory.LoadGalleries(),
                RootAlbumPrefix = String.Concat(Resources.GalleryServerPro.Site_Gallery_Text, " '{GalleryDescription}': "),
                SelectedAlbumIds = rootAlbumIds
            };

            Entity.TreeView tv = AlbumTreeViewBuilder.GetAlbumsAsTreeView(tvOptions);

            r.AlbumTreeDataJson = tv.ToJson();
            r.SelectedRootAlbumIds = rootAlbumIds.ToArray();

            r.Members = RoleController.GetUsersInRole(r.Name);

            return r;
        }