Skip to content

Commit

Permalink
Merge pull request #406 from DigitalExcellence/develop
Browse files Browse the repository at this point in the history
Release v.1.1.0-beta - 18-03-2021
  • Loading branch information
niraymak authored Mar 19, 2021
2 parents 802189d + 4acd460 commit 8e1191d
Show file tree
Hide file tree
Showing 321 changed files with 31,744 additions and 10,755 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
cd ~/docker_compose
docker-compose down
docker-compose pull
sleep 10s
sleep 20s
docker-compose up -d
2 changes: 1 addition & 1 deletion .github/workflows/staging-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
cd ~/docker_compose
docker-compose down
docker-compose pull
sleep 10s
sleep 20s
docker-compose up -d
60 changes: 60 additions & 0 deletions API/01_API.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>API</RootNamespace>
<DocumentationFile>.\API.xml</DocumentationFile>
<Company>Digital Excellence Fontys</Company>
<LangVersion>8</LangVersion>
<Version>1.1.0-beta</Version>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Resources\Project\**" />
<Content Remove="Resources\Project\**" />
<EmbeddedResource Remove="Resources\Project\**" />
<None Remove="Resources\Project\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Uploads\Images\.gitkeep" />
</ItemGroup>

<ItemGroup>
<Content Include="Uploads\Images\.gitkeep" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.6.2" />
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="5.0.0" />
<PackageReference Include="IdentityModel.AspNetCore" Version="3.0.0" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0-preview1.19506.1" />
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="NetEscapades.Configuration.Validation" Version="2.0.0" />
<PackageReference Include="RestSharp" Version="106.11.2" />
<PackageReference Include="Sentry.AspNetCore" Version="2.1.1" />
<PackageReference Include="Sentry.Serilog" Version="2.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Data\06_Data.csproj" />
<ProjectReference Include="..\MessageBrokerPublisher\09_MessageBrokerPublisher.csproj" />
<ProjectReference Include="..\Models\07_Models.csproj" />
<ProjectReference Include="..\NotificationSystem\11_NotificationSystem.csproj" />
<ProjectReference Include="..\Services\02_Services.csproj" />
</ItemGroup>


</Project>
58 changes: 0 additions & 58 deletions API/1_API.csproj

This file was deleted.

98 changes: 80 additions & 18 deletions API/Common/AuthorizationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,65 @@

namespace API.Common
{

/// <summary>
/// The interface for the authorization helper
/// </summary>
public interface IAuthorizationHelper
{

/// <summary>
/// This method checks if a user has the correct scope to use the endpoint.
/// This method checks for a normal scope and the data officer scope within the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="scope">The required scope for accessing this endpoint.</param>
/// <param name="dataOfficerScope">
/// The required scope for accessing this
/// endpoint for data officers within the same institution.
/// </param>
/// <param name="propertyOfUserId">
/// The id of the user owner of the property
/// which the logged in user wants to access.
/// </param>
/// <returns>bool: true if the user is allowed, false if the user is not allowed.</returns>
public Task<bool> UserIsAllowed(User loggedInUser,
string scope,
string dataOfficerScope,
int propertyOfUserId);

/// <summary>
/// This method checks if a user has the same institution, and both should not have null. It
/// also checks if the user has the correct institution scope that allows changes in the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="institutionScope">
/// The required scope for accessing this
/// endpoint for data officers within the same institution.
/// </param>
/// <param name="propertyOfUserId">
/// The id of the user owner of the property
/// which the logged in user wants to access.
/// </param>
/// <returns>Bool: true if the user is allowed, false if the user is not allowed.</returns>
Task<bool> SameInstitutionAndInstitutionScope(User loggedInUser,
string institutionScope,
int propertyOfUserId);

}

/// <summary>
/// The implementation for the authorization helper.
/// The implementation for the authorization helper.
/// </summary>
public class AuthorizationHelper : IAuthorizationHelper
{

private readonly IUserService userService;

/// <summary>
/// Initializes a new instance of the <see cref="AuthorizationHelper"/> class.
/// Initializes a new instance of the <see cref="AuthorizationHelper" /> class.
/// </summary>
/// <param name="userService">The user service for communicating with the logic layer.</param>
public AuthorizationHelper(IUserService userService)
Expand All @@ -39,18 +88,25 @@ public AuthorizationHelper(IUserService userService)
}

/// <summary>
/// This method checks if a user has the correct scope to use the endpoint.
/// This method checks for a normal scope and the data officer scope within the
/// same institution.
/// This method checks if a user has the correct scope to use the endpoint.
/// This method checks for a normal scope and the data officer scope within the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="scope">The required scope for accessing this endpoint.</param>
/// <param name="dataOfficerScope">The required scope for accessing this
/// endpoint for data officers within the same institution.</param>
/// <param name="propertyOfUserId">The id of the user owner of the property
/// which the logged in user wants to access.</param>
/// <param name="dataOfficerScope">
/// The required scope for accessing this
/// endpoint for data officers within the same institution.
/// </param>
/// <param name="propertyOfUserId">
/// The id of the user owner of the property
/// which the logged in user wants to access.
/// </param>
/// <returns>bool: true if the user is allowed, false if the user is not allowed.</returns>
public async Task<bool> UserIsAllowed(User loggedInUser, string scope, string dataOfficerScope, int propertyOfUserId)
public async Task<bool> UserIsAllowed(User loggedInUser,
string scope,
string dataOfficerScope,
int propertyOfUserId)
{
bool hasUserWriteScope = userService.UserHasScope(loggedInUser.IdentityId, scope);
bool hasCorrectDataOfficerRights =
Expand All @@ -60,17 +116,23 @@ public async Task<bool> UserIsAllowed(User loggedInUser, string scope, string da
}

/// <summary>
/// This method checks if a user has the same institution, and both should not have null. It
/// also checks if the user has the correct institution scope that allows changes in the
/// same institution.
/// This method checks if a user has the same institution, and both should not have null. It
/// also checks if the user has the correct institution scope that allows changes in the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="institutionScope">The required scope for accessing this
/// endpoint for data officers within the same institution.</param>
/// <param name="propertyOfUserId">The id of the user owner of the property
/// which the logged in user wants to access.</param>
/// <param name="institutionScope">
/// The required scope for accessing this
/// endpoint for data officers within the same institution.
/// </param>
/// <param name="propertyOfUserId">
/// The id of the user owner of the property
/// which the logged in user wants to access.
/// </param>
/// <returns>Bool: true if the user is allowed, false if the user is not allowed.</returns>
public async Task<bool> SameInstitutionAndInstitutionScope(User loggedInUser, string institutionScope, int propertyOfUserId)
public async Task<bool> SameInstitutionAndInstitutionScope(User loggedInUser,
string institutionScope,
int propertyOfUserId)
{
return userService.UserHasScope(loggedInUser.IdentityId, institutionScope) &&
await userService.HasSameInstitution(loggedInUser.Id, propertyOfUserId);
Expand Down
62 changes: 0 additions & 62 deletions API/Common/IAuthorizationHelper.cs

This file was deleted.

Loading

0 comments on commit 8e1191d

Please sign in to comment.