/// <summary>
        /// Fill the treeview with all albums. All nodes representing albums for which the specified role has permission
        /// will be checked. If the overload that doesn't take a role parameter is used, then check all checkboxes if the
        /// isAdministratorChecked parameter is true.
        /// </summary>
        /// <param name="role">The role to be updated. If adding a new role, then set this parameter to null.</param>
        /// <param name="isAdministrator">Indicates whether the administrator permission checkbox has been
        /// checked or the specified role has administrative permission. Since administrative permission applies to all
        /// albums, when this parameter is true, all checkboxes for all albums will be checked. An exception is thrown
        /// if the role.AllowAdministerSite property and the isAdministrator parameter do not match.</param>
        private void BindAlbumTreeview(IGalleryServerRole role, bool isAdministrator)
        {
            if ((role != null) && (role.AllowAdministerSite != isAdministrator))
            {
                throw new ArgumentException("Invalid arguments passed to BindAlbumTreeview method: The role.AllowAdministerSite property and the isAdministrator parameter must match.");
            }

            if (role != null)             // Role will be null when user is adding a new role
            {
                IIntegerCollection albumIds = tvUC.AlbumIdsToCheck;
                albumIds.Clear();
                albumIds.AddRange(role.RootAlbumIds);

                foreach (IGallery gallery in Factory.LoadGalleries())
                {
                    IAlbum rootAlbum = Factory.LoadRootAlbumInstance(gallery.GalleryId);

                    if (role.RootAlbumIds.Contains(rootAlbum.Id))
                    {
                        // The role applies to all albums. Since the treeview initially renders to two levels, we need
                        // to add the album IDs for the root album's child albums.
                        foreach (IGalleryObject album in rootAlbum.GetChildGalleryObjects(GalleryObjectType.Album))
                        {
                            albumIds.Add(album.Id);
                        }
                    }
                }
            }

            tvUC.RequiredSecurityPermissions = SecurityActions.AdministerSite | SecurityActions.AdministerGallery;
            tvUC.Galleries       = Factory.LoadGalleries();
            tvUC.RootAlbumPrefix = String.Concat(Resources.GalleryServerPro.Site_Gallery_Text, " '{GalleryDescription}': ");
            tvUC.BindTreeView();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fill the treeview with all albums. All nodes representing albums for which the specified role has permission
        /// will be checked. If the overload that doesn't take a role parameter is used, then check all checkboxes if the
        /// isAdministratorChecked parameter is true.
        /// </summary>
        /// <param name="role">The role to be updated. If adding a new role, then set this parameter to null.</param>
        /// <param name="isAdministrator">Indicates whether the administrator permission checkbox has been
        /// checked or the specified role has administrative permission. Since administrative permission applies to all
        /// albums, when this parameter is true, all checkboxes for all albums will be checked. An exception is thrown
        /// if the role.AllowAdministerSite property and the isAdministrator parameter do not match.</param>
        private void BindAlbumTreeview(IGalleryServerRole role, bool isAdministrator)
        {
            if ((role != null) && (role.AllowAdministerSite != isAdministrator))
            {
                throw new ArgumentException("Invalid arguments passed to BindAlbumTreeview method: The role.AllowAdministerSite property and the isAdministrator parameter must match.");
            }

            if (role != null)             // Role will be null when user is adding a new role
            {
                IIntegerCollection albumIds = tvUC.AlbumIdsToSelect;
                albumIds.Clear();
                albumIds.AddRange(role.RootAlbumIds);

                if (role.RootAlbumIds.Contains(Factory.LoadRootAlbumInstance().Id))
                {
                    // The role applies to all albums. Since the treeview initially renders to two levels, we need
                    // to add the album IDs for the root album's child albums.
                    foreach (IGalleryObject album in Factory.LoadRootAlbumInstance().GetChildGalleryObjects(GalleryObjectType.Album))
                    {
                        albumIds.Add(album.Id);
                    }
                }
            }

            tvUC.BindTreeView();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add the list of integers to the collection.
 /// </summary>
 /// <param name="values">A list of integers to add to the collection.</param>
 public void AddRange(IIntegerCollection values)
 {
     foreach (int value in values)
     {
         Items.Add(value);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Replace the list of root album IDs for the <paramref name="role"/> with the album ID's specified in
        /// <paramref name="topLevelCheckedAlbumIds"/>. Note that this function will cause the AllAlbumIds property
        /// to be cleared out (Count = 0). The property can be repopulated by calling <see cref="IGalleryServerRole.Save"/>.
        /// </summary>
        /// <param name="role">The role whose root album/role relationships should be updated. When editing
        /// an existing role, specify this.GalleryRole. For new roles, pass the newly created role before
        /// saving it.</param>
        /// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
        public static void UpdateRoleAlbumRelationships(IGalleryServerRole role, IIntegerCollection topLevelCheckedAlbumIds)
        {
            if (role == null)
            {
                throw new ArgumentNullException("role");
            }

            if (topLevelCheckedAlbumIds == null)
            {
                topLevelCheckedAlbumIds = new IntegerCollection();
            }

            int[] rootAlbumIdsOld = new int[role.RootAlbumIds.Count];
            role.RootAlbumIds.CopyTo(rootAlbumIdsOld, 0);

            role.RootAlbumIds.Clear();

            if (role.AllowAdministerSite)
            {
                // Administer site permission automatically applies to all albums, so all we need to do is get
                // a reference to the root album ID.
                role.RootAlbumIds.Add(Factory.LoadRootAlbumInstance().Id);
            }
            else
            {
                role.RootAlbumIds.AddRange(topLevelCheckedAlbumIds);
            }

            if (IsRoleAnAlbumOwnerRole(role.RoleName))
            {
                ValidateAlbumOwnerRoles(role.RoleName, rootAlbumIdsOld, role.RootAlbumIds);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the specified <paramref name="rootAlbumIds" /> to the UI template having <paramref name="uiTemplateId" />.
        /// </summary>
        /// <param name="uiTemplateId">The UI template identifier.</param>
        /// <param name="rootAlbumIds">The root album ids.</param>
        public void Save(int uiTemplateId, IIntegerCollection rootAlbumIds)
        {
            // Step 1: Copy the list of root album IDs to a new list. We'll be removing items from the list as we process them,
            // so we don't want to mess with the actual list attached to the object.
            var templateAlbumRelationshipsToPersist = new List <int>();

            foreach (var albumId in rootAlbumIds)
            {
                templateAlbumRelationshipsToPersist.Add(albumId);
            }

            // Step 2: Iterate through each template/album relationship in the data store. If it is in our list, then
            // remove it (see step 4 why). If not, the user must have unchecked it so add it to a list of
            // relationships to be deleted.
            var templateAlbumRelationshipsToDelete = new List <int>();

            foreach (var albumId in Where(j => j.FKUiTemplateId == uiTemplateId).Select(j => j.FKAlbumId))
            {
                if (templateAlbumRelationshipsToPersist.Contains(albumId))
                {
                    templateAlbumRelationshipsToPersist.Remove(albumId);
                }
                else
                {
                    templateAlbumRelationshipsToDelete.Add(albumId);
                }
            }

            // Step 3: Delete the records we accumulated in our list.
            foreach (UiTemplateAlbumDto roleAlbumDto in Where(j => j.FKUiTemplateId == uiTemplateId && templateAlbumRelationshipsToDelete.Contains(j.FKAlbumId)))
            {
                Delete(roleAlbumDto);
            }

            // Step 4: Any items still left in the templateAlbumRelationshipsToPersist list must be new ones
            // checked by the user. Add them.
            foreach (int albumId in templateAlbumRelationshipsToPersist)
            {
                Add(new UiTemplateAlbumDto {
                    FKUiTemplateId = uiTemplateId, FKAlbumId = albumId
                });
            }

            Save();
        }
Exemplo n.º 6
0
        }                                       // Hide default constructor

        /// <summary>
        /// Create a GalleryServerRole instance corresponding to the specified parameters. Throws an exception if a role with the
        /// specified name already exists in the data store.
        /// </summary>
        /// <param name="roleName">A string that uniquely identifies the role.</param>
        /// <param name="allowViewAlbumOrMediaObject">A value indicating whether the user assigned to this role has permission to view albums
        /// and media objects.</param>
        /// <param name="allowViewOriginalImage">A value indicating whether the user assigned to this role has permission to view the original,
        /// high resolution version of an image. This setting applies only to images. It has no effect if there are no
        /// high resolution images in the album or albums to which this role applies.</param>
        /// <param name="allowAddMediaObject">A value indicating whether the user assigned to this role has permission to add media objects to an album.</param>
        /// <param name="allowAddChildAlbum">A value indicating whether the user assigned to this role has permission to create child albums.</param>
        /// <param name="allowEditMediaObject">A value indicating whether the user assigned to this role has permission to edit a media object.</param>
        /// <param name="allowEditAlbum">A value indicating whether the user assigned to this role has permission to edit an album.</param>
        /// <param name="allowDeleteMediaObject">A value indicating whether the user assigned to this role has permission to delete media objects within an album.</param>
        /// <param name="allowDeleteChildAlbum">A value indicating whether the user assigned to this role has permission to delete child albums.</param>
        /// <param name="allowSynchronize">A value indicating whether the user assigned to this role has permission to synchronize an album.</param>
        /// <param name="allowAdministerSite">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums; it cannot be selectively applied.</param>
        /// <param name="hideWatermark">A value indicating whether the user assigned to this role has a watermark applied to images.
        /// This setting has no effect if watermarks are not used. A true value means the user does not see the watermark;
        /// a false value means the watermark is applied.</param>
        /// <returns>Returns a GalleryServerRole instance corresponding to the specified parameters.</returns>
        public GalleryServerRole(string roleName, bool allowViewAlbumOrMediaObject, bool allowViewOriginalImage, bool allowAddMediaObject, bool allowAddChildAlbum, bool allowEditMediaObject, bool allowEditAlbum, bool allowDeleteMediaObject, bool allowDeleteChildAlbum, bool allowSynchronize, bool allowAdministerSite, bool hideWatermark)
        {
            this._roleName = roleName;
            this._allowViewAlbumOrMediaObject = allowViewAlbumOrMediaObject;
            this._allowViewOriginalImage      = allowViewOriginalImage;
            this._allowAddMediaObject         = allowAddMediaObject;
            this._allowAddChildAlbum          = allowAddChildAlbum;
            this._allowEditMediaObject        = allowEditMediaObject;
            this._allowEditAlbum         = allowEditAlbum;
            this._allowDeleteMediaObject = allowDeleteMediaObject;
            this._allowDeleteChildAlbum  = allowDeleteChildAlbum;
            this._allowSynchronize       = allowSynchronize;
            this._allowAdministerSite    = allowAdministerSite;
            this._hideWatermark          = hideWatermark;

            this._rootAlbumIds          = new IntegerCollection();
            this._rootAlbumIds.Cleared += new EventHandler(_rootAlbumIds_Cleared);

            this._allAlbumIds = new IntegerCollection();
        }
        /// <summary>
        /// Create a GalleryServerRole instance corresponding to the specified parameters. Throws an exception if a role with the
        /// specified name already exists in the data store.
        /// </summary>
        /// <param name="roleName">A string that uniquely identifies the role.</param>
        /// <param name="allowViewAlbumOrMediaObject">A value indicating whether the user assigned to this role has permission to view albums
        /// and media objects.</param>
        /// <param name="allowViewOriginalImage">A value indicating whether the user assigned to this role has permission to view the original,
        /// high resolution version of an image. This setting applies only to images. It has no effect if there are no
        /// high resolution images in the album or albums to which this role applies.</param>
        /// <param name="allowAddMediaObject">A value indicating whether the user assigned to this role has permission to add media objects to an album.</param>
        /// <param name="allowAddChildAlbum">A value indicating whether the user assigned to this role has permission to create child albums.</param>
        /// <param name="allowEditMediaObject">A value indicating whether the user assigned to this role has permission to edit a media object.</param>
        /// <param name="allowEditAlbum">A value indicating whether the user assigned to this role has permission to edit an album.</param>
        /// <param name="allowDeleteMediaObject">A value indicating whether the user assigned to this role has permission to delete media objects within an album.</param>
        /// <param name="allowDeleteChildAlbum">A value indicating whether the user assigned to this role has permission to delete child albums.</param>
        /// <param name="allowSynchronize">A value indicating whether the user assigned to this role has permission to synchronize an album.</param>
        /// <param name="allowAdministerSite">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums across all galleries; it cannot be selectively applied.</param>
        /// <param name="allowAdministerGallery">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums in a particular gallery; it cannot be selectively applied.</param>
        /// <param name="hideWatermark">A value indicating whether the user assigned to this role has a watermark applied to images.
        /// This setting has no effect if watermarks are not used. A true value means the user does not see the watermark;
        /// a false value means the watermark is applied.</param>
        /// <returns>Returns a GalleryServerRole instance corresponding to the specified parameters.</returns>
        internal GalleryServerRole(string roleName, bool allowViewAlbumOrMediaObject, bool allowViewOriginalImage, bool allowAddMediaObject, bool allowAddChildAlbum, bool allowEditMediaObject, bool allowEditAlbum, bool allowDeleteMediaObject, bool allowDeleteChildAlbum, bool allowSynchronize, bool allowAdministerSite, bool allowAdministerGallery, bool hideWatermark)
        {
            this._roleName = roleName;
            this._allowViewAlbumOrMediaObject = allowViewAlbumOrMediaObject;
            this._allowViewOriginalImage = allowViewOriginalImage;
            this._allowAddMediaObject = allowAddMediaObject;
            this._allowAddChildAlbum = allowAddChildAlbum;
            this._allowEditMediaObject = allowEditMediaObject;
            this._allowEditAlbum = allowEditAlbum;
            this._allowDeleteMediaObject = allowDeleteMediaObject;
            this._allowDeleteChildAlbum = allowDeleteChildAlbum;
            this._allowSynchronize = allowSynchronize;
            this._allowAdministerSite = allowAdministerSite;
            this._allowAdministerGallery = allowAdministerGallery;
            this._hideWatermark = hideWatermark;

            this._galleries = new GalleryCollection();

            this._rootAlbumIds = new IntegerCollection();
            this._rootAlbumIds.Cleared += new EventHandler(_rootAlbumIds_Cleared);

            this._allAlbumIds = new IntegerCollection();
        }
Exemplo n.º 8
0
		/// <summary>
		/// Replace the list of root album IDs for the <paramref name="role"/> with the album ID's specified in
		/// <paramref name="topLevelCheckedAlbumIds"/>. Note that this function will cause the AllAlbumIds property 
		/// to be cleared out (Count = 0). The property can be repopulated by calling <see cref="IGalleryServerRole.Save"/>.
		/// </summary>
		/// <param name="role">The role whose root album/role relationships should be updated. When editing
		/// an existing role, specify this.GalleryRole. For new roles, pass the newly created role before
		/// saving it.</param>
		/// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
		public static void UpdateRoleAlbumRelationships(IGalleryServerRole role, IIntegerCollection topLevelCheckedAlbumIds)
		{
			if (role == null)
				throw new ArgumentNullException("role");

			if (topLevelCheckedAlbumIds == null)
				topLevelCheckedAlbumIds = new IntegerCollection();

			int[] rootAlbumIdsOld = new int[role.RootAlbumIds.Count];
			role.RootAlbumIds.CopyTo(rootAlbumIdsOld, 0);

			role.RootAlbumIds.Clear();

			if (role.AllowAdministerSite)
			{
				// Administer site permission automatically applies to all albums, so all we need to do is get
				// a reference to the root album ID.
				role.RootAlbumIds.Add(Factory.LoadRootAlbumInstance().Id);
			}
			else
			{
				role.RootAlbumIds.AddRange(topLevelCheckedAlbumIds);
			}

			if (IsRoleAnAlbumOwnerRole(role.RoleName))
				ValidateAlbumOwnerRoles(role.RoleName, rootAlbumIdsOld, role.RootAlbumIds);
		}
Exemplo n.º 9
0
		/// <summary>
		/// Create a Gallery Server Pro role corresponding to the specified parameters. Also creates the corresponding ASP.NET role.
		/// Throws an exception if a role with the specified name already exists in the data store. The role is persisted to the data store.
		/// </summary>
		/// <param name="roleName">A string that uniquely identifies the role.</param>
		/// <param name="allowViewAlbumOrMediaObject">A value indicating whether the user assigned to this role has permission to view albums
		/// and media objects.</param>
		/// <param name="allowViewOriginalImage">A value indicating whether the user assigned to this role has permission to view the original,
		/// high resolution version of an image. This setting applies only to images. It has no effect if there are no
		/// high resolution images in the album or albums to which this role applies.</param>
		/// <param name="allowAddMediaObject">A value indicating whether the user assigned to this role has permission to add media objects to an album.</param>
		/// <param name="allowAddChildAlbum">A value indicating whether the user assigned to this role has permission to create child albums.</param>
		/// <param name="allowEditMediaObject">A value indicating whether the user assigned to this role has permission to edit a media object.</param>
		/// <param name="allowEditAlbum">A value indicating whether the user assigned to this role has permission to edit an album.</param>
		/// <param name="allowDeleteMediaObject">A value indicating whether the user assigned to this role has permission to delete media objects within an album.</param>
		/// <param name="allowDeleteChildAlbum">A value indicating whether the user assigned to this role has permission to delete child albums.</param>
		/// <param name="allowSynchronize">A value indicating whether the user assigned to this role has permission to synchronize an album.</param>
		/// <param name="allowAdministerSite">A value indicating whether the user has administrative permission for all albums. This permission
		/// automatically applies to all albums; it cannot be selectively applied.</param>
		/// <param name="hideWatermark">A value indicating whether the user assigned to this role has a watermark applied to images.
		/// This setting has no effect if watermarks are not used. A true value means the user does not see the watermark;
		/// a false value means the watermark is applied.</param>
		/// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
		/// <returns>Returns an <see cref="IGalleryServerRole" /> object corresponding to the specified parameters.</returns>
		/// <exception cref="InvalidGalleryServerRoleException">Thrown when a role with the specified role name already exists in the data store.</exception>
		public static IGalleryServerRole CreateRole(string roleName, bool allowViewAlbumOrMediaObject, bool allowViewOriginalImage, bool allowAddMediaObject, bool allowAddChildAlbum, bool allowEditMediaObject, bool allowEditAlbum, bool allowDeleteMediaObject, bool allowDeleteChildAlbum, bool allowSynchronize, bool allowAdministerSite, bool hideWatermark, IIntegerCollection topLevelCheckedAlbumIds)
		{
			CreateRole(roleName);

			IGalleryServerRole role = Factory.CreateGalleryServerRoleInstance(roleName, allowViewAlbumOrMediaObject, allowViewOriginalImage, allowAddMediaObject, allowAddChildAlbum, allowEditMediaObject, allowEditAlbum, allowDeleteMediaObject, allowDeleteChildAlbum, allowSynchronize, allowAdministerSite, hideWatermark);

			UpdateRoleAlbumRelationships(role, topLevelCheckedAlbumIds);

			role.Save();

			return role;
		}
Exemplo n.º 10
0
        /// <summary>
        /// Persist the <paramref name="roleToSave" /> to the data store, associating any album IDs listed in <paramref name="topLevelCheckedAlbumIds" />
        /// with it. Prior to saving, validation is performed and a <see cref="GallerySecurityException" /> is thrown if a business rule
        /// is violated.
        /// </summary>
        /// <param name="roleToSave">The role to save.</param>
        /// <param name="topLevelCheckedAlbumIds">The top level album IDs. May be null.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="roleToSave" /> is null.</exception>
        /// <exception cref="GallerySecurityException">Thrown when the role cannot be saved because doing so would violate a business rule.</exception>
        /// <exception cref="InvalidGalleryServerRoleException">Thrown when an existing role cannot be found in the database that matches the 
        /// role name of the <paramref name="roleToSave" /> parameter.</exception>
        public static void Save(IGalleryServerRole roleToSave, IIntegerCollection topLevelCheckedAlbumIds)
        {
            if (roleToSave == null)
                throw new ArgumentNullException("roleToSave");

            ValidateSaveRole(roleToSave);

            UpdateRoleAlbumRelationships(roleToSave, topLevelCheckedAlbumIds);

            roleToSave.Save();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a Gallery Server Pro role corresponding to the specified parameters. Also creates the corresponding ASP.NET role.
        /// Throws an exception if a role with the specified name already exists in the data store. The role is persisted to the data store.
        /// </summary>
        /// <param name="roleName">A string that uniquely identifies the role.</param>
        /// <param name="allowViewAlbumOrMediaObject">A value indicating whether the user assigned to this role has permission to view albums
        /// and media objects.</param>
        /// <param name="allowViewOriginalImage">A value indicating whether the user assigned to this role has permission to view the original,
        /// high resolution version of an image. This setting applies only to images. It has no effect if there are no
        /// high resolution images in the album or albums to which this role applies.</param>
        /// <param name="allowAddMediaObject">A value indicating whether the user assigned to this role has permission to add media objects to an album.</param>
        /// <param name="allowAddChildAlbum">A value indicating whether the user assigned to this role has permission to create child albums.</param>
        /// <param name="allowEditMediaObject">A value indicating whether the user assigned to this role has permission to edit a media object.</param>
        /// <param name="allowEditAlbum">A value indicating whether the user assigned to this role has permission to edit an album.</param>
        /// <param name="allowDeleteMediaObject">A value indicating whether the user assigned to this role has permission to delete media objects within an album.</param>
        /// <param name="allowDeleteChildAlbum">A value indicating whether the user assigned to this role has permission to delete child albums.</param>
        /// <param name="allowSynchronize">A value indicating whether the user assigned to this role has permission to synchronize an album.</param>
        /// <param name="allowAdministerSite">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums across all galleries; it cannot be selectively applied.</param>
        /// <param name="allowAdministerGallery">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums in a particular gallery; it cannot be selectively applied.</param>
        /// <param name="hideWatermark">A value indicating whether the user assigned to this role has a watermark applied to images.
        /// This setting has no effect if watermarks are not used. A true value means the user does not see the watermark;
        /// a false value means the watermark is applied.</param>
        /// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
        /// <returns>
        /// Returns an <see cref="IGalleryServerRole"/> object corresponding to the specified parameters.
        /// </returns>
        /// <exception cref="InvalidGalleryServerRoleException">Thrown when a role with the specified role name already exists in the data store.</exception>
        public static IGalleryServerRole CreateRole(string roleName, bool allowViewAlbumOrMediaObject, bool allowViewOriginalImage, bool allowAddMediaObject, bool allowAddChildAlbum, bool allowEditMediaObject, bool allowEditAlbum, bool allowDeleteMediaObject, bool allowDeleteChildAlbum, bool allowSynchronize, bool allowAdministerSite, bool allowAdministerGallery, bool hideWatermark, IIntegerCollection topLevelCheckedAlbumIds)
        {
            lock (_sharedLock)
            {
                var uniqueRoleName = MakeRoleNameUnique(roleName);

                // Create the ASP.NET role.
                CreateRole(uniqueRoleName);

                // Create the Gallery Server Pro role that extends the functionality of the ASP.NET role.
                IGalleryServerRole role = Factory.CreateGalleryServerRoleInstance(uniqueRoleName, allowViewAlbumOrMediaObject, allowViewOriginalImage, allowAddMediaObject, allowAddChildAlbum, allowEditMediaObject, allowEditAlbum, allowDeleteMediaObject, allowDeleteChildAlbum, allowSynchronize, allowAdministerSite, allowAdministerGallery, hideWatermark);

                UpdateRoleAlbumRelationships(role, topLevelCheckedAlbumIds);

                ValidateSaveRole(role);

                role.Save();

                return role;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Replace the list of root album IDs for the <paramref name="role"/> with the album ID's specified in
        /// <paramref name="topLevelCheckedAlbumIds"/>. Note that this function will cause the AllAlbumIds property 
        /// to be cleared out (Count = 0). The property can be repopulated by calling <see cref="IGalleryServerRole.Save"/>.
        /// </summary>
        /// <param name="role">The role whose root album/role relationships should be updated. When editing
        /// an existing role, specify this.GalleryRole. For new roles, pass the newly created role before
        /// saving it.</param>
        /// <param name="topLevelCheckedAlbumIds">The top level album IDs. May be null.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="role" /> is null.</exception>
        private static void UpdateRoleAlbumRelationships(IGalleryServerRole role, IIntegerCollection topLevelCheckedAlbumIds)
        {
            if (role == null)
                throw new ArgumentNullException("role");

            if (topLevelCheckedAlbumIds == null)
                topLevelCheckedAlbumIds = new IntegerCollection();

            int[] rootAlbumIdsOld = new int[role.RootAlbumIds.Count];
            role.RootAlbumIds.CopyTo(rootAlbumIdsOld, 0);

            role.RootAlbumIds.Clear();

            if (role.AllowAdministerSite)
            {
                // Administer site permission automatically applies to all albums, so all we need to do is get
                // a reference to the root album ID in each gallery.
                foreach (IGallery gallery in role.Galleries)
                {
                    role.RootAlbumIds.Add(Factory.LoadRootAlbumInstance(gallery.GalleryId).Id);
                }
            }
            else if (role.AllowAdministerGallery)
            {
                // Administer gallery permission automatically applies to all albums in a gallery, so get a reference
                // to the root album for each checked album ID.
                foreach (int albumId in topLevelCheckedAlbumIds)
                {
                    IAlbum album = AlbumController.LoadAlbumInstance(albumId, false);

                    while (!(album.Parent is GalleryServerPro.Business.NullObjects.NullGalleryObject))
                    {
                        album = (IAlbum)album.Parent;
                    }

                    if (!role.RootAlbumIds.Contains(album.Id))
                    {
                        role.RootAlbumIds.Add(album.Id);
                    }
                }
            }
            else
            {
                role.RootAlbumIds.AddRange(topLevelCheckedAlbumIds);
            }

            if (IsRoleAnAlbumOwnerRole(role.RoleName))
                ValidateAlbumOwnerRoles(role.RoleName, rootAlbumIdsOld, role.RootAlbumIds);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Create a Gallery Server Pro role corresponding to the specified parameters. Also creates the corresponding ASP.NET role.
        /// Throws an exception if a role with the specified name already exists in the data store. The role is persisted to the data store.
        /// </summary>
        /// <param name="roleName">A string that uniquely identifies the role.</param>
        /// <param name="allowViewAlbumOrMediaObject">A value indicating whether the user assigned to this role has permission to view albums
        /// and media objects.</param>
        /// <param name="allowViewOriginalImage">A value indicating whether the user assigned to this role has permission to view the original,
        /// high resolution version of an image. This setting applies only to images. It has no effect if there are no
        /// high resolution images in the album or albums to which this role applies.</param>
        /// <param name="allowAddMediaObject">A value indicating whether the user assigned to this role has permission to add media objects to an album.</param>
        /// <param name="allowAddChildAlbum">A value indicating whether the user assigned to this role has permission to create child albums.</param>
        /// <param name="allowEditMediaObject">A value indicating whether the user assigned to this role has permission to edit a media object.</param>
        /// <param name="allowEditAlbum">A value indicating whether the user assigned to this role has permission to edit an album.</param>
        /// <param name="allowDeleteMediaObject">A value indicating whether the user assigned to this role has permission to delete media objects within an album.</param>
        /// <param name="allowDeleteChildAlbum">A value indicating whether the user assigned to this role has permission to delete child albums.</param>
        /// <param name="allowSynchronize">A value indicating whether the user assigned to this role has permission to synchronize an album.</param>
        /// <param name="allowAdministerSite">A value indicating whether the user has administrative permission for all albums. This permission
        /// automatically applies to all albums; it cannot be selectively applied.</param>
        /// <param name="hideWatermark">A value indicating whether the user assigned to this role has a watermark applied to images.
        /// This setting has no effect if watermarks are not used. A true value means the user does not see the watermark;
        /// a false value means the watermark is applied.</param>
        /// <param name="topLevelCheckedAlbumIds">The top level checked album ids. May be null.</param>
        /// <returns>Returns an <see cref="IGalleryServerRole" /> object corresponding to the specified parameters.</returns>
        /// <exception cref="InvalidGalleryServerRoleException">Thrown when a role with the specified role name already exists in the data store.</exception>
        public static IGalleryServerRole CreateRole(string roleName, bool allowViewAlbumOrMediaObject, bool allowViewOriginalImage, bool allowAddMediaObject, bool allowAddChildAlbum, bool allowEditMediaObject, bool allowEditAlbum, bool allowDeleteMediaObject, bool allowDeleteChildAlbum, bool allowSynchronize, bool allowAdministerSite, bool hideWatermark, IIntegerCollection topLevelCheckedAlbumIds)
        {
            CreateRole(roleName);

            IGalleryServerRole role = Factory.CreateGalleryServerRoleInstance(roleName, allowViewAlbumOrMediaObject, allowViewOriginalImage, allowAddMediaObject, allowAddChildAlbum, allowEditMediaObject, allowEditAlbum, allowDeleteMediaObject, allowDeleteChildAlbum, allowSynchronize, allowAdministerSite, hideWatermark);

            UpdateRoleAlbumRelationships(role, topLevelCheckedAlbumIds);

            role.Save();

            return(role);
        }