Example #1
0
        public static IGalleryServerRoleCollection GetGalleryServerRoles(bool includeOwnerRoles)
        {
            if (includeOwnerRoles)
            {
                return(Factory.LoadGalleryServerRoles());
            }
            else
            {
                IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

                foreach (IGalleryServerRole role in Factory.LoadGalleryServerRoles())
                {
                    if (!IsRoleAnAlbumOwnerRole(role.RoleName))
                    {
                        roles.Add(role);
                    }
                }

                return(roles);
            }
        }
Example #2
0
		public static IGalleryServerRoleCollection GetGalleryServerRoles(bool includeOwnerRoles)
		{
			if (includeOwnerRoles)
			{
				return Factory.LoadGalleryServerRoles();
			}			
			else
			{
				IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

				foreach (IGalleryServerRole role in Factory.LoadGalleryServerRoles())
				{
					if (!IsRoleAnAlbumOwnerRole(role.RoleName))
					{
						roles.Add(role);
					}
				}

				return roles;
			}
		}
Example #3
0
        private static IGalleryServerRoleCollection GetRolesFromRoleDtos(IEnumerable<RoleDto> roleDtos)
        {
            IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

            foreach (RoleDto roleDto in roleDtos)
            {
                IGalleryServerRole role = new GalleryServerRole(
                    roleDto.RoleName,
                    roleDto.AllowViewAlbumsAndObjects,
                    roleDto.AllowViewOriginalImage,
                    roleDto.AllowAddMediaObject,
                    roleDto.AllowAddChildAlbum,
                    roleDto.AllowEditMediaObject,
                    roleDto.AllowEditAlbum,
                    roleDto.AllowDeleteMediaObject,
                    roleDto.AllowDeleteChildAlbum,
                    roleDto.AllowSynchronize,
                    roleDto.AllowAdministerSite,
                    roleDto.AllowAdministerGallery,
                    roleDto.HideWatermark);

                role.RootAlbumIds.AddRange(from r in roleDto.RoleAlbums select r.FKAlbumId);

                roles.Add(role);
            }

            return roles;
        }
Example #4
0
        /// <summary>
        /// Gets the list of roles the user has permission to view. Users who have administer site permission can view all roles.
        /// Users with administer gallery permission can only view roles they have been associated with or roles that aren't 
        /// associated with *any* gallery, unless the application setting <see cref="IAppSetting.AllowGalleryAdminToViewAllUsersAndRoles" />
        /// is true, in which case they can see all roles.
        /// </summary>
        /// <param name="userIsSiteAdmin">If set to <c>true</c>, the currently logged on user is a site administrator.</param>
        /// <param name="userIsGalleryAdmin">If set to <c>true</c>, the currently logged on user is a gallery administrator for the current gallery.</param>
        /// <returns>Returns an <see cref="IGalleryServerRoleCollection" /> containing a list of roles the user has permission to view.</returns>
        public static IGalleryServerRoleCollection GetRolesCurrentUserCanView(bool userIsSiteAdmin, bool userIsGalleryAdmin)
        {
            if (userIsSiteAdmin || (userIsGalleryAdmin && AppSetting.Instance.AllowGalleryAdminToViewAllUsersAndRoles))
            {
                return RoleController.GetGalleryServerRoles();
            }
            else if (userIsGalleryAdmin)
            {
                IGalleryServerRoleCollection roles = RoleController.GetGalleryServerRoles();
                IGalleryServerRoleCollection filteredRoles = new GalleryServerRoleCollection();

                // Build up a list of roles where (1) the current user is a gallery admin for at least one gallery,
                // (2) the role is an album owner template role and the current user is a gallery admin for its associated gallery, or
                // (3) the role isn't associated with any albums/galleries.
                foreach (IGalleryServerRole role in roles)
                {
                    if (role.Galleries.Count > 0)
                    {
                        if (IsUserGalleryAdminForRole(role))
                        {
                            // Current user has gallery admin permissions for at least one galley associated with the role.
                            filteredRoles.Add(role);
                        }
                    }
                    else if (IsRoleAnAlbumOwnerTemplateRole(role.RoleName))
                    {
                        if (IsUserGalleryAdminForAlbumOwnerTemplateRole(role))
                        {
                            // The role is an album owner template role and the current user is a gallery admin for it's associated gallery.
                            filteredRoles.Add(role);
                        }
                    }
                    else
                    {
                        // Role isn't an album owner role and it isn't assigned to any albums. Add it.
                        filteredRoles.Add(role);
                    }
                }

                return filteredRoles;
            }
            else
            {
                return new GalleryServerRoleCollection();
            }
        }
Example #5
0
        /// <summary>
        /// Gets all the gallery server roles that apply to the specified <paramref name="gallery" />.
        /// </summary>
        /// <param name="gallery">The gallery.</param>
        /// <returns>Returns an <see cref="IGalleryServerRoleCollection"/> representing the roles that apply to the specified 
        /// <paramref name="gallery" />.</returns>
        public static IGalleryServerRoleCollection GetGalleryServerRolesForGallery(IGallery gallery)
        {
            IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

            foreach (IGalleryServerRole role in GetGalleryServerRoles())
            {
                if (role.Galleries.Contains(gallery) && (!roles.Contains(role)))
                {
                    roles.Add(role);
                }
            }

            return roles;
        }
Example #6
0
		/// <summary>
		/// Get all Gallery Server roles for the current gallery.
		/// </summary>
		/// <returns>Returns all Gallery Server roles for the current gallery.</returns>
		private static IGalleryServerRoleCollection GetGalleryServerRolesFromDataStore()
		{
			IGalleryServerRoleCollection roles = null;

			IDataReader dr = null;
			try
			{
				using (dr = Factory.GetDataProvider().Roles_GetDataReaderRoles())
				{
					// Create the roles.
					roles = GetRolesFromDataReader(dr);
				}

				if (roles == null)
				{
					roles = new GalleryServerRoleCollection();
				}

				#region Add complete album list

				// Add the entire list of albums that are affected by this role.
				foreach (IGalleryServerRole role in roles)
				{
					using (dr = Factory.GetDataProvider().Roles_GetDataReaderRoleAllAlbums(role.RoleName))
					{
						// Contains one field - "AlbumId"
						while (dr.Read())
						{
							role.AddToAllAlbumIds(dr.GetInt32(0));
						}
					}
				}

				#endregion

				#region Add top level albums

				// Add the list of top level albums that are affected by this role.
				foreach (IGalleryServerRole role in roles)
				{
					using (dr = Factory.GetDataProvider().Roles_GetDataReaderRoleRootAlbums(role.RoleName))
					{
						// Contains one field - "FKAlbumId"
						//SELECT gs_Role_Album.FKAlbumId
						//FROM gs_Role_Album INNER JOIN gs_Album ON gs_Role_Album.FKAlbumId = gs_Album.AlbumID
						//WHERE (gs_Role_Album.FKRoleName = @RoleName) AND (gs_Album.FKGalleryID = @GalleryId)
						while (dr.Read())
						{
							role.RootAlbumIds.Add(dr.GetInt32(0));
						}
					}
				}

				#endregion

			}
			finally
			{
				if (dr != null) dr.Close();
			}

			return roles;
		}
Example #7
0
		private static IGalleryServerRoleCollection GetRolesFromDataReader(IDataReader dr)
		{
			IGalleryServerRoleCollection roles = new GalleryServerRoleCollection();

			//SELECT RoleName, AllowViewAlbumsAndObjects, AllowViewOriginalImage, AllowAddChildAlbum,
			//  AllowAddMediaObject, AllowEditAlbum, AllowEditMediaObject, AllowDeleteAlbum, 
			//  AllowDeleteChildAlbum, AllowDeleteMediaObject,	AllowSynchronize, HideWatermark, 
			//  AllowAdministerSite
			//FROM gs_Roles
			//WHERE (FKGalleryId = @GalleryId)
			while (dr.Read())
			{
				roles.Add(new GalleryServerRole(dr["RoleName"].ToString(),
				                                Convert.ToBoolean(dr["AllowViewAlbumsAndObjects"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowViewOriginalImage"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowAddMediaObject"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowAddChildAlbum"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowEditMediaObject"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowEditAlbum"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowDeleteMediaObject"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowDeleteChildAlbum"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowSynchronize"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["AllowAdministerSite"], CultureInfo.InvariantCulture),
				                                Convert.ToBoolean(dr["HideWatermark"], CultureInfo.InvariantCulture)));
			}

			return roles;
		}