diff --git a/build.ps1 b/build.ps1 index 02179d21b7..fb22e7d4d3 100644 --- a/build.ps1 +++ b/build.ps1 @@ -10,7 +10,7 @@ param ( [string]$PackageSuffix, [string]$Branch, [string]$CommitSHA, - [string]$BuildBranch = '795fed66b8bae2d248237ee5ec82e688e7174a42' + [string]$BuildBranch = '5fd8377a9abf3ff411918dbb973948a6677432db' ) Set-StrictMode -Version 1.0 diff --git a/src/GalleryTools/Commands/BackfillRepositoryMetadataCommand.cs b/src/GalleryTools/Commands/BackfillRepositoryMetadataCommand.cs index a8a461e2a1..9e5a5999c7 100644 --- a/src/GalleryTools/Commands/BackfillRepositoryMetadataCommand.cs +++ b/src/GalleryTools/Commands/BackfillRepositoryMetadataCommand.cs @@ -17,6 +17,7 @@ using Microsoft.Extensions.CommandLineUtils; using NuGet.Packaging; using NuGet.Packaging.Core; +using NuGet.Services.Entities; using NuGet.Services.Search.Client; using NuGetGallery; using NuGetGallery.Configuration; @@ -447,7 +448,7 @@ public RepositoryMetadataLogMap() private class FileCursor : IDisposable { - private FileStream _fileStream; + private readonly FileStream _fileStream; private StreamWriter _cursorWriter; public FileCursor(string fileName) @@ -473,7 +474,7 @@ public void Dispose() public DateTime GetCursorTime() { - using (var reader = new StreamReader(_fileStream, Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize:100, leaveOpen: true)) + using (var reader = new StreamReader(_fileStream, Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize: 100, leaveOpen: true)) { reader.BaseStream.Seek(0, SeekOrigin.Begin); diff --git a/src/GalleryTools/Commands/HashCommand.cs b/src/GalleryTools/Commands/HashCommand.cs index 43f44870ed..8a7cdd94c2 100644 --- a/src/GalleryTools/Commands/HashCommand.cs +++ b/src/GalleryTools/Commands/HashCommand.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Autofac; using Microsoft.Extensions.CommandLineUtils; +using NuGet.Services.Entities; using NuGetGallery; using NuGetGallery.Configuration; using NuGetGallery.Infrastructure.Authentication; diff --git a/src/GalleryTools/Commands/VerifyApiKeyCommand.cs b/src/GalleryTools/Commands/VerifyApiKeyCommand.cs index 6bd68b2022..ae6de3bf72 100644 --- a/src/GalleryTools/Commands/VerifyApiKeyCommand.cs +++ b/src/GalleryTools/Commands/VerifyApiKeyCommand.cs @@ -4,6 +4,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.CommandLineUtils; +using NuGet.Services.Entities; using NuGetGallery; using NuGetGallery.Infrastructure.Authentication; diff --git a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackage.cs b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackage.cs index 08def17cda..98b84cc1e1 100644 --- a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackage.cs +++ b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackage.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using NuGet.Services.Entities; using NuGetGallery.Auditing.Obfuscation; namespace NuGetGallery.Auditing.AuditedEntities diff --git a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackageRegistration.cs b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackageRegistration.cs index 0245fe7177..bd43a2f1c0 100644 --- a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackageRegistration.cs +++ b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedPackageRegistration.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; + namespace NuGetGallery.Auditing.AuditedEntities { public class AuditedPackageRegistration diff --git a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedReservedNamespace.cs b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedReservedNamespace.cs index 2f3b54ea0b..92ae269bbf 100644 --- a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedReservedNamespace.cs +++ b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedReservedNamespace.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; + namespace NuGetGallery.Auditing.AuditedEntities { public class AuditedReservedNamespace diff --git a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedUserSecurityPolicy.cs b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedUserSecurityPolicy.cs index e300ab0169..949e44d16c 100644 --- a/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedUserSecurityPolicy.cs +++ b/src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedUserSecurityPolicy.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; + namespace NuGetGallery.Auditing.AuditedEntities { /// diff --git a/src/NuGetGallery.Core/Auditing/CredentialAuditRecord.cs b/src/NuGetGallery.Core/Auditing/CredentialAuditRecord.cs index df9fa1dbaa..af15da0cd2 100644 --- a/src/NuGetGallery.Core/Auditing/CredentialAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/CredentialAuditRecord.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using NuGet.Services.Entities; namespace NuGetGallery.Auditing { diff --git a/src/NuGetGallery.Core/Auditing/FailedAuthenticatedOperationAuditRecord.cs b/src/NuGetGallery.Core/Auditing/FailedAuthenticatedOperationAuditRecord.cs index ec0d768d64..409fe2d766 100644 --- a/src/NuGetGallery.Core/Auditing/FailedAuthenticatedOperationAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/FailedAuthenticatedOperationAuditRecord.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; using NuGetGallery.Auditing.AuditedEntities; namespace NuGetGallery.Auditing diff --git a/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs b/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs index 1cc20e0b68..c5eaaa6b80 100644 --- a/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; using NuGetGallery.Auditing.AuditedEntities; namespace NuGetGallery.Auditing diff --git a/src/NuGetGallery.Core/Auditing/PackageRegistrationAuditRecord.cs b/src/NuGetGallery.Core/Auditing/PackageRegistrationAuditRecord.cs index 40a3eb2821..bc7cc52537 100644 --- a/src/NuGetGallery.Core/Auditing/PackageRegistrationAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/PackageRegistrationAuditRecord.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using NuGet.Services.Entities; using NuGetGallery.Auditing.AuditedEntities; namespace NuGetGallery.Auditing diff --git a/src/NuGetGallery.Core/Auditing/ReservedNamespaceAuditRecord.cs b/src/NuGetGallery.Core/Auditing/ReservedNamespaceAuditRecord.cs index 3a99283356..2f0e0fd90d 100644 --- a/src/NuGetGallery.Core/Auditing/ReservedNamespaceAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/ReservedNamespaceAuditRecord.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Collections.Generic; using NuGetGallery.Auditing.AuditedEntities; +using NuGet.Services.Entities; namespace NuGetGallery.Auditing { diff --git a/src/NuGetGallery.Core/Auditing/UserAuditRecord.cs b/src/NuGetGallery.Core/Auditing/UserAuditRecord.cs index f6e7084684..0e3b828256 100644 --- a/src/NuGetGallery.Core/Auditing/UserAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/UserAuditRecord.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NuGet.Services.Entities; using NuGetGallery.Auditing.AuditedEntities; namespace NuGetGallery.Auditing diff --git a/src/NuGetGallery.Core/Auditing/UserSecurityPolicyAuditRecord.cs b/src/NuGetGallery.Core/Auditing/UserSecurityPolicyAuditRecord.cs index a923adeacd..9f2afe3089 100644 --- a/src/NuGetGallery.Core/Auditing/UserSecurityPolicyAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/UserSecurityPolicyAuditRecord.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NuGet.Services.Entities; using NuGetGallery.Auditing.AuditedEntities; namespace NuGetGallery.Auditing diff --git a/src/NuGetGallery.Core/CoreConstants.cs b/src/NuGetGallery.Core/CoreConstants.cs index bcf438a363..4c4b5c2091 100644 --- a/src/NuGetGallery.Core/CoreConstants.cs +++ b/src/NuGetGallery.Core/CoreConstants.cs @@ -7,8 +7,6 @@ public static class CoreConstants { public const string AdminRoleName = "Admins"; - public const int MaxPackageIdLength = 128; - public const string PackageFileSavePathTemplate = "{0}.{1}{2}"; public const string PackageFileBackupSavePathTemplate = "{0}/{1}/{2}.{3}"; diff --git a/src/NuGetGallery.Core/CredentialTypes.cs b/src/NuGetGallery.Core/CredentialTypes.cs index 0a92737039..c7c5f899f0 100644 --- a/src/NuGetGallery.Core/CredentialTypes.cs +++ b/src/NuGetGallery.Core/CredentialTypes.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Entities/AccountDelete.cs b/src/NuGetGallery.Core/Entities/AccountDelete.cs deleted file mode 100644 index 0f4e15d11f..0000000000 --- a/src/NuGetGallery.Core/Entities/AccountDelete.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class AccountDelete - : IEntity - { - public int Key { get; set; } - - /// - /// The date when the account was deleted. - /// - [Required] - public DateTime DeletedOn { get; set; } - - /// - /// The deleted account key. - /// - public int DeletedAccountKey { get; set; } - - /// - /// The deleted account. - /// - public User DeletedAccount { get; set; } - - /// - /// The User(admin) key that executed the delete action. - /// - public int DeletedByKey { get; set; } - - /// - /// The User(admin) that executed the delete action. - /// - public User DeletedBy { get; set; } - - /// - /// The signature of the admin. - /// - public string Signature { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/Certificate.cs b/src/NuGetGallery.Core/Entities/Certificate.cs deleted file mode 100644 index bf13104639..0000000000 --- a/src/NuGetGallery.Core/Entities/Certificate.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - [DisplayColumn(nameof(Thumbprint))] - public class Certificate : IEntity - { - /// - /// The database-mastered identifier for this certificate. - /// - public int Key { get; set; } - - /// - /// Gets or sets the SHA-1 thumbprint of the certificate. - /// - public string Sha1Thumbprint { get; set; } - - /// - /// The SHA-256 thumbprint (fingerprint) that uniquely identifies this certificate. This is a string with - /// exactly 64 characters and is the hexadecimal encoding of the hash digest. Note that the SQL column that - /// stores this property allows longer string values to facilitate future hash algorithm changes. - /// - public string Thumbprint { get; set; } - - /// - /// The subject distinguished name of the certificate. - /// - public string Subject { get; set; } - - /// - /// The short subject of the certificate. In most cases, this is the CN attribute. - /// - public string ShortSubject { get; set; } - - /// - /// The issuer distinguished name of the certificate. - /// - public string Issuer { get; set; } - - /// - /// The short issuer of the certificate. In most cases, this is the CN attribute. - /// - public string ShortIssuer { get; set; } - - /// - /// The expiration date and time of the certificate. - /// - public DateTime? Expiration { get; set; } - - /// - /// Gets or sets the collection of user certificates. - /// - public ICollection UserCertificates { get; set; } - - public Certificate() - { - UserCertificates = new List(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/Credential.cs b/src/NuGetGallery.Core/Entities/Credential.cs deleted file mode 100644 index 1811eb268a..0000000000 --- a/src/NuGetGallery.Core/Entities/Credential.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; - -namespace NuGetGallery -{ - public class Credential - : IEntity - { - /// - /// Represents a credential used by NuGet Gallery. Can be an API key credential, - /// username/password or external credential like Microsoft Account or Azure Active Directory. - /// - public Credential() - { - Scopes = new List(); - } - - - /// - /// Represents a credential used by NuGet Gallery. Can be an API key credential, - /// username/password or external credential like Microsoft Account or Azure Active Directory. - /// - /// Credential type. See - /// Credential value - public Credential(string type, string value) - : this() - { - Type = type; - Value = value; - } - - /// - /// Represents a credential used by NuGet Gallery. Can be an API key credential, - /// username/password or external credential like Microsoft Account or Azure Active Directory. - /// - /// Credential type. See - /// Credential value - /// Optional expiration timespan for the credential. - public Credential(string type, string value, TimeSpan? expiration) - : this(type, value) - { - if (expiration.HasValue && expiration.Value > TimeSpan.Zero) - { - Expires = DateTime.UtcNow.Add(expiration.Value); - ExpirationTicks = expiration.Value.Ticks; - } - } - - public int Key { get; set; } - - [Required] - public int UserKey { get; set; } - - [Required] - [StringLength(maximumLength: 64)] - public string Type { get; set; } - - [Required] - [StringLength(maximumLength: 256)] - public string Value { get; set; } - - [StringLength(maximumLength: 256)] - public string TenantId { get; set; } - - [StringLength(maximumLength: 256)] - public string Description { get; set; } - - [StringLength(maximumLength: 256)] - public string Identity { get; set; } - - [DatabaseGenerated(DatabaseGeneratedOption.Computed)] - public DateTime Created { get; set; } - - public DateTime? Expires { get; set; } - - public long? ExpirationTicks { get; set; } - - public DateTime? LastUsed { get; set; } - - public virtual User User { get; set; } - - public virtual ICollection Scopes { get; set; } - - [NotMapped] - public bool HasExpired - { - get - { - if (Expires.HasValue) - { - return DateTime.UtcNow >= Expires.Value; - } - - return false; - } - } - - public bool HasBeenUsedInLastDays(int numberOfDays) - { - if (numberOfDays > 0 && LastUsed.HasValue) - { - return LastUsed.Value.AddDays(numberOfDays) > DateTime.UtcNow; - } - - return true; - } - } -} diff --git a/src/NuGetGallery.Core/Entities/CuratedFeed.cs b/src/NuGetGallery.Core/Entities/CuratedFeed.cs deleted file mode 100644 index d488435c92..0000000000 --- a/src/NuGetGallery.Core/Entities/CuratedFeed.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace NuGetGallery -{ - public class CuratedFeed - : IEntity - { - public CuratedFeed() - { - Managers = new HashSet(); - Packages = new HashSet(); - } - - public string Name { get; set; } - public virtual ICollection Managers { get; set; } - public virtual ICollection Packages { get; set; } - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/CuratedPackage.cs b/src/NuGetGallery.Core/Entities/CuratedPackage.cs deleted file mode 100644 index 0788f98c7d..0000000000 --- a/src/NuGetGallery.Core/Entities/CuratedPackage.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public class CuratedPackage - : IEntity - { - public CuratedFeed CuratedFeed { get; set; } - public int CuratedFeedKey { get; set; } - public PackageRegistration PackageRegistration { get; set; } - public int PackageRegistrationKey { get; set; } - public bool AutomaticallyCurated { get; set; } - public bool Included { get; set; } - public string Notes { get; set; } - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/EmailMessage.cs b/src/NuGetGallery.Core/Entities/EmailMessage.cs deleted file mode 100644 index 101a46242d..0000000000 --- a/src/NuGetGallery.Core/Entities/EmailMessage.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public class EmailMessage - : IEntity - { - public EmailMessage() - : this(null, null) - { - } - - public EmailMessage(string subject, string body) - { - Body = body; - Subject = subject; - } - - public string Body { get; set; } - public User FromUser { get; set; } - public int? FromUserKey { get; set; } - public bool Sent { get; set; } - public string Subject { get; set; } - public User ToUser { get; set; } - public int ToUserKey { get; set; } - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/EntitiesContext.cs b/src/NuGetGallery.Core/Entities/EntitiesContext.cs index 624cec9fde..081e79ceda 100644 --- a/src/NuGetGallery.Core/Entities/EntitiesContext.cs +++ b/src/NuGetGallery.Core/Entities/EntitiesContext.cs @@ -6,6 +6,7 @@ using System.Data.Entity; using System.Data.Entity.Infrastructure.Annotations; using System.Threading.Tasks; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Entities/GallerySetting.cs b/src/NuGetGallery.Core/Entities/GallerySetting.cs index 6e77c71aec..d50986fb9c 100644 --- a/src/NuGetGallery.Core/Entities/GallerySetting.cs +++ b/src/NuGetGallery.Core/Entities/GallerySetting.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using NuGet.Services.Entities; + namespace NuGetGallery { // These guys are no longer referenced by code, but they are still referenced by diff --git a/src/NuGetGallery.Core/Entities/IEntitiesContext.cs b/src/NuGetGallery.Core/Entities/IEntitiesContext.cs index 2cd79343f4..afeb3831f5 100644 --- a/src/NuGetGallery.Core/Entities/IEntitiesContext.cs +++ b/src/NuGetGallery.Core/Entities/IEntitiesContext.cs @@ -3,6 +3,7 @@ using System.Data.Entity; using System.Threading.Tasks; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Entities/IEntity.cs b/src/NuGetGallery.Core/Entities/IEntity.cs deleted file mode 100644 index 09b9e42dc6..0000000000 --- a/src/NuGetGallery.Core/Entities/IEntity.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public interface IEntity - { - int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/IPackageEntity.cs b/src/NuGetGallery.Core/Entities/IPackageEntity.cs deleted file mode 100644 index 6ea528cca8..0000000000 --- a/src/NuGetGallery.Core/Entities/IPackageEntity.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - /// - /// The common entity type to be shared by and - /// This allows us the generic type instantiation in dependency injection for the commonly required code. - /// - public interface IPackageEntity : IEntity - { - string Id { get; } - - string Version { get; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/Membership.cs b/src/NuGetGallery.Core/Entities/Membership.cs deleted file mode 100644 index 23092444f7..0000000000 --- a/src/NuGetGallery.Core/Entities/Membership.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - /// - /// Tracks membership of a User account in an Organization account. - /// - public class Membership - { - /// - /// Organization foreign key. - /// - public int OrganizationKey { get; set; } - - /// - /// The that contains members. - /// - public virtual Organization Organization { get; set; } - - /// - /// Member (User) foreign key. - /// - public int MemberKey { get; set; } - - /// - /// The that is a member of the . - /// - /// Note that there is no database contraint preventing memberships of Organizations into other - /// Organizations. For now this is restricted by the Gallery, but could be considered in the - /// future if we want to support Organization teams. - /// - public virtual User Member { get; set; } - - /// - /// Whether the is an administrator for the . - /// - /// Administrators have the following capabilities that collaborators don't: - /// - Organization management (e.g., settings, membership) - /// - Package owner management - /// - Pushing new package registrations - /// - public bool IsAdmin { get; set; } - } -} diff --git a/src/NuGetGallery.Core/Entities/MembershipRequest.cs b/src/NuGetGallery.Core/Entities/MembershipRequest.cs deleted file mode 100644 index 8b6c78f21d..0000000000 --- a/src/NuGetGallery.Core/Entities/MembershipRequest.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class MembershipRequest - { - public int OrganizationKey { get; set; } - - public virtual Organization Organization { get; set; } - - public int NewMemberKey { get; set; } - - public virtual User NewMember { get; set; } - - public bool IsAdmin { get; set; } - - [Required] - public string ConfirmationToken { get; set; } - - public DateTime RequestDate { get; set; } - } -} diff --git a/src/NuGetGallery.Core/Entities/Organization.cs b/src/NuGetGallery.Core/Entities/Organization.cs deleted file mode 100644 index 94469aa441..0000000000 --- a/src/NuGetGallery.Core/Entities/Organization.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; - -namespace NuGetGallery -{ - /// - /// Organization account, based on TPT hierarchy. - /// - /// With the addition of organizations, the users table effectively becomes an account table. Organizations accounts - /// are child types created using TPT inheritance. User accounts are not child types, but this could be done in the - /// future if we want to add constraints for user accounts or user-only settings. - /// - /// - public class Organization : User - { - public Organization() : this(null) - { - } - - public Organization(string name) : base(name) - { - Members = new List(); - MemberRequests = new List(); - - _administrators = new Lazy>( - () => Members.Where(m => m.IsAdmin).Select(m => m.Member).ToList()); - _collaborators = new Lazy>( - () => Members.Where(m => !m.IsAdmin).Select(m => m.Member).ToList()); - } - - /// - /// Organization Memberships to this organization. - /// - public virtual ICollection Members { get; set; } - - /// - /// Requests to become a member of this . - /// - public virtual ICollection MemberRequests { get; set; } - - #region per-request query cache - - private Lazy> _administrators; - private Lazy> _collaborators; - - [NotMapped] - public IEnumerable Administrators - { - get - { - return _administrators.Value; - } - } - - [NotMapped] - public IEnumerable Collaborators - { - get - { - return _collaborators.Value; - } - } - - #endregion - - } -} diff --git a/src/NuGetGallery.Core/Entities/OrganizationMigrationRequest.cs b/src/NuGetGallery.Core/Entities/OrganizationMigrationRequest.cs deleted file mode 100644 index 6647a81981..0000000000 --- a/src/NuGetGallery.Core/Entities/OrganizationMigrationRequest.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class OrganizationMigrationRequest - { - public int NewOrganizationKey { get; set; } - - public virtual User NewOrganization { get; set; } - - public int AdminUserKey { get; set; } - - public virtual User AdminUser { get; set; } - - [Required] - public string ConfirmationToken { get; set; } - - public DateTime RequestDate { get; set; } - } -} diff --git a/src/NuGetGallery.Core/Entities/Package.cs b/src/NuGetGallery.Core/Entities/Package.cs deleted file mode 100644 index 1febfdd5f9..0000000000 --- a/src/NuGetGallery.Core/Entities/Package.cs +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace NuGetGallery -{ - [DisplayColumn("Title")] - public class Package - : IPackageEntity - { - -#pragma warning disable 618 // TODO: remove Package.Authors completely once production services definitely no longer need it - public Package() - { - Authors = new HashSet(); - Dependencies = new HashSet(); - PackageHistories = new HashSet(); - PackageTypes = new HashSet(); - SupportedFrameworks = new HashSet(); - SymbolPackages = new HashSet(); - Listed = true; - } -#pragma warning restore 618 - - public PackageRegistration PackageRegistration { get; set; } - public int PackageRegistrationKey { get; set; } - - [Obsolete("Will be removed in a future iteration, for now is write-only")] - public virtual ICollection Authors { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string Copyright { get; set; } - - [DatabaseGenerated(DatabaseGeneratedOption.Computed)] - public DateTime Created { get; set; } - - public virtual ICollection Dependencies { get; set; } - - public virtual ICollection PackageTypes { get; set; } - - /// - /// Has a max length of 4000. Is not indexed but *IS* used for searches. Db column is nvarchar(max). - /// - public string Description { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string ReleaseNotes { get; set; } - - public int DownloadCount { get; set; } - - /// - /// Is not a property that we support. Maintained for legacy reasons. - /// - [Obsolete] - public string ExternalPackageUrl { get; set; } - - [StringLength(10)] - public string HashAlgorithm { get; set; } - - /// - /// Stringified hashcode generated by hashing the nupkg file with HashAlgorithm. - /// - [StringLength(256)] - [Required] - public string Hash { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string IconUrl { get; set; } - - public bool IsLatest { get; set; } - public bool IsLatestStable { get; set; } - - public bool IsLatestSemVer2 { get; set; } - public bool IsLatestStableSemVer2 { get; set; } - - /// - /// This is when the Package Entity was last touched (so caches can notice changes). In UTC. - /// - [DatabaseGenerated(DatabaseGeneratedOption.Computed)] - public DateTime LastUpdated { get; set; } - - /// - /// This is when the Package Metadata was last edited by a user. Or NULL. In UTC. - /// - /// This field is updated by a trigger on the database if it is edited. - /// This trigger is defined by a migration named "AddTriggerForPackagesLastEdited". - /// The trigger guarantees that the timestamps of multiple instances of the gallery do not conflict. - /// - public DateTime? LastEdited { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string LicenseUrl { get; set; } - - public bool HideLicenseReport { get; set; } - - [StringLength(20)] - public string Language { get; set; } - - [DatabaseGenerated(DatabaseGeneratedOption.Computed)] - public DateTime Published { get; set; } - - /// The size of the nupkg file in bytes. - public long PackageFileSize { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string ProjectUrl { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string RepositoryUrl { get; set; } - - - /// - /// Has a max length of 100. Is not indexed and not used for searches. Db column is nvarchar(100). - /// - [StringLength(100)] - public string RepositoryType { get; set; } - - /// - /// Nullable flag stored in the database. Callers should use the HasReadMe property instead. - /// - [Column("HasReadMe")] - public bool? HasReadMeInternal { get; set; } - - /// - /// Signifies whether or not the ReadMe exists. Falses stored as NULL in database to avoid updating existing rows. - /// - [NotMapped] - public bool HasReadMe { - get - { - return HasReadMeInternal ?? false; - } - set - { - HasReadMeInternal = value ? (bool?)true : null; - } - } - - public bool RequiresLicenseAcceptance { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string Summary { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and *IS* used for searches, but is maintained via Lucene. Db column is nvarchar(max). - /// - public string Tags { get; set; } - - [StringLength(256)] - public string Title { get; set; } - - /// - /// Gets or sets the version listed in the manifest for this package, which MAY NOT conform to NuGet's use of SemVer - /// - [StringLength(64)] - [Required] - public string Version { get; set; } - - /// - /// Gets or sets the version for this package that has been normalized to conform to NuGet's use of SemVer - /// - [StringLength(64)] - public string NormalizedVersion { get; set; } - - /// - /// Gets or sets the minimum required SemVer level for consumers of this package, - /// based on the Version property containing the original version string, - /// or the dependency version ranges of this package. - /// - /// - /// If the field value is null, the SemVer level of this version is unknown, - /// and could either indicate the package version is SemVer1- or non-SemVer-compliant at all (e.g. System.Versioning pattern). - /// - public int? SemVerLevelKey { get; set; } - - public virtual ICollection LicenseReports { get; set; } - - // Pre-calculated data for the feed - public string LicenseNames { get; set; } - public string LicenseReportUrl { get; set; } - - public bool Listed { get; set; } - public bool IsPrerelease { get; set; } - public virtual ICollection SupportedFrameworks { get; set; } - - public string FlattenedAuthors { get; set; } - - public string FlattenedDependencies { get; set; } - - public string FlattenedPackageTypes { get; set; } - - public int Key { get; set; } - - [StringLength(44)] - public string MinClientVersion { get; set; } - - /// - /// The logged in user when this package version was created. - /// NULL for older packages. - /// - public User User { get; set; } - public int? UserKey { get; set; } - - /// - /// List of historical metadata info of this package (before edits were applied) - /// - public virtual ICollection PackageHistories { get; set; } - - [Obsolete] - public bool Deleted { get; set; } - - /// - /// The package status key, referring to the enum. - /// - public PackageStatus PackageStatusKey { get; set; } - - /// - /// Gets or sets the foreign key of the certificate used to sign the package. - /// - public int? CertificateKey { get; set; } - - /// - /// Gets or sets the certificate used to sign the package. - /// - public virtual Certificate Certificate { get; set; } - - public virtual ICollection SymbolPackages { get; set; } - - public string Id => PackageRegistration.Id; - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageAuthor.cs b/src/NuGetGallery.Core/Entities/PackageAuthor.cs deleted file mode 100644 index e9cf441aa5..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageAuthor.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public class PackageAuthor - : IEntity - { - public Package Package { get; set; } - public int PackageKey { get; set; } - - /// - /// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max). - /// - public string Name { get; set; } - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageDelete.cs b/src/NuGetGallery.Core/Entities/PackageDelete.cs deleted file mode 100644 index 23094b1e17..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageDelete.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageDelete - : IEntity - { - public PackageDelete() - { - Packages = new HashSet(); - } - - public int Key { get; set; } - - [Required] - public DateTime DeletedOn { get; set; } - - [Required] - public User DeletedBy { get; set; } - public int DeletedByKey { get; set; } - - [Required] - public string Reason { get; set; } - - [Required] - public string Signature { get; set; } - - public virtual ICollection Packages { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageDependency.cs b/src/NuGetGallery.Core/Entities/PackageDependency.cs deleted file mode 100644 index d7f806786a..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageDependency.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageDependency - : IEntity - { - public Package Package { get; set; } - public int PackageKey { get; set; } - - /// - /// We insert a record with a null Id to indicate an empty package dependency set. In such a case, the Id would be empty and hence - /// we cannot mandate that it is required. - /// - [StringLength(CoreConstants.MaxPackageIdLength)] - public string Id { get; set; } - - [StringLength(256)] - public string VersionSpec { get; set; } - - [StringLength(256)] - public string TargetFramework { get; set; } - - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageEditReadMeState.cs b/src/NuGetGallery.Core/Entities/PackageEditReadMeState.cs deleted file mode 100644 index d567dc387f..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageEditReadMeState.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public enum PackageEditReadMeState - { - Changed, - Unchanged, - Deleted - } -} diff --git a/src/NuGetGallery.Core/Entities/PackageFramework.cs b/src/NuGetGallery.Core/Entities/PackageFramework.cs deleted file mode 100644 index c8f76b15d9..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageFramework.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using NuGet.Frameworks; - -namespace NuGetGallery -{ - public class PackageFramework - : IEntity, IEquatable - { - private string _targetFramework; - - public Package Package { get; set; } - - [StringLength(256)] - public string TargetFramework - { - get { return _targetFramework; } - set - { - _targetFramework = value; - FrameworkName = NuGetFramework.Parse(_targetFramework); - } - } - - [NotMapped] - public NuGetFramework FrameworkName { get; private set; } - - public int Key { get; set; } - - public bool Equals(PackageFramework framework) - { - return framework != null && FrameworkName == framework.FrameworkName; - } - - public override bool Equals(object obj) - { - var other = obj as PackageFramework; - return Equals(other); - } - - public override int GetHashCode() - { - return FrameworkName.GetHashCode(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageHistory.cs b/src/NuGetGallery.Core/Entities/PackageHistory.cs deleted file mode 100644 index 24c601ac7a..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageHistory.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - /// - /// This records the OLD metadata of a particular package, before an edit was applied. - /// - public class PackageHistory - : IEntity - { - public PackageHistory() - { - } - - public PackageHistory(Package package) - { - Package = package; - User = package.User; - Timestamp = DateTime.UtcNow; - Title = package.Title; - Authors = package.FlattenedAuthors; - Copyright = package.Copyright; - Description = package.Description; - IconUrl = package.IconUrl; - LicenseUrl = package.LicenseUrl; - ProjectUrl = package.ProjectUrl; - RepositoryUrl = package.RepositoryUrl; - ReleaseNotes = package.ReleaseNotes; - RequiresLicenseAcceptance = package.RequiresLicenseAcceptance; - Summary = package.Summary; - Tags = package.Tags; - Hash = package.Hash; - HashAlgorithm = package.HashAlgorithm; - PackageFileSize = package.PackageFileSize; - LastUpdated = package.LastUpdated; - Published = package.Published; - } - - public int Key { get; set; } - - public Package Package { get; set; } - public int PackageKey { get; set; } - - /// - /// The user who generated this old metadata. NULL if unknown. - /// - public User User { get; set; } - public int? UserKey { get; set; } - - /// - /// Time the metadata replacement occurred (UTC) - /// - public DateTime Timestamp { get; set; } - - //////////////// The rest are same as on Package //////////// - - [StringLength(256)] - public string Title { get; set; } - public string Authors { get; set; } - public string Copyright { get; set; } - public string Description { get; set; } - public string IconUrl { get; set; } - public string LicenseUrl { get; set; } - public string ProjectUrl { get; set; } - public string RepositoryUrl { get; set; } - public string ReleaseNotes { get; set; } - public bool RequiresLicenseAcceptance { get; set; } - public string Summary { get; set; } - public string Tags { get; set; } - - [StringLength(256)] - public string Hash { get; set; } - - [StringLength(10)] - public string HashAlgorithm { get; set; } - - public long PackageFileSize { get; set; } - public DateTime LastUpdated { get; set; } - public DateTime Published { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageLicense.cs b/src/NuGetGallery.Core/Entities/PackageLicense.cs deleted file mode 100644 index 509f8117ec..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageLicense.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageLicense - : IEntity - { - public int Key { get; set; } - - [Required] - [StringLength(128)] - public string Name { get; set; } - - public virtual ICollection Reports { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageLicenseReport.cs b/src/NuGetGallery.Core/Entities/PackageLicenseReport.cs deleted file mode 100644 index fde6c21f73..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageLicenseReport.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageLicenseReport - : IEntity - { - public int Key { get; set; } - - [Required] - public int PackageKey { get; set; } - - [Required] - public DateTime CreatedUtc { get; set; } - - [Required] - public int Sequence { get; set; } - - [Required] - [StringLength(256)] - public string ReportUrl { get; set; } - - [StringLength(256)] - public string Comment { get; set; } - - public virtual ICollection Licenses { get; set; } - - public virtual Package Package { get; set; } - } -} diff --git a/src/NuGetGallery.Core/Entities/PackageOwnerRequest.cs b/src/NuGetGallery.Core/Entities/PackageOwnerRequest.cs deleted file mode 100644 index 7652b9048e..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageOwnerRequest.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace NuGetGallery -{ - public class PackageOwnerRequest - : IEntity - { - public int PackageRegistrationKey { get; set; } - public virtual PackageRegistration PackageRegistration { get; set; } - public int NewOwnerKey { get; set; } - public virtual User NewOwner { get; set; } - public virtual User RequestingOwner { get; set; } - public int RequestingOwnerKey { get; set; } - public string ConfirmationCode { get; set; } - public DateTime RequestDate { get; set; } - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageRegistration.cs b/src/NuGetGallery.Core/Entities/PackageRegistration.cs deleted file mode 100644 index 1ddfde5834..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageRegistration.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageRegistration - : IEntity - { - public PackageRegistration() - { - Owners = new HashSet(); - Packages = new HashSet(); - ReservedNamespaces = new HashSet(); - RequiredSigners = new HashSet(); - } - - [StringLength(CoreConstants.MaxPackageIdLength)] - [Required] - public string Id { get; set; } - - public int DownloadCount { get; set; } - - public bool IsVerified { get; set; } - - public bool IsLocked { get; set; } - - public virtual ICollection Owners { get; set; } - public virtual ICollection Packages { get; set; } - public virtual ICollection ReservedNamespaces { get; set; } - - /// - /// Gets or sets required signers for this package registration. - /// - public virtual ICollection RequiredSigners { get; set; } - - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/PackageType.cs b/src/NuGetGallery.Core/Entities/PackageType.cs deleted file mode 100644 index 0d9ccb6d9b..0000000000 --- a/src/NuGetGallery.Core/Entities/PackageType.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class PackageType - : IEntity - { - public Package Package { get; set; } - public int PackageKey { get; set; } - - /// - /// Has a max length of 512. Is indexed. Db column is nvarchar(512). - /// - public string Name { get; set; } - - public string Version { get; set; } - - [Key] - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/ReservedNamespace.cs b/src/NuGetGallery.Core/Entities/ReservedNamespace.cs deleted file mode 100644 index c034efc8d4..0000000000 --- a/src/NuGetGallery.Core/Entities/ReservedNamespace.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class ReservedNamespace : IEntity - { - public ReservedNamespace() - : this(value: null, isSharedNamespace: false, isPrefix: false) - { - } - - public ReservedNamespace(string value, bool isSharedNamespace, bool isPrefix) - { - Value = value; - IsSharedNamespace = isSharedNamespace; - IsPrefix = isPrefix; - PackageRegistrations = new HashSet(); - Owners = new HashSet(); - } - - [StringLength(CoreConstants.MaxPackageIdLength)] - [Required] - public string Value { get; set; } - - public bool IsSharedNamespace { get; set; } - - public bool IsPrefix { get; set; } - - public virtual ICollection PackageRegistrations { get; set; } - public virtual ICollection Owners { get; set; } - - [Key] - public int Key { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/Role.cs b/src/NuGetGallery.Core/Entities/Role.cs deleted file mode 100644 index 2cae4f677b..0000000000 --- a/src/NuGetGallery.Core/Entities/Role.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace NuGetGallery -{ - public class Role - : IEntity - { - public int Key { get; set; } - public string Name { get; set; } - public virtual ICollection Users { get; set; } - - public Role() - { - Users = new HashSet(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/Scope.cs b/src/NuGetGallery.Core/Entities/Scope.cs deleted file mode 100644 index ae8ba596b9..0000000000 --- a/src/NuGetGallery.Core/Entities/Scope.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json; - -namespace NuGetGallery -{ - public class Scope - : IEntity - { - [JsonIgnore] - public int Key { get; set; } - - [JsonIgnore] - public int CredentialKey { get; set; } - - /// - /// Package owner (user or organization) scoping. - /// - [JsonProperty("o")] - public int? OwnerKey { get; set; } - - /// - /// Package owner (user or organization) scoping. - /// - [JsonIgnore] - public virtual User Owner { get; set; } - - /// - /// Packages glob pattern. - /// - [JsonProperty("s")] - public string Subject { get; set; } - - [Required] - [JsonProperty("a")] - public string AllowedAction { get; set; } - - [JsonIgnore] - public virtual Credential Credential { get; set; } - - public Scope() - { - } - - public Scope(User owner, string subject, string allowedAction) - { - Owner = owner; - Subject = subject; - AllowedAction = allowedAction; - } - - public Scope(int? ownerKey, string subject, string allowedAction) - { - OwnerKey = ownerKey; - Subject = subject; - AllowedAction = allowedAction; - } - - // Deprecated: Should be removed once ApiKeys.cshtml is updated to support owner scope. - public Scope(string subject, string allowedAction) - { - Subject = subject; - AllowedAction = allowedAction; - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/SymbolPackage.cs b/src/NuGetGallery.Core/Entities/SymbolPackage.cs deleted file mode 100644 index b848630f53..0000000000 --- a/src/NuGetGallery.Core/Entities/SymbolPackage.cs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - public class SymbolPackage - : IPackageEntity, IEquatable - { - public int Key { get; set; } - - public Package Package { get; set; } - - public int PackageKey { get; set; } - - /// - /// Timestamp when this symbol was created. - /// - public DateTime Created { get; set; } - - /// - /// Time when this symbol package is available for consumption. It will be updated after validations are complete. - /// - public DateTime? Published { get; set; } - - /// - /// The size of the snupkg file in bytes. - /// - public long FileSize { get; set; } - - [StringLength(10)] - public string HashAlgorithm { get; set; } - - /// - /// Stringified hashcode generated by hashing the snupkg file with HashAlgorithm. - /// - [StringLength(256)] - [Required] - public string Hash { get; set; } - - /// - /// Availability status of the symbol - /// - public PackageStatus StatusKey { get; set; } - - /// - /// Used for optimistic concurrency when updating the symbols. - /// - public byte[] RowVersion { get; set; } - - public string Id => Package?.Id; - - public string Version => Package?.Version; - - public bool Equals(SymbolPackage other) - { - return other.Key == Key; - } - - public override int GetHashCode() - { - return Key.GetHashCode(); - } - - public override bool Equals(object obj) - { - if (obj == null) - { - return false; - } - - SymbolPackage sp = obj as SymbolPackage; - if (sp == null) - { - return false; - } - - return Equals(sp); - } - - public static bool operator ==(SymbolPackage sp1, SymbolPackage sp2) - { - if (((object)sp1) == null || ((object)sp2) == null) - { - return Equals(sp1, sp2); - } - - return sp1.Equals(sp2); - } - - public static bool operator !=(SymbolPackage sp1, SymbolPackage sp2) - { - if (((object)sp1) == null || ((object)sp2) == null) - { - return !Equals(sp1, sp2); - } - - return !sp1.Equals(sp2); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/User.cs b/src/NuGetGallery.Core/Entities/User.cs deleted file mode 100644 index f62f2c13c2..0000000000 --- a/src/NuGetGallery.Core/Entities/User.cs +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace NuGetGallery -{ - /// - /// With the addition of organizations, the users table effectively becomes an account table. Organizations accounts - /// are child types created using TPT inheritance. User accounts are not child types, but this could be done in the - /// future if we want to add constraints for user accounts or user-only settings. - /// - /// - public class User : IEntity, IEquatable - { - #region per-request query cache - - private bool? _isAdmin; - - [NotMapped] - public bool IsAdministrator - { - get - { - if (!_isAdmin.HasValue) - { - _isAdmin = IsInRole(CoreConstants.AdminRoleName); - } - return _isAdmin.Value; - } - } - - #endregion - - public User() : this(null) - { - } - - public User(string username) - { - Credentials = new List(); - SecurityPolicies = new List(); - ReservedNamespaces = new HashSet(); - Organizations = new List(); - OrganizationMigrationRequests = new List(); - OrganizationRequests = new List(); - Roles = new List(); - Username = username; - UserCertificates = new List(); - } - - /// - /// Organization memberships, for a non-organization account. - /// - public virtual ICollection Organizations { get; set; } - - /// - /// Organization membership requests, for a non-organization account. - /// - public virtual ICollection OrganizationRequests { get; set; } - - /// - /// Request to transform a account into an account. - /// - public virtual OrganizationMigrationRequest OrganizationMigrationRequest { get; set; } - - /// - /// Requests for this user to become the admin of a account that was transformed into an account. - /// - public virtual ICollection OrganizationMigrationRequests { get; set; } - - [StringLength(256)] - public string EmailAddress { get; set; } - - [StringLength(256)] - public string UnconfirmedEmailAddress { get; set; } - - public virtual ICollection Messages { get; set; } - - [StringLength(64)] - [Required] - public string Username { get; set; } - - public virtual ICollection Roles { get; set; } - - public bool EmailAllowed { get; set; } - - public bool IsDeleted { get; set; } - - public bool EnableMultiFactorAuthentication { get; set; } - - public virtual ICollection ReservedNamespaces { get; set; } - - [DefaultValue(true)] - public bool NotifyPackagePushed { get; set; } - - public bool Confirmed - { - get { return !String.IsNullOrEmpty(EmailAddress); } - } - - [StringLength(32)] - public string EmailConfirmationToken { get; set; } - - [StringLength(32)] - public string PasswordResetToken { get; set; } - - public DateTime? PasswordResetTokenExpirationDate { get; set; } - - public int Key { get; set; } - - public DateTime? CreatedUtc { get; set; } - - public DateTime? LastFailedLoginUtc { get; set; } - - public int FailedLoginCount { get; set; } - - public string LastSavedEmailAddress - { - get - { - return UnconfirmedEmailAddress ?? EmailAddress; - } - } - - public virtual ICollection Credentials { get; set; } - - public virtual ICollection SecurityPolicies { get; set; } - - /// - /// Gets or sets the collection of user certificates. - /// - public virtual ICollection UserCertificates { get; set; } - - public void ConfirmEmailAddress() - { - if (string.IsNullOrEmpty(UnconfirmedEmailAddress)) - { - throw new InvalidOperationException("User does not have an email address to confirm"); - } - EmailAddress = UnconfirmedEmailAddress; - EmailConfirmationToken = null; - UnconfirmedEmailAddress = null; - } - - public void CancelChangeEmailAddress() - { - EmailConfirmationToken = null; - UnconfirmedEmailAddress = null; - } - - public void UpdateUnconfirmedEmailAddress(string newEmailAddress, Func generateToken) - { - if (!string.IsNullOrEmpty(UnconfirmedEmailAddress)) - { - if (string.Equals(UnconfirmedEmailAddress, newEmailAddress, StringComparison.Ordinal)) - { - return; // already set as latest (unconfirmed) email address - } - } - else - { - if (String.Equals(EmailAddress, newEmailAddress, StringComparison.Ordinal)) - { - return; // already set as latest (confirmed) email address - } - } - - UnconfirmedEmailAddress = newEmailAddress; - EmailConfirmationToken = generateToken(); - } - - public bool IsInRole(string roleName) - { - return Roles.Any(r => String.Equals(r.Name, roleName, StringComparison.OrdinalIgnoreCase)); - } - - public bool Equals(User other) - { - return other.Key == Key; - } - - public override bool Equals(object obj) - { - if(obj == null) - { - return false; - } - User user = obj as User; - if(user == null) - { - return false; - } - return Equals(user); - } - - public override int GetHashCode() - { - return Key.GetHashCode(); - } - - public static bool operator ==(User user1, User user2) - { - if (((object)user1) == null || ((object)user2) == null) - { - return Equals(user1, user2); - } - - return user1.Equals(user2); - } - - public static bool operator !=(User user1, User user2) - { - if (((object)user1) == null || ((object)user2) == null) - { - return !Equals(user1, user2); - } - - return !user1.Equals(user2); - } - } -} diff --git a/src/NuGetGallery.Core/Entities/UserCertificate.cs b/src/NuGetGallery.Core/Entities/UserCertificate.cs deleted file mode 100644 index 4e5879a1d8..0000000000 --- a/src/NuGetGallery.Core/Entities/UserCertificate.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.ComponentModel.DataAnnotations.Schema; - -namespace NuGetGallery -{ - /// - /// Represents a relationship between a user and certificate. - /// - public class UserCertificate : IEntity - { - /// - /// Gets or sets the primary key for the entity. - /// - public int Key { get; set; } - - /// - /// Gets or sets the foreign key of the certificate entity. - /// - [Index("IX_UserCertificates_CertificateKeyUserKey", IsUnique = true, Order = 0)] - public int CertificateKey { get; set; } - - /// - /// Gets or sets the certificate entity. - /// - public virtual Certificate Certificate { get; set; } - - /// - /// Gets or sets the foreign key of the user entity. - /// - [Index("IX_UserCertificates_CertificateKeyUserKey", IsUnique = true, Order = 1)] - public int UserKey { get; set; } - - /// - /// Gets or sets the user entity. - /// - public virtual User User { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Entities/UserSecurityPolicy.cs b/src/NuGetGallery.Core/Entities/UserSecurityPolicy.cs deleted file mode 100644 index 2af8266c70..0000000000 --- a/src/NuGetGallery.Core/Entities/UserSecurityPolicy.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.ComponentModel.DataAnnotations; - -namespace NuGetGallery -{ - /// - /// User-subscribed security policy. - /// - public class UserSecurityPolicy : IEntity, IEquatable - { - public UserSecurityPolicy() - { - } - - public UserSecurityPolicy(UserSecurityPolicy policy) - : this(policy.Name, policy.Subscription, policy.Value) - { - } - - public UserSecurityPolicy(string name, string subscription, string value = null) - { - Name = name ?? throw new ArgumentNullException(nameof(name)); - Subscription = subscription ?? throw new ArgumentNullException(nameof(subscription)); - Value = value; - } - - /// - /// Policy key. - /// - public int Key { get; set; } - - /// - /// User key. - /// - public int UserKey { get; set; } - - /// - /// User subscribed to this security policy. - /// - public User User { get; set; } - - /// - /// Type name for the policy handler that provides policy behavior. - /// - [Required] - [StringLength(256)] - public string Name { get; set; } - - /// - /// Name of subscription that added this policy. - /// - [Required] - [StringLength(256)] - public string Subscription { get; set; } - - /// - /// Support for JSON-serialized properties for specific policies. - /// - public string Value { get; set; } - - /// - /// Determine if two policies are equal. - /// - public bool Equals(UserSecurityPolicy other) - { - return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) && - Subscription.Equals(other.Subscription, StringComparison.OrdinalIgnoreCase) && - ( - (string.IsNullOrEmpty(Value) && string.IsNullOrEmpty(other.Value)) || - (Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase)) - ); - } - - private static readonly Func _hash = (i, hash) => ((hash << 5) + hash) ^ (i?.GetHashCode() ?? 0); - private const long _seed = 0x1505L; - - public override int GetHashCode() - { - return _hash(Value, _hash(Subscription, _hash(Name, _seed))).GetHashCode(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.cs b/src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.cs index 4f38932bb0..0e7517c0ba 100644 --- a/src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.cs +++ b/src/NuGetGallery.Core/Extensions/EntitiesContextExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Data.SqlClient; using System.Threading.Tasks; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Extensions/PackageExtensions.cs b/src/NuGetGallery.Core/Extensions/PackageExtensions.cs deleted file mode 100644 index 1e4b202007..0000000000 --- a/src/NuGetGallery.Core/Extensions/PackageExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Linq; - -namespace NuGetGallery.Extensions -{ - public static class PackageExtensions - { - /// - /// Get the latest(last) uploaded symbols package for the given package. - /// - /// for which latest symbol package is to be retrieved. - /// The latest symbol package if present, null otherwise - public static SymbolPackage LatestSymbolPackage(this Package package) - { - return package - .SymbolPackages? - .OrderByDescending(sp => sp.Created) - .FirstOrDefault(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Extensions/PackageRegistrationExtensions.cs b/src/NuGetGallery.Core/Extensions/PackageRegistrationExtensions.cs deleted file mode 100644 index e17ac40c24..0000000000 --- a/src/NuGetGallery.Core/Extensions/PackageRegistrationExtensions.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; - -namespace NuGetGallery.Extensions -{ - public static class PackageRegistrationExtensions - { - /// - /// Determines if package signing is allowed for the specified package registration. - /// - /// A package registration. - /// A flag indicating whether package signing is allowed. - /// Thrown if - /// is null. - public static bool IsSigningAllowed(this PackageRegistration packageRegistration) - { - if (packageRegistration == null) - { - throw new ArgumentNullException(nameof(packageRegistration)); - } - - var requiredSigner = packageRegistration.RequiredSigners.FirstOrDefault(); - - if (requiredSigner == null) - { - return packageRegistration.Owners.Any(owner => HasAnyCertificate(owner)); - } - - return HasAnyCertificate(requiredSigner); - } - - /// - /// Determines if package signing is required for the specified package registration. - /// - /// A package registration. - /// A flag indicating whether package signing is required. - /// Thrown if - /// is null. - public static bool IsSigningRequired(this PackageRegistration packageRegistration) - { - if (packageRegistration == null) - { - throw new ArgumentNullException(nameof(packageRegistration)); - } - - var requiredSigner = packageRegistration.RequiredSigners.FirstOrDefault(); - - if (requiredSigner == null) - { - return packageRegistration.Owners.All(HasAnyCertificate); - } - - return HasAnyCertificate(requiredSigner); - } - - /// - /// Determines if the certificate with specified thumbprint is valid for signing the specified package registration. - /// - /// A package registration. - /// A certificate thumbprint. - /// A flag indicating whether the certificate is acceptable for signing. - /// Thrown if - /// is null. - /// Thrown if is null - /// or empty. - public static bool IsAcceptableSigningCertificate(this PackageRegistration packageRegistration, string thumbprint) - { - if (packageRegistration == null) - { - throw new ArgumentNullException(nameof(packageRegistration)); - } - - if (string.IsNullOrWhiteSpace(thumbprint)) - { - throw new ArgumentException(CoreStrings.ArgumentCannotBeNullOrEmpty, nameof(thumbprint)); - } - - var requiredSigner = packageRegistration.RequiredSigners.FirstOrDefault(); - - if (requiredSigner == null) - { - return packageRegistration.Owners.Any(owner => CanUseCertificate(owner, thumbprint)); - } - - return CanUseCertificate(requiredSigner, thumbprint); - } - - private static bool HasAnyCertificate(User user) - { - return user.UserCertificates.Any(); - } - - private static bool CanUseCertificate(User user, string thumbprint) - { - return user.UserCertificates.Any(uc => string.Equals(uc.Certificate.Thumbprint, thumbprint, StringComparison.OrdinalIgnoreCase)); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Extensions/PackageValidationSetExtensions.cs b/src/NuGetGallery.Core/Extensions/PackageValidationSetExtensions.cs deleted file mode 100644 index 43c6180048..0000000000 --- a/src/NuGetGallery.Core/Extensions/PackageValidationSetExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using NuGet.Services.Validation; -using NuGet.Services.Validation.Issues; -using System.Collections.Generic; -using System.Linq; - -namespace NuGetGallery -{ - public static class PackageValidationSetExtensions - { - public static IReadOnlyList GetValidationIssues(this PackageValidationSet validationSet) - { - IReadOnlyList issues = null; - - if (validationSet != null) - { - // Get the failed validation set's validation issues. The issues are ordered by their - // key so that it appears that issues are appended as more validations fail. - issues = validationSet - .PackageValidations - .SelectMany(v => v.PackageValidationIssues) - .OrderBy(i => i.Key) - .Select(i => ValidationIssue.Deserialize(i.IssueCode, i.Data)) - .ToList(); - - // Filter out unknown issues and deduplicate the issues by code and data. This also deduplicates cases - // where there is extraneous data in the serialized data field or if the issue code is unknown. - issues = issues - .GroupBy(x => new { x.IssueCode, Data = x.Serialize() }) - .Select(x => x.First()) - .ToList(); - } - - // If the package failed validation but we could not find an issue that explains why, use a generic error message. - if (issues == null || !issues.Any()) - { - issues = new[] { ValidationIssue.Unknown }; - } - - return issues; - } - } -} diff --git a/src/NuGetGallery.Core/Extensions/UserExtensionsCore.cs b/src/NuGetGallery.Core/Extensions/UserExtensionsCore.cs index f1a594abd6..4990bdc39b 100644 --- a/src/NuGetGallery.Core/Extensions/UserExtensionsCore.cs +++ b/src/NuGetGallery.Core/Extensions/UserExtensionsCore.cs @@ -3,6 +3,7 @@ using System; using System.Net.Mail; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Infrastructure/mail/ConfirmationEmailBuilder.cs b/src/NuGetGallery.Core/Infrastructure/mail/ConfirmationEmailBuilder.cs deleted file mode 100644 index eb893b781e..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/ConfirmationEmailBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail -{ - public abstract class ConfirmationEmailBuilder : MarkdownEmailBuilder - { - protected readonly IMessageServiceConfiguration Configuration; - protected readonly string RawConfirmationUrl; - protected readonly bool IsOrganization; - - protected ConfirmationEmailBuilder( - IMessageServiceConfiguration configuration, - User user, - string confirmationUrl) - { - Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - User = user ?? throw new ArgumentNullException(nameof(user)); - IsOrganization = user is Organization; - RawConfirmationUrl = confirmationUrl ?? throw new ArgumentNullException(nameof(confirmationUrl)); - ConfirmationUrl = EscapeLinkForMarkdown(confirmationUrl); - } - - public override MailAddress Sender => Configuration.GalleryNoReplyAddress; - - public User User { get; } - public string ConfirmationUrl { get; } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/CoreMarkdownMessageService.cs b/src/NuGetGallery.Core/Infrastructure/mail/CoreMarkdownMessageService.cs deleted file mode 100644 index a1d61c4ca5..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/CoreMarkdownMessageService.cs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.ObjectModel; -using System.Globalization; -using System.Linq; -using System.Net.Mail; -using System.Threading.Tasks; -using AnglicanGeek.MarkdownMailer; - -namespace NuGetGallery.Infrastructure.Mail -{ - public class CoreMarkdownMessageService : IMessageService - { - private static readonly ReadOnlyCollection RetryDelays = Array.AsReadOnly(new[] { - TimeSpan.FromSeconds(0.1), - TimeSpan.FromSeconds(1), - TimeSpan.FromSeconds(10) - }); - - public CoreMarkdownMessageService( - IMailSender mailSender, - IMessageServiceConfiguration configuration) - { - MailSender = mailSender ?? throw new ArgumentNullException(nameof(mailSender)); - Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - } - - public IMailSender MailSender { get; protected set; } - public IMessageServiceConfiguration Configuration { get; protected set; } - - public async Task SendMessageAsync(IEmailBuilder emailBuilder, bool copySender = false, bool discloseSenderAddress = false) - { - if (emailBuilder == null) - { - throw new ArgumentNullException(nameof(emailBuilder)); - } - - using (var email = CreateMailMessage(emailBuilder)) - { - await SendMessageInternalAsync(email); - - if (copySender && !discloseSenderAddress) - { - await SendMessageToSenderAsync(email); - } - } - } - - protected virtual async Task SendMessageInternalAsync(MailMessage mailMessage) - { - if (!mailMessage.To.Any()) - { - return; - } - - var attempt = 0; - var success = false; - while (!success) - { - try - { - await AttemptSendMessageAsync(mailMessage, attempt + 1); - success = true; - } - catch (SmtpException) - { - if (attempt < RetryDelays.Count) - { - await Task.Delay(RetryDelays[attempt]); - attempt++; - } - else - { - throw; - } - } - } - } - - protected virtual Task AttemptSendMessageAsync(MailMessage mailMessage, int attemptNumber) - { - // AnglicanGeek.MarkdownMailer doesn't have an async overload - MailSender.Send(mailMessage); - return Task.CompletedTask; - } - - protected static MailMessage CreateMailMessage(IEmailBuilder emailBuilder) - { - if (emailBuilder == null) - { - throw new ArgumentNullException(nameof(emailBuilder)); - } - - var mailMessage = new MailMessage(); - mailMessage.From = emailBuilder.Sender; - mailMessage.Subject = emailBuilder.GetSubject(); - mailMessage.Body = emailBuilder.GetBody(EmailFormat.Markdown); - - var recipients = emailBuilder.GetRecipients(); - foreach (var toAddress in recipients.To) - { - mailMessage.To.Add(toAddress); - } - - foreach (var ccAddress in recipients.CC) - { - mailMessage.CC.Add(ccAddress); - } - - foreach (var bccAddress in recipients.Bcc) - { - mailMessage.Bcc.Add(bccAddress); - } - - foreach (var replyToAddress in recipients.ReplyTo) - { - mailMessage.ReplyToList.Add(replyToAddress); - } - - return mailMessage; - } - - private async Task SendMessageToSenderAsync(MailMessage mailMessage) - { - using (var senderCopy = new MailMessage( - Configuration.GalleryOwner, - mailMessage.ReplyToList.First())) - { - senderCopy.Subject = mailMessage.Subject + " [Sender Copy]"; - senderCopy.Body = string.Format( - CultureInfo.CurrentCulture, - "You sent the following message via {0}: {1}{1}{2}", - Configuration.GalleryOwner.DisplayName, - Environment.NewLine, - mailMessage.Body); - senderCopy.ReplyToList.Add(mailMessage.ReplyToList.First()); - await SendMessageInternalAsync(senderCopy); - } - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/EmailBuilder.cs b/src/NuGetGallery.Core/Infrastructure/mail/EmailBuilder.cs deleted file mode 100644 index 45fb00b189..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/EmailBuilder.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Net.Mail; -using System.Web; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// Abstract base class for building email messages. - /// - public abstract class EmailBuilder : IEmailBuilder - { - public abstract MailAddress Sender { get; } - - public string GetBody(EmailFormat format) - { - switch (format) - { - case EmailFormat.PlainText: - return GetPlainTextBody(); - case EmailFormat.Markdown: - return GetMarkdownBody(); - default: - throw new ArgumentOutOfRangeException(nameof(format)); - } - } - - public abstract IEmailRecipients GetRecipients(); - - public abstract string GetSubject(); - - protected abstract string GetPlainTextBody(); - protected abstract string GetMarkdownBody(); - - /// - /// Markdown sees the underscore as italics indicator, so underscores are stripped in the message. - /// This prevents cut and pasting of the address or the use of text only email readers. - /// - /// The encoded Url - /// Returns a Markdown-friendly url by escaping underscore characters. - protected string EscapeLinkForMarkdown(string encodedUrl) - { - if (encodedUrl == null) - { - throw new ArgumentNullException(nameof(encodedUrl)); - } - - return HttpUtility.UrlDecode(encodedUrl).Replace("_", "\\_"); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/EmailFormat.cs b/src/NuGetGallery.Core/Infrastructure/mail/EmailFormat.cs deleted file mode 100644 index a50338483f..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/EmailFormat.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// Defines the formatting to be used by for creating email messages. - /// - public enum EmailFormat - { - /// - /// Indicates that will create plain-text email messages, without markup. - /// Used as a fallback by email clients that don't support other formats. - /// - PlainText, - - /// - /// Indicates that will create email messages using Markdown formatting, - /// which will be rendered as HTML by email clients. - /// - Markdown - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/EmailRecipients.cs b/src/NuGetGallery.Core/Infrastructure/mail/EmailRecipients.cs deleted file mode 100644 index 85cc6c4510..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/EmailRecipients.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail -{ - public class EmailRecipients : IEmailRecipients - { - public EmailRecipients( - IReadOnlyList to, - IReadOnlyList cc = null, - IReadOnlyList bcc = null, - IReadOnlyList replyTo = null) - { - To = to ?? throw new ArgumentNullException(nameof(to)); - CC = cc ?? new List(); - Bcc = bcc ?? new List(); - ReplyTo = replyTo ?? new List(); - } - - public static IEmailRecipients None = new EmailRecipients(to: Array.Empty()); - - public IReadOnlyList To { get; } - - public IReadOnlyList CC { get; } - - public IReadOnlyList Bcc { get; } - - public IReadOnlyList ReplyTo { get; } - - public static IReadOnlyList GetAllOwners(PackageRegistration packageRegistration, bool requireEmailAllowed) - { - if (packageRegistration == null) - { - throw new ArgumentNullException(nameof(packageRegistration)); - } - - var recipients = new List(); - var owners = requireEmailAllowed - ? packageRegistration.Owners.Where(o => o.EmailAllowed) - : packageRegistration.Owners; - - foreach (var owner in owners) - { - recipients.Add(owner.ToMailAddress()); - } - - return recipients; - } - - public static IReadOnlyList GetOwnersSubscribedToPackagePushedNotification(PackageRegistration packageRegistration) - { - if (packageRegistration == null) - { - throw new ArgumentNullException(nameof(packageRegistration)); - } - - var recipients = new List(); - foreach (var owner in packageRegistration.Owners.Where(o => o.NotifyPackagePushed)) - { - recipients.Add(owner.ToMailAddress()); - } - - return recipients; - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/IEmailBuilder.cs b/src/NuGetGallery.Core/Infrastructure/mail/IEmailBuilder.cs deleted file mode 100644 index 15db124cb3..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/IEmailBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// Represents an email message builder. - /// - public interface IEmailBuilder - { - /// - /// The sender of the email message. - /// - MailAddress Sender { get; } - - /// - /// Retrieve the email message body in the requested . - /// - /// The requested markup format for the email body. - string GetBody(EmailFormat format); - - /// - /// Gets the email message subject. - /// - string GetSubject(); - - /// - /// Gets the email recipients. - /// - IEmailRecipients GetRecipients(); - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/IEmailRecipients.cs b/src/NuGetGallery.Core/Infrastructure/mail/IEmailRecipients.cs deleted file mode 100644 index 5af7624f28..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/IEmailRecipients.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// Represents a set of email recipients. - /// - public interface IEmailRecipients - { - /// - /// The list of email addresses the email is to be sent to. - /// - IReadOnlyList To { get; } - - /// - /// The list of email addresses to be cc-ed. - /// - IReadOnlyList CC { get; } - - /// - /// The list of email addresses to be bcc-ed. - /// - IReadOnlyList Bcc { get; } - - /// - /// The list of email addresses to be replied to. - /// - IReadOnlyList ReplyTo { get; } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/IMessageService.cs b/src/NuGetGallery.Core/Infrastructure/mail/IMessageService.cs deleted file mode 100644 index 1bf89ab386..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/IMessageService.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; - -namespace NuGetGallery.Infrastructure.Mail -{ - public interface IMessageService - { - /// - /// Sends the message using the provided . - /// - /// The that will create the message. - /// True to send a copy to the sender; otherwise false. - /// - /// True if the sender's email address may be disclosed; otherwise false. - /// If false and is true, a separate email will be sent to the sender. - /// - Task SendMessageAsync(IEmailBuilder emailBuilder, bool copySender = false, bool discloseSenderAddress = false); - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Infrastructure/mail/IMessageServiceConfiguration.cs b/src/NuGetGallery.Core/Infrastructure/mail/IMessageServiceConfiguration.cs deleted file mode 100644 index cbf66b8069..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/IMessageServiceConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail -{ - public interface IMessageServiceConfiguration - { - /// - /// Gets the gallery owner name and email address - /// - MailAddress GalleryOwner { get; set; } - - /// - /// Gets the gallery e-mail from name and email address - /// - MailAddress GalleryNoReplyAddress { get; set; } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextAutoLinkInlineRenderer.cs b/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextAutoLinkInlineRenderer.cs deleted file mode 100644 index 30be82a56e..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextAutoLinkInlineRenderer.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Markdig.Renderers.Normalize; -using Markdig.Syntax.Inlines; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// A Plain Text renderer for a . - /// - internal class PlainTextAutoLinkInlineRenderer : NormalizeObjectRenderer - { - protected override void Write(NormalizeRenderer renderer, AutolinkInline obj) - { - renderer.Write(obj.Url); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextEmphasisInlineRenderer.cs b/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextEmphasisInlineRenderer.cs deleted file mode 100644 index b362e8d88e..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextEmphasisInlineRenderer.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Markdig.Renderers.Normalize; -using Markdig.Syntax.Inlines; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// A Plain Text renderer for an . - /// - internal class PlainTextEmphasisInlineRenderer : NormalizeObjectRenderer - { - protected override void Write(NormalizeRenderer renderer, EmphasisInline obj) - { - renderer.WriteChildren(obj); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextLinkInlineRenderer.cs b/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextLinkInlineRenderer.cs deleted file mode 100644 index 6a0cf9e1c0..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextLinkInlineRenderer.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Markdig.Renderers.Normalize; -using Markdig.Syntax.Inlines; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// A Plain Text renderer for a . - /// - internal class PlainTextLinkInlineRenderer : NormalizeObjectRenderer - { - protected override void Write(NormalizeRenderer renderer, LinkInline link) - { - if (link.IsImage) - { - return; - } - - renderer.WriteChildren(link); - - if (link.Label != null) - { - renderer.Write(link.Label); - } - else if (!string.IsNullOrEmpty(link.Url) && !UrlMatchesChildInline(link)) - { - renderer.Write(" (").Write(link.Url).Write(")"); - - if (!string.IsNullOrEmpty(link.Title)) - { - renderer.Write(" \""); - renderer.Write(link.Title.Replace(@"""", @"\""")); - renderer.Write("\""); - } - } - } - - /// - /// For a given [text](url), checks whether the text value matches the url. - /// - private static bool UrlMatchesChildInline(LinkInline link) - { - if (link.FirstChild != null - && link.FirstChild == link.LastChild - && link.FirstChild is LiteralInline literalInline - && string.Equals(link.Url, literalInline.Content.ToString())) - { - return true; - } - - return false; - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextListRenderer.cs b/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextListRenderer.cs deleted file mode 100644 index cf8b276434..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextListRenderer.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Markdig.Syntax; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// A Plain Text renderer for a . - /// - internal class PlainTextListRenderer : PlainTextRenderer - { - protected override void Write(PlainTextRenderer renderer, ListBlock listBlock) - { - renderer.EnsureLine(); - - foreach (var item in listBlock) - { - renderer.EnsureLine(); - - renderer.WriteChildren((ListItemBlock)item); - } - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextRenderer.cs b/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextRenderer.cs deleted file mode 100644 index b7724d008f..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Internal/PlainTextRenderer.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using Markdig.Renderers; -using Markdig.Renderers.Normalize; -using Markdig.Renderers.Normalize.Inlines; -using Markdig.Syntax; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// A Plain Text renderer. - /// - internal class PlainTextRenderer : NormalizeRenderer - { - public PlainTextRenderer(TextWriter writer) - : base(writer) - { - writer.NewLine = "\r\n"; - - // Replace some default inline renderers to work-around plain-text conversion bugs in Markdig.Markdown.ToPlainText(). - ObjectRenderers.Replace(new PlainTextAutoLinkInlineRenderer()); - ObjectRenderers.Replace(new PlainTextEmphasisInlineRenderer()); - ObjectRenderers.Replace(new PlainTextLinkInlineRenderer()); - } - } - - /// - /// A base class for Plain Text rendering and Markdown objects. - /// - /// The type of the object. - internal abstract class PlainTextRenderer - : MarkdownObjectRenderer where TObject : MarkdownObject - { - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/MarkdownEmailBuilder.cs b/src/NuGetGallery.Core/Infrastructure/mail/MarkdownEmailBuilder.cs deleted file mode 100644 index 961993c7f7..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/MarkdownEmailBuilder.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using Markdig; - -namespace NuGetGallery.Infrastructure.Mail -{ - /// - /// Abstract base class for building email messages relying on Markdown syntax. - /// - public abstract class MarkdownEmailBuilder : EmailBuilder - { - protected override string GetPlainTextBody() - { - var markdown = GetMarkdownBody(); - - var writer = new StringWriter(); - var pipeline = new MarkdownPipelineBuilder().Build(); - - // We override the renderer with our own writer - var renderer = new PlainTextRenderer(writer); - - pipeline.Setup(renderer); - - var document = Markdown.Parse(markdown, pipeline); - renderer.Render(document); - writer.Flush(); - - return writer.ToString(); - } - } -} \ No newline at end of file diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/ContactSupportMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/ContactSupportMessage.cs deleted file mode 100644 index a4677bc90b..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/ContactSupportMessage.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class ContactSupportMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - - public ContactSupportMessage( - IMessageServiceConfiguration configuration, - MailAddress fromAddress, - User requestingUser, - string message, - string reason, - bool copySender) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - FromAddress = fromAddress ?? throw new ArgumentNullException(nameof(fromAddress)); - RequestingUser = requestingUser ?? throw new ArgumentNullException(nameof(requestingUser)); - Message = message ?? throw new ArgumentNullException(nameof(message)); - Reason = reason ?? throw new ArgumentNullException(nameof(reason)); - CopySender = copySender; - } - - public override MailAddress Sender => _configuration.GalleryOwner; - - public MailAddress FromAddress { get; } - public User RequestingUser { get; } - public string Message { get; } - public string Reason { get; } - public bool CopySender { get; } - - public override IEmailRecipients GetRecipients() - => new EmailRecipients( - to: new[] { _configuration.GalleryOwner }, - cc: CopySender ? new[] { FromAddress } : null, - replyTo: new[] { FromAddress }); - - public override string GetSubject() => $"Support Request (Reason: {Reason})"; - - protected override string GetMarkdownBody() - { - return string.Format( - CultureInfo.CurrentCulture, - @"**Email:** {0} ({1}) - -**Reason:** -{2} - -**Message:** -{3}", - RequestingUser.Username, - RequestingUser.EmailAddress, - Reason, - Message); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedMessage.cs deleted file mode 100644 index 4a0163ea02..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedMessage.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class PackageAddedMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly string _packageUrl; - private readonly string _packageSupportUrl; - private readonly string _emailSettingsUrl; - private readonly IEnumerable _warningMessages; - private readonly bool _hasWarnings; - - public PackageAddedMessage( - IMessageServiceConfiguration configuration, - Package package, - string packageUrl, - string packageSupportUrl, - string emailSettingsUrl, - IEnumerable warningMessages) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - Package = package ?? throw new ArgumentNullException(nameof(package)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - _packageSupportUrl = packageSupportUrl ?? throw new ArgumentNullException(nameof(packageSupportUrl)); - _emailSettingsUrl = emailSettingsUrl ?? throw new ArgumentNullException(nameof(emailSettingsUrl)); - _warningMessages = warningMessages; - _hasWarnings = warningMessages != null && warningMessages.Any(); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public Package Package { get; } - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetOwnersSubscribedToPackagePushedNotification(Package.PackageRegistration); - return new EmailRecipients(to); - } - - public override string GetSubject() - { - if (_hasWarnings) - { - return $"[{_configuration.GalleryOwner.DisplayName}] Package published with warnings - {Package.PackageRegistration.Id} {Package.Version}"; - } - else - { - return $"[{_configuration.GalleryOwner.DisplayName}] Package published - {Package.PackageRegistration.Id} {Package.Version}"; - } - } - - protected override string GetMarkdownBody() - { - var warningMessagesPlaceholder = string.Empty; - if (_hasWarnings) - { - warningMessagesPlaceholder = Environment.NewLine + string.Join(Environment.NewLine, _warningMessages); - } - - return $@"The package [{Package.PackageRegistration.Id} {Package.Version}]({_packageUrl}) was recently published on {_configuration.GalleryOwner.DisplayName} by {Package.User.Username}. If this was not intended, please [contact support]({_packageSupportUrl}). -{warningMessagesPlaceholder} - ------------------------------------------------ - - To stop receiving emails as an owner of this package, sign in to the {_configuration.GalleryOwner.DisplayName} and - [change your email notification settings]({_emailSettingsUrl}). -"; - } - - protected override string GetPlainTextBody() - { - // The HTML emphasis tag is not supported by the Plain Text renderer in Markdig. - // Manually overriding this one. - var warningMessagesPlaceholder = string.Empty; - if (_hasWarnings) - { - warningMessagesPlaceholder = Environment.NewLine + string.Join(Environment.NewLine, _warningMessages); - } - - return $@"The package {Package.PackageRegistration.Id} {Package.Version} ({_packageUrl}) was recently published on {_configuration.GalleryOwner.DisplayName} by {Package.User.Username}. If this was not intended, please contact support ({_packageSupportUrl}). -{warningMessagesPlaceholder} - ------------------------------------------------ - To stop receiving emails as an owner of this package, sign in to the {_configuration.GalleryOwner.DisplayName} and - change your email notification settings ({_emailSettingsUrl})."; - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedWithWarningsMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedWithWarningsMessage.cs deleted file mode 100644 index 2f05517aa7..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageAddedWithWarningsMessage.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class PackageAddedWithWarningsMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly Package _package; - private readonly string _packageUrl; - private readonly string _packageSupportUrl; - private readonly IEnumerable _warningMessages; - - public PackageAddedWithWarningsMessage( - IMessageServiceConfiguration configuration, - Package package, - string packageUrl, - string packageSupportUrl, - IEnumerable warningMessages) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _package = package ?? throw new ArgumentNullException(nameof(package)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - _packageSupportUrl = packageSupportUrl ?? throw new ArgumentNullException(nameof(packageSupportUrl)); - _warningMessages = warningMessages ?? throw new ArgumentNullException(nameof(warningMessages)); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetOwnersSubscribedToPackagePushedNotification(_package.PackageRegistration); - return new EmailRecipients(to); - } - - public override string GetSubject() - => $"[{_configuration.GalleryOwner.DisplayName}] Package pushed with warnings - {_package.PackageRegistration.Id} {_package.Version}"; - - protected override string GetMarkdownBody() - { - var warningMessagesPlaceholder = Environment.NewLine + string.Join(Environment.NewLine, _warningMessages); - - return $@"The package [{_package.PackageRegistration.Id} {_package.Version}]({_packageUrl}) was recently pushed to {_configuration.GalleryOwner.DisplayName} by {_package.User.Username}. If this was not intended, please [contact support]({_packageSupportUrl}). -{warningMessagesPlaceholder} -"; - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationFailedMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationFailedMessage.cs deleted file mode 100644 index 0ae79857ab..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationFailedMessage.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using System.Net.Mail; -using System.Text; -using NuGet.Services.Validation; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class PackageValidationFailedMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly Package _package; - private readonly PackageValidationSet _validationSet; - private readonly string _packageUrl; - private readonly string _packageSupportUrl; - private readonly string _announcementsUrl; - private readonly string _twitterUrl; - - public PackageValidationFailedMessage( - IMessageServiceConfiguration configuration, - Package package, - PackageValidationSet validationSet, - string packageUrl, - string packageSupportUrl, - string announcementsUrl, - string twitterUrl) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _package = package ?? throw new ArgumentNullException(nameof(package)); - _validationSet = validationSet ?? throw new ArgumentNullException(nameof(validationSet)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - _packageSupportUrl = packageSupportUrl ?? throw new ArgumentNullException(nameof(packageSupportUrl)); - _announcementsUrl = announcementsUrl ?? throw new ArgumentNullException(nameof(announcementsUrl)); - _twitterUrl = twitterUrl ?? throw new ArgumentNullException(nameof(twitterUrl)); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetAllOwners(_package.PackageRegistration, requireEmailAllowed: false); - return new EmailRecipients(to); - } - - public override string GetSubject() - => $"[{_configuration.GalleryOwner.DisplayName}] Package validation failed - {_package.PackageRegistration.Id} {_package.Version}"; - - protected override string GetMarkdownBody() - { - var validationIssues = _validationSet.GetValidationIssues(); - - var bodyBuilder = new StringBuilder(); - bodyBuilder.Append($@"The package [{_package.PackageRegistration.Id} {_package.Version}]({_packageUrl}) failed validation because of the following reason(s): -"); - - foreach (var validationIssue in validationIssues) - { - bodyBuilder.Append($@" -- {validationIssue.ToMarkdownString(_announcementsUrl, _twitterUrl)}"); - } - - bodyBuilder.Append($@" - -Your package was not published on {_configuration.GalleryOwner.DisplayName} and is not available for consumption. - -"); - - if (validationIssues.Any(i => i.IssueCode == ValidationIssueCode.Unknown)) - { - bodyBuilder.Append($"Please [contact support]({_packageSupportUrl}) to help fix your package."); - } - else - { - var issuePluralString = validationIssues.Count() > 1 ? "all the issues" : "the issue"; - bodyBuilder.Append($"You can reupload your package once you've fixed {issuePluralString} with it."); - } - - return bodyBuilder.ToString(); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationTakingTooLongMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationTakingTooLongMessage.cs deleted file mode 100644 index ffe207a37f..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/PackageValidationTakingTooLongMessage.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class PackageValidationTakingTooLongMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly Package _package; - private readonly string _packageUrl; - - public PackageValidationTakingTooLongMessage( - IMessageServiceConfiguration configuration, - Package package, - string packageUrl) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _package = package ?? throw new ArgumentNullException(nameof(package)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetOwnersSubscribedToPackagePushedNotification(_package.PackageRegistration); - return new EmailRecipients(to); - } - - public override string GetSubject() - => string.Format( - CultureInfo.CurrentCulture, - "[{0}] Package validation taking longer than expected - {1} {2}", - _configuration.GalleryOwner.DisplayName, - _package.PackageRegistration.Id, - _package.Version); - - protected override string GetMarkdownBody() - { - var body = @"It is taking longer than expected for your package [{1} {2}]({3}) to get published. - -We are looking into it and there is no action on you at this time. We’ll send you an email notification when your package has been published. - -Thank you for your patience."; - - return string.Format( - CultureInfo.CurrentCulture, - body, - _configuration.GalleryOwner.DisplayName, - _package.PackageRegistration.Id, - _package.Version, - _packageUrl); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageAddedMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageAddedMessage.cs deleted file mode 100644 index 1899e9daf7..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageAddedMessage.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class SymbolPackageAddedMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly SymbolPackage _symbolPackage; - private readonly string _packageUrl; - private readonly string _packageSupportUrl; - private readonly string _emailSettingsUrl; - private readonly IEnumerable _warningMessages; - private readonly bool _hasWarnings; - - public SymbolPackageAddedMessage( - IMessageServiceConfiguration configuration, - SymbolPackage package, - string packageUrl, - string packageSupportUrl, - string emailSettingsUrl, - IEnumerable warningMessages) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _symbolPackage = package ?? throw new ArgumentNullException(nameof(package)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - _packageSupportUrl = packageSupportUrl ?? throw new ArgumentNullException(nameof(packageSupportUrl)); - _emailSettingsUrl = emailSettingsUrl ?? throw new ArgumentNullException(nameof(emailSettingsUrl)); - _warningMessages = warningMessages; - _hasWarnings = warningMessages != null && warningMessages.Any(); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetOwnersSubscribedToPackagePushedNotification(_symbolPackage.Package.PackageRegistration); - return new EmailRecipients(to); - } - - public override string GetSubject() - { - if (_hasWarnings) - { - return $"[{_configuration.GalleryOwner.DisplayName}] Symbol package published with warnings - {_symbolPackage.Id} {_symbolPackage.Version}"; - } - else - { - return $"[{_configuration.GalleryOwner.DisplayName}] Symbol package published - {_symbolPackage.Id} {_symbolPackage.Version}"; - } - } - - protected override string GetMarkdownBody() - { - var warningMessagesPlaceholder = string.Empty; - if (_hasWarnings) - { - warningMessagesPlaceholder = Environment.NewLine + string.Join(Environment.NewLine, _warningMessages); - } - - return $@"The symbol package [{_symbolPackage.Id} {_symbolPackage.Version}]({_packageUrl}) was recently published on {_configuration.GalleryOwner.DisplayName} by {_symbolPackage.Package.User.Username}. If this was not intended, please [contact support]({_packageSupportUrl}). -{warningMessagesPlaceholder} - ------------------------------------------------ - - To stop receiving emails as an owner of this package, sign in to the {_configuration.GalleryOwner.DisplayName} and - [change your email notification settings]({_emailSettingsUrl}). -"; - } - - protected override string GetPlainTextBody() - { - // The HTML emphasis tag is not supported by the Plain Text renderer in Markdig. - // Manually overriding this one. - var warningMessagesPlaceholder = string.Empty; - if (_hasWarnings) - { - warningMessagesPlaceholder = Environment.NewLine + string.Join(Environment.NewLine, _warningMessages); - } - - return $@"The symbol package {_symbolPackage.Id} {_symbolPackage.Version} ({_packageUrl}) was recently published on {_configuration.GalleryOwner.DisplayName} by {_symbolPackage.Package.User.Username}. If this was not intended, please contact support ({_packageSupportUrl}). -{warningMessagesPlaceholder} - ------------------------------------------------ - To stop receiving emails as an owner of this package, sign in to the {_configuration.GalleryOwner.DisplayName} and - change your email notification settings ({_emailSettingsUrl})."; - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationFailedMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationFailedMessage.cs deleted file mode 100644 index 08deaae1ff..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationFailedMessage.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using System.Net.Mail; -using System.Text; -using NuGet.Services.Validation; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class SymbolPackageValidationFailedMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly SymbolPackage _symbolPackage; - private readonly PackageValidationSet _validationSet; - private readonly string _packageUrl; - private readonly string _packageSupportUrl; - private readonly string _announcementsUrl; - private readonly string _twitterUrl; - - public SymbolPackageValidationFailedMessage( - IMessageServiceConfiguration configuration, - SymbolPackage symbolPackage, - PackageValidationSet validationSet, - string packageUrl, - string packageSupportUrl, - string announcementsUrl, - string twitterUrl) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _symbolPackage = symbolPackage ?? throw new ArgumentNullException(nameof(symbolPackage)); - _validationSet = validationSet ?? throw new ArgumentNullException(nameof(validationSet)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - _packageSupportUrl = packageSupportUrl ?? throw new ArgumentNullException(nameof(packageSupportUrl)); - _announcementsUrl = announcementsUrl ?? throw new ArgumentNullException(nameof(announcementsUrl)); - _twitterUrl = twitterUrl ?? throw new ArgumentNullException(nameof(twitterUrl)); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetAllOwners(_symbolPackage.Package.PackageRegistration, requireEmailAllowed: false); - return new EmailRecipients(to); - } - - public override string GetSubject() - => $"[{_configuration.GalleryOwner.DisplayName}] Symbol package validation failed - {_symbolPackage.Id} {_symbolPackage.Version}"; - - protected override string GetMarkdownBody() - { - var validationIssues = _validationSet.GetValidationIssues(); - - var bodyBuilder = new StringBuilder(); - bodyBuilder.Append($@"The symbol package [{_symbolPackage.Id} {_symbolPackage.Version}]({_packageUrl}) failed validation because of the following reason(s): -"); - - foreach (var validationIssue in validationIssues) - { - bodyBuilder.Append($@" -- {validationIssue.ToMarkdownString(_announcementsUrl, _twitterUrl)}"); - } - - bodyBuilder.Append($@" - -Your symbol package was not published on {_configuration.GalleryOwner.DisplayName} and is not available for consumption. - -"); - - if (validationIssues.Any(i => i.IssueCode == ValidationIssueCode.Unknown)) - { - bodyBuilder.Append($"Please [contact support]({_packageSupportUrl}) to help."); - } - else - { - var issuePluralString = validationIssues.Count() > 1 ? "all the issues" : "the issue"; - bodyBuilder.Append($"You can reupload your symbol package once you've fixed {issuePluralString} with it."); - } - - return bodyBuilder.ToString(); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationTakingTooLongMessage.cs b/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationTakingTooLongMessage.cs deleted file mode 100644 index c9149482ac..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/Messages/SymbolPackageValidationTakingTooLongMessage.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Globalization; -using System.Net.Mail; - -namespace NuGetGallery.Infrastructure.Mail.Messages -{ - public class SymbolPackageValidationTakingTooLongMessage : MarkdownEmailBuilder - { - private readonly IMessageServiceConfiguration _configuration; - private readonly SymbolPackage _symbolPackage; - private readonly string _packageUrl; - - public SymbolPackageValidationTakingTooLongMessage( - IMessageServiceConfiguration configuration, - SymbolPackage symbolPackage, - string packageUrl) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _symbolPackage = symbolPackage ?? throw new ArgumentNullException(nameof(symbolPackage)); - _packageUrl = packageUrl ?? throw new ArgumentNullException(nameof(packageUrl)); - } - - public override MailAddress Sender => _configuration.GalleryNoReplyAddress; - - public override IEmailRecipients GetRecipients() - { - var to = EmailRecipients.GetOwnersSubscribedToPackagePushedNotification(_symbolPackage.Package.PackageRegistration); - return new EmailRecipients(to); - } - - public override string GetSubject() - => string.Format( - CultureInfo.CurrentCulture, - "[{0}] Symbol package validation taking longer than expected - {1} {2}", - _configuration.GalleryOwner.DisplayName, - _symbolPackage.Package.PackageRegistration.Id, - _symbolPackage.Version); - - protected override string GetMarkdownBody() - { - var body = @"It is taking longer than expected for your symbol package [{1} {2}]({3}) to get published. - -We are looking into it and there is no action on you at this time. We’ll send you an email notification when your symbol package has been published. - -Thank you for your patience."; - - return string.Format( - CultureInfo.CurrentCulture, - body, - _configuration.GalleryOwner.DisplayName, - _symbolPackage.Id, - _symbolPackage.Version, - _packageUrl); - } - } -} diff --git a/src/NuGetGallery.Core/Infrastructure/mail/ValidationIssueExtensions.cs b/src/NuGetGallery.Core/Infrastructure/mail/ValidationIssueExtensions.cs deleted file mode 100644 index 830317d8c2..0000000000 --- a/src/NuGetGallery.Core/Infrastructure/mail/ValidationIssueExtensions.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using NuGet.Services.Validation; -using NuGet.Services.Validation.Issues; - -namespace NuGetGallery.Infrastructure.Mail -{ - internal static class ValidationIssueExtensions - { - /// - /// Returns a Markdown representation describing the in a user-friendly way. - /// - public static string ToMarkdownString(this ValidationIssue validationIssue, string announcementsUrl, string twitterUrl) - { - if (validationIssue == null) - { - throw new ArgumentNullException(nameof(validationIssue)); - } - - if (announcementsUrl == null) - { - throw new ArgumentNullException(nameof(announcementsUrl)); - } - - if (twitterUrl == null) - { - throw new ArgumentNullException(nameof(twitterUrl)); - } - - switch (validationIssue.IssueCode) - { - case ValidationIssueCode.PackageIsSigned: - return $"This package could not be published since it is signed. We do not accept signed packages at this moment. To be notified about package signing and more, watch our [Announcements]({announcementsUrl}) page or follow us on [Twitter]({twitterUrl})."; - case ValidationIssueCode.ClientSigningVerificationFailure: - var clientIssue = (ClientSigningVerificationFailure)validationIssue; - return clientIssue != null - ? $"**{clientIssue.ClientCode}**: {clientIssue.ClientMessage}" - : "This package's signature was unable to get verified."; - case ValidationIssueCode.PackageIsZip64: - return "Zip64 packages are not supported."; - case ValidationIssueCode.OnlyAuthorSignaturesSupported: - return "Signed packages must only have an author signature. Other signature types are not supported."; - case ValidationIssueCode.AuthorAndRepositoryCounterSignaturesNotSupported: - return "Author countersignatures and repository countersignatures are not supported."; - case ValidationIssueCode.OnlySignatureFormatVersion1Supported: - return "**NU3007:** Package signatures must have format version 1."; - case ValidationIssueCode.AuthorCounterSignaturesNotSupported: - return "Author countersignatures are not supported."; - case ValidationIssueCode.PackageIsNotSigned: - return "This package must be signed with a registered certificate. [Read more...](https://aka.ms/nuget-signed-ref)"; - case ValidationIssueCode.PackageIsSignedWithUnauthorizedCertificate: - var certIssue = (UnauthorizedCertificateFailure)validationIssue; - return $"The package was signed, but the signing certificate {(certIssue != null ? $"(SHA-1 thumbprint {certIssue.Sha1Thumbprint})" : "")} is not associated with your account. You must register this certificate to publish signed packages. [Read more...](https://aka.ms/nuget-signed-ref)"; - case ValidationIssueCode.SymbolErrorCode_ChecksumDoesNotMatch: - return "The checksum does not match for the dll(s) and corresponding pdb(s)."; - case ValidationIssueCode.SymbolErrorCode_MatchingPortablePDBNotFound: - return "The uploaded symbols package contains pdb(s) for a corresponding dll(s) not found in the nuget package."; - default: - return "There was an unknown failure when validating your package."; - } - } - } -} diff --git a/src/NuGetGallery.Core/NuGetGallery.Core.csproj b/src/NuGetGallery.Core/NuGetGallery.Core.csproj index 33f8a5cfe0..f431a94ec7 100644 --- a/src/NuGetGallery.Core/NuGetGallery.Core.csproj +++ b/src/NuGetGallery.Core/NuGetGallery.Core.csproj @@ -113,23 +113,10 @@ - - - - - - - - - - - - - @@ -138,64 +125,20 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -214,11 +157,11 @@ - + @@ -230,7 +173,6 @@ - @@ -260,8 +202,11 @@ - - 0.15.3 + + 2.31.0 + + + 2.31.0 1.2.0 @@ -294,13 +239,13 @@ all - 4.8.0-preview4.5287 + 4.8.0 - 2.29.0 + 2.31.0 - 2.29.0 + 2.31.0 7.1.2 diff --git a/src/NuGetGallery.Core/PackageStatus.cs b/src/NuGetGallery.Core/PackageStatus.cs deleted file mode 100644 index 8bc10e9a99..0000000000 --- a/src/NuGetGallery.Core/PackageStatus.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace NuGetGallery -{ - public enum PackageStatus - { - /// - /// The package is visible and available for all normal package operations. - /// - Available = 0, - - /// - /// The package has been soft deleted. This means that the package is not available but the package ID and - /// version are still reserved. - /// - Deleted = 1, - - /// - /// The package is in the process of being validated. The validation is being done asynchronously. When the - /// validation is complete it will move to the , , or - /// state. When packages are in this state, they are not available but the - /// package ID and version are still reserved. - /// - Validating = 2, - - /// - /// The package has completed validation and the result has come back as a failure. When packages are in this - /// state, they are not available but the package ID and version are still reserved. - /// - FailedValidation = 3, - } -} diff --git a/src/NuGetGallery.Core/Packaging/PackageIdValidator.cs b/src/NuGetGallery.Core/Packaging/PackageIdValidator.cs index ee795f133e..37606a5f9d 100644 --- a/src/NuGetGallery.Core/Packaging/PackageIdValidator.cs +++ b/src/NuGetGallery.Core/Packaging/PackageIdValidator.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using System.Text.RegularExpressions; +using NuGet.Services.Entities; namespace NuGetGallery.Packaging { @@ -33,15 +34,15 @@ public static void ValidatePackageId(string packageId) throw new ArgumentNullException(nameof(packageId)); } - if (packageId.Length > CoreConstants.MaxPackageIdLength) + if (packageId.Length > Constants.MaxPackageIdLength) { - throw new ArgumentException($"Id must not exceed {CoreConstants.MaxPackageIdLength} characters."); + throw new ArgumentException($"Id must not exceed {Constants.MaxPackageIdLength} characters."); } if (!IsValidPackageId(packageId)) { throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, + CultureInfo.CurrentCulture, "The package ID '{0}' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'.", packageId)); } diff --git a/src/NuGetGallery.Core/SemVerLevelKey.cs b/src/NuGetGallery.Core/SemVerLevelKey.cs index d69b753f5b..efcc7bc814 100644 --- a/src/NuGetGallery.Core/SemVerLevelKey.cs +++ b/src/NuGetGallery.Core/SemVerLevelKey.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using NuGet.Services.Entities; using NuGet.Versioning; namespace NuGetGallery diff --git a/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs b/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs index 95c91c214a..c709e9ceab 100644 --- a/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs +++ b/src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs @@ -426,6 +426,27 @@ public async Task SetMetadataAsync( } } + public async Task GetETagOrNullAsync( + string folderName, + string fileName) + { + folderName = folderName ?? throw new ArgumentNullException(nameof(folderName)); + fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); + + var container = await GetContainerAsync(folderName); + var blob = container.GetBlobReference(fileName); + try + { + await blob.FetchAttributesAsync(); + return blob.ETag; + } + // In case that the blob does not exist return null. + catch (StorageException) + { + return null; + } + } + private static SharedAccessBlobPermissions MapFileUriPermissions(FileUriPermissions permissions) { return (SharedAccessBlobPermissions)permissions; diff --git a/src/NuGetGallery.Core/Services/CorePackageFileService.cs b/src/NuGetGallery.Core/Services/CorePackageFileService.cs index c7e7c3c945..87e992608b 100644 --- a/src/NuGetGallery.Core/Services/CorePackageFileService.cs +++ b/src/NuGetGallery.Core/Services/CorePackageFileService.cs @@ -6,6 +6,7 @@ using System.IO; using System.Threading.Tasks; using System.Web; +using NuGet.Services.Entities; using NuGet.Versioning; namespace NuGetGallery diff --git a/src/NuGetGallery.Core/Services/CorePackageService.cs b/src/NuGetGallery.Core/Services/CorePackageService.cs index 5387c03f5f..6c262fbb49 100644 --- a/src/NuGetGallery.Core/Services/CorePackageService.cs +++ b/src/NuGetGallery.Core/Services/CorePackageService.cs @@ -5,6 +5,7 @@ using System.Data.Entity; using System.Linq; using System.Threading.Tasks; +using NuGet.Services.Entities; using NuGet.Versioning; using NuGetGallery.Packaging; diff --git a/src/NuGetGallery.Core/Services/CoreSymbolPackageService.cs b/src/NuGetGallery.Core/Services/CoreSymbolPackageService.cs index 7b5025e286..c143ee7fc4 100644 --- a/src/NuGetGallery.Core/Services/CoreSymbolPackageService.cs +++ b/src/NuGetGallery.Core/Services/CoreSymbolPackageService.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Services/ICoreFileStorageService.cs b/src/NuGetGallery.Core/Services/ICoreFileStorageService.cs index 184eff8367..0914455990 100644 --- a/src/NuGetGallery.Core/Services/ICoreFileStorageService.cs +++ b/src/NuGetGallery.Core/Services/ICoreFileStorageService.cs @@ -120,5 +120,15 @@ Task SetMetadataAsync( string folderName, string fileName, Func>, IDictionary, Task> updateMetadataAsync); + + /// + /// Returns the etag value for the specified blob. If the blob does not exists it will return null. + /// + /// The folder name. + /// The file name. + /// The etag of the specified file. + Task GetETagOrNullAsync( + string folderName, + string fileName); } } \ No newline at end of file diff --git a/src/NuGetGallery.Core/Services/ICorePackageFileService.cs b/src/NuGetGallery.Core/Services/ICorePackageFileService.cs index b155a283ac..a5e2c9c6f4 100644 --- a/src/NuGetGallery.Core/Services/ICorePackageFileService.cs +++ b/src/NuGetGallery.Core/Services/ICorePackageFileService.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Threading.Tasks; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Services/ICorePackageService.cs b/src/NuGetGallery.Core/Services/ICorePackageService.cs index 370eb1d041..d35f5dc1f7 100644 --- a/src/NuGetGallery.Core/Services/ICorePackageService.cs +++ b/src/NuGetGallery.Core/Services/ICorePackageService.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using NuGet.Services.Entities; using NuGetGallery.Packaging; namespace NuGetGallery diff --git a/src/NuGetGallery.Core/Services/ICoreSymbolPackageService.cs b/src/NuGetGallery.Core/Services/ICoreSymbolPackageService.cs index f03311c867..e4e012505b 100644 --- a/src/NuGetGallery.Core/Services/ICoreSymbolPackageService.cs +++ b/src/NuGetGallery.Core/Services/ICoreSymbolPackageService.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -using NuGetGallery.Packaging; +using NuGet.Services.Entities; namespace NuGetGallery { diff --git a/src/NuGetGallery.Core/Services/PackageAlreadyExistsException.cs b/src/NuGetGallery.Core/Services/PackageAlreadyExistsException.cs new file mode 100644 index 0000000000..6748c7d5a4 --- /dev/null +++ b/src/NuGetGallery.Core/Services/PackageAlreadyExistsException.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace NuGetGallery +{ + [Serializable] + public sealed class PackageAlreadyExistsException : Exception + { + public PackageAlreadyExistsException() { } + public PackageAlreadyExistsException(string message) : base(message) { } + public PackageAlreadyExistsException(string message, Exception inner) : base(message, inner) { } + } +} \ No newline at end of file diff --git a/src/NuGetGallery/App_Code/ViewHelpers.cshtml b/src/NuGetGallery/App_Code/ViewHelpers.cshtml index 84e04c4a5a..86233edca8 100644 --- a/src/NuGetGallery/App_Code/ViewHelpers.cshtml +++ b/src/NuGetGallery/App_Code/ViewHelpers.cshtml @@ -1,11 +1,10 @@ @using System.Web.Mvc @using System.Web.Routing -@using System.Web.Mvc.Html -@using Microsoft.Web.Helpers @using NuGetGallery @using NuGetGallery.Helpers @using NuGetGallery.Configuration @using NuGetGallery.Cookies +@using NuGet.Services.Entities @helper GetColumnClasses(string screenSize, int? columns) { @@ -41,7 +40,7 @@ @helper Alert(Func htmlContent, string subclass, string icon, bool isAlertRole = false) { -
role="alert" aria-live="assertive" }> +
role="alert" aria-live="assertive" }> @htmlContent(MvcHtmlString.Empty)
@@ -243,7 +242,8 @@ }); } -@helper UserLinkWithIcon(UrlHelper url, User user) { +@helper UserLinkWithIcon(UrlHelper url, User user) +{ @if (user is Organization) { @@ -253,17 +253,21 @@ } -@helper WriteMeta(string name, string val) { - if(!String.IsNullOrEmpty(val)) { +@helper WriteMeta(string name, string val) +{ + if (!String.IsNullOrEmpty(val)) + { } } -@helper ReleaseMeta() { +@helper ReleaseMeta() +{ // Get Version info var ver = ApplicationVersionHelper.GetVersion(); - if(ver.Present) { + if (ver.Present) + { WriteMeta("branch", ver.Branch); WriteMeta("commit", ver.ShortCommit); WriteMeta("time", ver.BuildDateUtc == DateTime.MinValue ? null : ver.BuildDateUtc.ToString("O")); @@ -344,14 +348,15 @@ @helper AnalyticsScript() { var config = DependencyResolver.Current.GetService(); - if(config != null) { + if (config != null) + { var propertyId = config.Current.GoogleAnalyticsPropertyId; if (!string.IsNullOrEmpty(propertyId)) { var cookieService = DependencyResolver.Current.GetService(); if (cookieService.CanWriteNonEssentialCookies(Request)) { - var obfuscatedRequest = ObfuscationHelper.ObfuscateRequestUrl(new HttpContextWrapper(HttpContext.Current), RouteTable.Routes); + var obfuscatedRequest = ObfuscationHelper.ObfuscateRequestUrl(new HttpContextWrapper(HttpContext.Current), RouteTable.Routes); @Scripts.Render("~/Scripts/gallery/page-add-organization.min.js") } \ No newline at end of file diff --git a/src/NuGetGallery/Views/Organizations/DeleteAccount.cshtml b/src/NuGetGallery/Views/Organizations/DeleteAccount.cshtml index b2161a6bd1..fbb8c0256d 100644 --- a/src/NuGetGallery/Views/Organizations/DeleteAccount.cshtml +++ b/src/NuGetGallery/Views/Organizations/DeleteAccount.cshtml @@ -1,7 +1,7 @@ @model DeleteOrganizationViewModel @{ ViewBag.Title = "Delete Organization " + Model.AccountName; - ViewBag.MdPageColumns = Constants.ColumnsFormMd; + ViewBag.MdPageColumns = GalleryConstants.ColumnsFormMd; }

- + Delete Symbols Package Version

-
+
@ViewHelpers.AlertDanger( @ - Deleting this symbols package will remove all the symbols from the symbol server and make them unavailable.
+ Deleting this symbols package will remove all symbols in this package from the symbol server and make them unavailable.
) @using (Html.BeginForm("DeleteSymbolsPackage", "Packages", FormMethod.Post, new { id = "delete-symbols-form" })) diff --git a/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml b/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml index 7698cd36b7..9968291441 100644 --- a/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml +++ b/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml @@ -1,4 +1,3 @@ - @using NuGet.Services.Validation; @model DisplayPackageViewModel @@ -79,7 +78,7 @@ @helper VersionListDivider(int rowCount, bool versionsExpanded) { - if (rowCount == Constants.VisibleVersions + 1) + if (rowCount == GalleryConstants.VisibleVersions + 1) { @: } @@ -276,9 +275,8 @@ { @ViewHelpers.AlertWarning( @ - The symbols for this package have not been indexed yet. They are not available - for download from the NuGet.org symbol server. Symbols will be indexed and will - be available for download after both validation and indexing are complete. + The symbols for this package have not been indexed yet. They are not available + for download from the NuGet.org symbol server. Symbols will be available for download after both validation and indexing are complete. Symbols validation and indexing may take up to an hour. Read more. ) @@ -486,7 +484,7 @@ var rowCount = 0; var versionsExpanded = Model .PackageVersions - .Skip(Constants.VisibleVersions) + .Skip(GalleryConstants.VisibleVersions) .Any(v => v.IsCurrent(Model)); } @foreach (var packageVersion in Model.PackageVersions) @@ -560,7 +558,7 @@ } - @if (rowCount > Constants.VisibleVersions) + @if (rowCount > GalleryConstants.VisibleVersions) { @@ -722,10 +720,13 @@ Revalidate package -
  • - - Revalidate symbols -
  • + if (Model.LatestSymbolsPackage != null) + { +
  • + + Revalidate symbols +
  • + } } @if (User.IsAdministrator() && Config.Current.AsynchronousPackageValidationEnabled) @@ -776,7 +777,7 @@ foreach (var owner in Model.Owners)
  • @if (!String.IsNullOrEmpty(owner.EmailAddress)) { - @ViewHelpers.GravatarImage(owner.EmailAddress, owner.Username, Constants.GravatarElementSize) + @ViewHelpers.GravatarImage(owner.EmailAddress, owner.Username, GalleryConstants.GravatarElementSize) } @owner.Username diff --git a/src/NuGetGallery/Views/Packages/Edit.cshtml b/src/NuGetGallery/Views/Packages/Edit.cshtml index 0dee88cb10..860079d3e7 100644 --- a/src/NuGetGallery/Views/Packages/Edit.cshtml +++ b/src/NuGetGallery/Views/Packages/Edit.cshtml @@ -2,7 +2,7 @@ @{ ViewBag.Title = "Editing: " + Model.PackageId + " " + Model.Version; ViewBag.Tab = "Packages"; - ViewBag.MdPageColumns = Constants.ColumnsFormMd; + ViewBag.MdPageColumns = GalleryConstants.ColumnsFormMd; } @@ -46,14 +59,24 @@
    @ViewHelpers.AlertWarning( - @ - We found the following issue(s): -
      -
    • -
    - We recommend that you fix these issues and upload a new package. -
    Read more
    - ) + @ + We found the following issue(s): +
      + +
    • + + + +
    • + + +
    • + + +
    + We recommend that you fix these issues and upload a new package. + Read more
    +
    )
    @@ -121,6 +144,7 @@
    +
    @@ -136,7 +160,6 @@
    -
    (for this version)
    diff --git a/src/NuGetGallery/Views/Pages/Contact.cshtml b/src/NuGetGallery/Views/Pages/Contact.cshtml index 8cd8dd4ea0..5186b4adc3 100644 --- a/src/NuGetGallery/Views/Pages/Contact.cshtml +++ b/src/NuGetGallery/Views/Pages/Contact.cshtml @@ -2,7 +2,7 @@ @model ContactSupportViewModel @{ ViewBag.Title = "Contact"; - ViewBag.MdPageColumns = Constants.ColumnsFormMd; + ViewBag.MdPageColumns = GalleryConstants.ColumnsFormMd; }
    diff --git a/src/NuGetGallery/Views/Shared/Confirm.cshtml b/src/NuGetGallery/Views/Shared/Confirm.cshtml index 659bdc3e83..9dbb74a694 100644 --- a/src/NuGetGallery/Views/Shared/Confirm.cshtml +++ b/src/NuGetGallery/Views/Shared/Confirm.cshtml @@ -2,8 +2,8 @@ @{ var titleString = Model.ConfirmingNewAccount ? (Model.IsOrganization ? "Organization" : "Account") : "Email"; ViewBag.Title = "Confirm Your " + titleString; - ViewBag.SmPageColumns = Constants.ColumnsWideAuthenticationSm; - ViewBag.MdPageColumns = Constants.ColumnsWideAuthenticationMd; + ViewBag.SmPageColumns = GalleryConstants.ColumnsWideAuthenticationSm; + ViewBag.MdPageColumns = GalleryConstants.ColumnsWideAuthenticationMd; }
    diff --git a/src/NuGetGallery/Views/Shared/ConfirmationRequired.cshtml b/src/NuGetGallery/Views/Shared/ConfirmationRequired.cshtml index 9c07f2e43d..0219f6412b 100644 --- a/src/NuGetGallery/Views/Shared/ConfirmationRequired.cshtml +++ b/src/NuGetGallery/Views/Shared/ConfirmationRequired.cshtml @@ -3,8 +3,8 @@ ViewBag.Title = "Confirm Your " + (Model.IsOrganization ? "Organization " : "") + (Model.ConfirmingNewAccount ? "Account" : "Email"); - ViewBag.SmPageColumns = Constants.ColumnsWideAuthenticationSm; - ViewBag.MdPageColumns = Constants.ColumnsWideAuthenticationMd; + ViewBag.SmPageColumns = GalleryConstants.ColumnsWideAuthenticationSm; + ViewBag.MdPageColumns = GalleryConstants.ColumnsWideAuthenticationMd; if (Model.IsOrganization) { diff --git a/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml b/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml index 9c8e0dc86f..490408b9ec 100644 --- a/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml +++ b/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml @@ -94,7 +94,7 @@