Skip to content

Commit

Permalink
Remove organizations feature flag (#5822)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Bommarito authored Apr 18, 2018
1 parent e6d0113 commit 2c222f7
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 194 deletions.
16 changes: 2 additions & 14 deletions src/NuGetGallery/Services/LoginDiscontinuationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ public class LoginDiscontinuationConfiguration : ILoginDiscontinuationConfigurat
internal HashSet<string> ExceptionsForEmailAddresses { get; }
internal HashSet<string> ForceTransformationToOrganizationForEmailAddresses { get; }
internal HashSet<OrganizationTenantPair> EnabledOrganizationAadTenants { get; }
internal bool OrganizationsEnabledForAll { get; }

public LoginDiscontinuationConfiguration()
: this(Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
Enumerable.Empty<OrganizationTenantPair>(),
organizationsEnabledForAll: false)
Enumerable.Empty<OrganizationTenantPair>())
{
}

Expand All @@ -35,15 +33,13 @@ public LoginDiscontinuationConfiguration(
IEnumerable<string> discontinuedForDomains,
IEnumerable<string> exceptionsForEmailAddresses,
IEnumerable<string> forceTransformationToOrganizationForEmailAddresses,
IEnumerable<OrganizationTenantPair> enabledOrganizationAadTenants,
bool organizationsEnabledForAll)
IEnumerable<OrganizationTenantPair> enabledOrganizationAadTenants)
{
DiscontinuedForEmailAddresses = new HashSet<string>(discontinuedForEmailAddresses, StringComparer.OrdinalIgnoreCase);
DiscontinuedForDomains = new HashSet<string>(discontinuedForDomains, StringComparer.OrdinalIgnoreCase);
ExceptionsForEmailAddresses = new HashSet<string>(exceptionsForEmailAddresses, StringComparer.OrdinalIgnoreCase);
ForceTransformationToOrganizationForEmailAddresses = new HashSet<string>(forceTransformationToOrganizationForEmailAddresses, StringComparer.OrdinalIgnoreCase);
EnabledOrganizationAadTenants = new HashSet<OrganizationTenantPair>(enabledOrganizationAadTenants, new OrganizationTenantPairComparer());
OrganizationsEnabledForAll = organizationsEnabledForAll;
}

public bool IsLoginDiscontinued(AuthenticatedUser authUser)
Expand Down Expand Up @@ -73,13 +69,6 @@ public bool IsUserOnWhitelist(User user)
DiscontinuedForEmailAddresses.Contains(email.Address);
}

public bool AreOrganizationsSupportedForUser(User user)
{
return OrganizationsEnabledForAll ||
(user != null &&
(user.Organizations.Any() || IsUserOnWhitelist(user)));
}

public bool ShouldUserTransformIntoOrganization(User user)
{
if (user == null)
Expand All @@ -101,7 +90,6 @@ public interface ILoginDiscontinuationConfiguration
{
bool IsLoginDiscontinued(AuthenticatedUser authUser);
bool IsUserOnWhitelist(User user);
bool AreOrganizationsSupportedForUser(User user);
bool ShouldUserTransformIntoOrganization(User user);
bool IsTenantIdPolicySupportedForOrganization(string emailAddress, string tenantId);
}
Expand Down
11 changes: 0 additions & 11 deletions src/NuGetGallery/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ public bool CanTransformUserToOrganization(User accountToTransform, out string e
{
errorReason = Strings.TransformAccount_AccountHasMemberships;
}
else if (!ContentObjectService.LoginDiscontinuationConfiguration.AreOrganizationsSupportedForUser(accountToTransform))
{
errorReason = String.Format(CultureInfo.CurrentCulture,
Strings.Organizations_NotSupportedForAccount, accountToTransform.Username);
}

return errorReason == null;
}
Expand Down Expand Up @@ -498,12 +493,6 @@ public async Task<bool> TransformUserToOrganization(User accountToTransform, Use

public async Task<Organization> AddOrganizationAsync(string username, string emailAddress, User adminUser)
{
if (!ContentObjectService.LoginDiscontinuationConfiguration.AreOrganizationsSupportedForUser(adminUser))
{
throw new EntityException(String.Format(CultureInfo.CurrentCulture,
Strings.Organizations_NotSupportedForAccount, adminUser.Username));
}

var existingUserWithIdentity = EntitiesContext.Users
.FirstOrDefault(u => u.Username == username || u.EmailAddress == emailAddress);
if (existingUserWithIdentity != null)
Expand Down
9 changes: 0 additions & 9 deletions src/NuGetGallery/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/NuGetGallery/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,4 @@ If you wish to update the linked Microsoft account you can do so from the accoun
<data name="AddMember_UserIsOrganization" xml:space="preserve">
<value>User '{0}' is an organization and cannot be a member of another organization.</value>
</data>
<data name="Organizations_NotSupportedForAccount" xml:space="preserve">
<value>Account '{0}' does not support organizations.</value>
</data>
</root>
5 changes: 1 addition & 4 deletions src/NuGetGallery/Views/Shared/Gallery/Header.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@
</li>
<li role="presentation"><a href="@Url.ManageMyApiKeys()" role="menuitem">API Keys</a></li>
<li class="divider"></li>
@if (ContentObjectService.Value.LoginDiscontinuationConfiguration.AreOrganizationsSupportedForUser(CurrentUser))
{
<li role="presentation"><a href="@Url.ManageMyOrganizations()" role="menuitem">Manage Organizations</a></li>
}
<li role="presentation"><a href="@Url.ManageMyOrganizations()" role="menuitem">Manage Organizations</a></li>
<li role="presentation"><a href="@Url.ManageMyPackages()" role="menuitem">Manage Packages</a></li>
<li role="presentation"><a href="@Url.UploadPackage()" role="menuitem">Upload Package</a></li>
<li class="divider"></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public async Task RefreshRefreshesObject()
var exceptions = new[] { "[email protected]" };
var shouldTransforms = new[] { "[email protected]" };
var orgTenantPairs = new[] { new OrganizationTenantPair("example.com", "tenantId") };
var orgsEnabledForAll = true;

var config = new LoginDiscontinuationConfiguration(emails, domains, exceptions, shouldTransforms, orgTenantPairs, orgsEnabledForAll);
var config = new LoginDiscontinuationConfiguration(emails, domains, exceptions, shouldTransforms, orgTenantPairs);
var configString = JsonConvert.SerializeObject(config);

GetMock<IContentService>()
Expand All @@ -54,7 +53,6 @@ public async Task RefreshRefreshesObject()
Assert.True(loginDiscontinuationConfiguration.DiscontinuedForDomains.SequenceEqual(domains));
Assert.True(loginDiscontinuationConfiguration.ExceptionsForEmailAddresses.SequenceEqual(exceptions));
Assert.True(loginDiscontinuationConfiguration.EnabledOrganizationAadTenants.SequenceEqual(orgTenantPairs));
Assert.Equal(orgsEnabledForAll, loginDiscontinuationConfiguration.OrganizationsEnabledForAll);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ public static IEnumerable<object[]> PossibleListStates
{
foreach (var isOnTenantPairList in new[] { true, false })
{
foreach (var organizationsEnabledForAll in new[] { true, false })
foreach (var isWrongCase in new[] { true, false })
{
foreach (var isWrongCase in new[] { true, false })
{
yield return MemberDataHelper.AsData(isOnWhiteList, isOnDomainList, isOnExceptionList, isOnTransformList, isOnTenantPairList, organizationsEnabledForAll, isWrongCase);
}
yield return MemberDataHelper.AsData(isOnWhiteList, isOnDomainList, isOnExceptionList, isOnTransformList, isOnTenantPairList, isWrongCase);
}
}
}
Expand All @@ -48,7 +45,7 @@ public static IEnumerable<object[]> PossibleListStates
}
}

public static ILoginDiscontinuationConfiguration CreateConfiguration(bool isOnWhiteList, bool isOnDomainList, bool isOnExceptionList, bool isOnTransformList, bool isOnTenantPairList, bool organizationsEnabledForAll, bool isWrongCase)
public static ILoginDiscontinuationConfiguration CreateConfiguration(bool isOnWhiteList, bool isOnDomainList, bool isOnExceptionList, bool isOnTransformList, bool isOnTenantPairList, bool isWrongCase)
{
var emails = isOnWhiteList ? new[] { ToUppercaseIfWrongCase(_email, isWrongCase) } : new[] { ToUppercaseIfWrongCase(_incorrectEmail, isWrongCase) };
var domains = isOnDomainList ? new[] { ToUppercaseIfWrongCase(_domain, isWrongCase) } : new[] { ToUppercaseIfWrongCase(_incorrectDomain, isWrongCase) };
Expand All @@ -58,7 +55,7 @@ public static ILoginDiscontinuationConfiguration CreateConfiguration(bool isOnWh
new[] { new OrganizationTenantPair(ToUppercaseIfWrongCase(_domain, isWrongCase), ToUppercaseIfWrongCase(_tenant, isWrongCase)) } :
new[] { new OrganizationTenantPair(ToUppercaseIfWrongCase(_incorrectDomain, isWrongCase), ToUppercaseIfWrongCase(_incorrectTenant, isWrongCase)) };

return new LoginDiscontinuationConfiguration(emails, domains, exceptions, shouldTransforms, orgTenantPairs, organizationsEnabledForAll);
return new LoginDiscontinuationConfiguration(emails, domains, exceptions, shouldTransforms, orgTenantPairs);
}

private static string ToUppercaseIfWrongCase(string input, bool isWrongCase)
Expand Down Expand Up @@ -152,7 +149,7 @@ private void TestIsLoginDiscontinued(string credentialType, bool isOnWhiteList,
var user = new User("test") { EmailAddress = _email, Credentials = new[] { credential } };
var authUser = new AuthenticatedUser(user, credential);

var config = CreateConfiguration(isOnWhiteList, isOnDomainList, isOnExceptionList, isOnTransformList, isOnTenantPairList: false, organizationsEnabledForAll: false, isWrongCase: isWrongCase);
var config = CreateConfiguration(isOnWhiteList, isOnDomainList, isOnExceptionList, isOnTransformList, isOnTenantPairList: false, isWrongCase: isWrongCase);

// Act
var result = config.IsLoginDiscontinued(authUser);
Expand All @@ -169,7 +166,6 @@ public class WhitelistMethodData
public bool IsOnExceptionList { get; }
public bool IsOnTransformList { get; }
public bool IsOnTenantPairList { get; }
public bool OrganizationsEnabledForAll { get; }
public bool IsWrongCase { get; }

public WhitelistMethodData(object[] data)
Expand All @@ -191,10 +187,7 @@ public WhitelistMethodData(object[] data)
var isOnTenantPairList = boolData[4];
IsOnTenantPairList = isOnTenantPairList;

var organizationsEnabledForAll = boolData[5];
OrganizationsEnabledForAll = organizationsEnabledForAll;

var isWrongCase = boolData[6];
var isWrongCase = boolData[5];
IsWrongCase = isWrongCase;
}
}
Expand Down Expand Up @@ -248,7 +241,7 @@ public void ReturnsExpectedWhenNull(WhitelistMethodData data)

private ILoginDiscontinuationConfiguration GetConfiguration(WhitelistMethodData data)
{
return CreateConfiguration(data.IsOnWhiteList, data.IsOnDomainList, data.IsOnExceptionList, data.IsOnTransformList, data.IsOnTenantPairList, data.OrganizationsEnabledForAll, data.IsWrongCase);
return CreateConfiguration(data.IsOnWhiteList, data.IsOnDomainList, data.IsOnExceptionList, data.IsOnTransformList, data.IsOnTenantPairList, data.IsWrongCase);
}
}

Expand Down Expand Up @@ -295,56 +288,5 @@ protected override bool GetWhitelistValue(ILoginDiscontinuationConfiguration con
return config.ShouldUserTransformIntoOrganization(user);
}
}

public class TheAreOrganizationsSupportedForUserMethodData : WhitelistMethodData
{
public bool HasOrganization { get; }

public TheAreOrganizationsSupportedForUserMethodData(object[] data, bool hasOrganization)
: base(data)
{
HasOrganization = hasOrganization;
}
}

public class TheAreOrganizationsSupportedForUserMethod : WhitelistBaseMethod
{
protected override User GetUser(WhitelistMethodData data)
{
var user = base.GetUser(data);
if ((data as TheAreOrganizationsSupportedForUserMethodData).HasOrganization)
{
user.Organizations = new[] { new Membership() };
}

return user;
}

public static IEnumerable<object[]> ReturnsAsExpectedWhenNonNull_Data =>
PossibleListStates.SelectMany(data =>
new[] { false, true }
.Select(hasOrganization =>
MemberDataHelper.AsData(
new TheAreOrganizationsSupportedForUserMethodData(data, hasOrganization))));

public override bool GetExpectedValueForNonNull(WhitelistMethodData data)
{
return data.OrganizationsEnabledForAll ||
(data as TheAreOrganizationsSupportedForUserMethodData).HasOrganization ||
new TheIsUserOnWhitelistMethod().GetExpectedValueForNonNull(data);
}

public static IEnumerable<object[]> ReturnsFalseWhenNull_Data => WhitelistBaseMethodReturnsExpected_Data;

public override bool GetExpectedValueForNull(WhitelistMethodData data)
{
return data.OrganizationsEnabledForAll;
}

protected override bool GetWhitelistValue(ILoginDiscontinuationConfiguration config, User user)
{
return config.AreOrganizationsSupportedForUser(user);
}
}
}
}
Loading

0 comments on commit 2c222f7

Please sign in to comment.