Skip to content

Commit

Permalink
Changes around hard delete and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooja Adhikari committed Jan 9, 2019
1 parent cb50822 commit 860df62
Show file tree
Hide file tree
Showing 34 changed files with 362 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Microsoft.Health.Fhir.sln
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Global
{A906D1FB-9282-46A0-ADDC-46726B2C1378} = {8AD2A324-DAB5-4380-94A5-31F7D817C384}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E370FB31-CF95-47D1-B1E1-863A77973FF8}
RESX_SortFileContentOnSave = True
SolutionGuid = {E370FB31-CF95-47D1-B1E1-863A77973FF8}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.1.403"
"version": "2.1.500"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading;
using Microsoft.Health.ControlPlane.Core.Features.Persistence;
using Microsoft.Health.ControlPlane.Core.Features.Rbac;
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles;
using NSubstitute;
using Xunit;

Expand Down Expand Up @@ -67,14 +66,6 @@ public async void GivenAName_WhenUpsertingRoles_ThenDataStoreIsCalled()
Assert.Same(_role, role);
}

[Fact]
public async void GivenAName_WhenDeletingRoles_ThenDataStoreIsCalled()
{
var status = await _rbacService.DeleteRoleAsync(_role.Name, CancellationToken.None);

Assert.Equal("success", status.ToString());
}

[Fact]
public async void GivenAnIdentityProvider_WhenUpsertingIdentityProvider_ThenDataStoreIsCalled()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Diagnostics;
using EnsureThat;

namespace Microsoft.Health.ControlPlane.Core.Features.Exceptions
{
public class RoleNotFoundException : ControlPlaneException
{
public RoleNotFoundException(string name)
: base(string.Format(Resources.RoleNotFound, name))
: base(ValidateAndFormatMessage(name))
{
Debug.Assert(!string.IsNullOrEmpty(name), "Role identifier should not be empty");
}

private static string ValidateAndFormatMessage(string name)
{
EnsureArg.IsNotNullOrWhiteSpace(name, nameof(name));

return string.Format(Resources.RoleNotFound, name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Health.ControlPlane.Core.Features.Rbac;
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles;

namespace Microsoft.Health.ControlPlane.Core.Features.Persistence
{
Expand All @@ -24,5 +23,7 @@ public interface IControlPlaneDataStore
Task<IEnumerable<Role>> GetRoleAllAsync(CancellationToken cancellationToken);

Task<string> DeleteRoleAsync(string name, CancellationToken cancellationToken);

Task HardDeleteRoleAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles;

namespace Microsoft.Health.ControlPlane.Core.Features.Rbac
{
Expand All @@ -22,6 +21,6 @@ public interface IRbacService

Task<IEnumerable<Role>> GetRoleForAllAsync(CancellationToken cancellationToken);

Task<string> DeleteRoleAsync(string name, CancellationToken cancellationToken);
Task DeleteRoleAsync(string name, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading.Tasks;
using EnsureThat;
using Microsoft.Health.ControlPlane.Core.Features.Persistence;
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles;

namespace Microsoft.Health.ControlPlane.Core.Features.Rbac
{
Expand Down Expand Up @@ -50,10 +49,10 @@ public async Task<Role> UpsertRoleAsync(Role role, CancellationToken cancellatio
return await _controlPlaneDataStore.UpsertRoleAsync(role, cancellationToken);
}

public async Task<string> DeleteRoleAsync(string name, CancellationToken cancellationToken)
public async Task DeleteRoleAsync(string name, CancellationToken cancellationToken)
{
EnsureArg.IsNotNullOrWhiteSpace(name, nameof(name));
return await _controlPlaneDataStore.DeleteRoleAsync(name, cancellationToken);
await _controlPlaneDataStore.HardDeleteRoleAsync(name, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Microsoft.Health.Fhir.Core.Features.Security
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac
{
[JsonConverter(typeof(StringEnumConverter))]
public enum ResourceAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System.Collections.Generic;

namespace Microsoft.Health.Fhir.Core.Features.Security
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac
{
public class ResourcePermission
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json;

namespace Microsoft.Health.Fhir.Core.Features.Security
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac
{
public class Role : IValidatableObject
{
[JsonConstructor]
public Role()
{
}

public Role(string name, IList<ResourcePermission> resourcePermissions, string version)
{
Name = name;
ResourcePermissions = resourcePermissions;
Version = version;
}

public string Name { get; set; }

public virtual string Version { get; set; }

public IList<ResourcePermission> ResourcePermissions { get; internal set; } = new List<ResourcePermission>();
public IList<ResourcePermission> ResourcePermissions { get; set; } = new List<ResourcePermission>();

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
Expand Down

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions src/Microsoft.Health.ControlPlane.Core/Features/Rbac/Roles/Role.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Ensure.That" Version="8.1.0" />
<PackageReference Include="Hl7.Fhir.STU3" Version="0.96.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" />
Expand Down
38 changes: 33 additions & 5 deletions src/Microsoft.Health.ControlPlane.Core/Resources.Designer.cs

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

12 changes: 12 additions & 0 deletions src/Microsoft.Health.ControlPlane.Core/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@
<data name="IdentityProviderNotFound" xml:space="preserve">
<value>Identity provider '{0}' was not found.</value>
</data>
<data name="ResourcePermissionEmpty" xml:space="preserve">
<value>Resource Permissions cannot be empty</value>
</data>
<data name="RoleNameEmpty" xml:space="preserve">
<value>Role Name '{0}' cannot be empty</value>
</data>
<data name="RoleNotFound" xml:space="preserve">
<value>Role '{0}' was not found.</value>
</data>
<data name="RoleResourcePermissionWithNoAction" xml:space="preserve">
<value>Resource Permission must have at least one action</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ public ControlPlaneDataStoreTests()

var logger = NullLogger<ControlPlaneDataStore>.Instance;

var retryExceptionPolicyFactory = Substitute.For<RetryExceptionPolicyFactory>();

_controlPlaneDataStore = new ControlPlaneDataStore(
scopedIDocumentClient,
cosmosDataStoreConfiguration,
cosmosDocumentQueryFactory,
optionsMonitor,
retryExceptionPolicyFactory,
logger);
}

Expand Down
Loading

0 comments on commit 860df62

Please sign in to comment.