Skip to content

Commit

Permalink
Merge pull request #383 from Strongminds/release-2.8.1
Browse files Browse the repository at this point in the history
Release 2.8.1
  • Loading branch information
mrjsawdk authored Sep 19, 2019
2 parents 058f792 + 608ed52 commit 040f88f
Show file tree
Hide file tree
Showing 167 changed files with 7,102 additions and 546 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Presentation.Web/Scripts/*.min.js
Presentation.Web/Content/css/fonts/*.svg
Presentation.Web/Content/fonts/*.svg
Presentation.Web/Content/css/app.min.css
Presentation.Web/Content/css/maps/*.map

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/
Expand Down
2 changes: 1 addition & 1 deletion Core.ApplicationServices/AdviceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Collections.Generic;

namespace Core.ApplicationServices
{
using DomainModel.ItSystemUsage;
using Ninject.Extensions.Logging;
using System.Collections.Generic;

public class AdviceService: IAdviceService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ public interface IAuthorizationContext
/// <param name="entity"></param>
/// <returns></returns>
bool AllowEntityVisibilityControl(IEntity entity);
/// <summary>
/// Determines if the current context allows system migration
/// </summary>
/// <returns></returns>
bool AllowSystemUsageMigration();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public bool AllowEntityVisibilityControl(IEntity entity)
return AllowModify(entity) && _activeUserContext.CanChangeVisibilityOf(entity);
}

public bool AllowSystemUsageMigration()
{
return IsGlobalAdmin() && IsReadOnly() == false;
}

private bool AllowWritesToEntity(IEntity entity)
{
var result = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ public bool IsActiveInSameOrganizationAs(IEntity entity)
{
switch (entity)
{
case IContextAware contextAware:
return contextAware.IsInContext(ActiveOrganizationId);
//Prefer match on hasOrganization first since it has static knowledge of organization relationship
case IHasOrganization hasOrg:
return IsActiveInOrganization(hasOrg.OrganizationId);
case IContextAware contextAware:
return contextAware.IsInContext(ActiveOrganizationId);
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public bool AllowEntityVisibilityControl(IEntity entity)
{
return false;
}

public bool AllowSystemUsageMigration()
{
return false;
}
}
}
17 changes: 16 additions & 1 deletion Core.ApplicationServices/Core.ApplicationServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,22 @@
<Compile Include="Authorization\UnauthenticatedAuthorizationContext.cs" />
<Compile Include="Authorization\UnauthenticatedUserContext.cs" />
<Compile Include="Authorization\UserContextFactory.cs" />
<Compile Include="Extensions\IAuthorizationContextExtensions.cs" />
<Compile Include="FeatureChecker.cs" />
<Compile Include="IAdviceService.cs" />
<Compile Include="IFeatureChecker.cs" />
<Compile Include="Interface\ExhibitUsage\IInterfaceExhibitUsageService.cs" />
<Compile Include="Interface\ExhibitUsage\InterfaceExhibitUsageService.cs" />
<Compile Include="Interface\Usage\IInterfaceUsageService.cs" />
<Compile Include="Interface\Usage\InterfaceUsageService.cs" />
<Compile Include="Model\Shared\NamedEntity.cs" />
<Compile Include="Model\System\UsingOrganization.cs" />
<Compile Include="SystemUsage\Migration\IItSystemUsageMigrationService.cs" />
<Compile Include="SystemUsage\Migration\ItSystemUsageMigrationService.cs" />
<Compile Include="Model\SystemUsage\Migration\ItSystemUsageMigration.cs" />
<Compile Include="Model\SystemUsage\Migration\ItContractMigration.cs" />
<Compile Include="Model\Result\OperationResult.cs" />
<Compile Include="Model\Result\Result.cs" />
<Compile Include="OrganizationRoleService.cs" />
<Compile Include="AuthenticationService.cs" />
<Compile Include="IAuthenticationService.cs" />
Expand All @@ -108,7 +121,8 @@
<Compile Include="ItContractService.cs" />
<Compile Include="ItProjectService.cs" />
<Compile Include="ItInterfaceService.cs" />
<Compile Include="ItSystemService.cs" />
<Compile Include="System\IItSystemService.cs" />
<Compile Include="System\ItSystemService.cs" />
<Compile Include="ItSystemUsageService.cs" />
<Compile Include="LinqTreeExtensions.cs" />
<Compile Include="ExcelImportError.cs" />
Expand Down Expand Up @@ -138,6 +152,7 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Core.ApplicationServices.Authorization;
using Core.DomainServices.Authorization;

namespace Core.ApplicationServices.Extensions
{
public static class AuthorizationContextExtensions
{
public static DataAccessLevel GetDataAccessLevel(this IAuthorizationContext context, int organizationId)
{
return new DataAccessLevel(context.GetCrossOrganizationReadAccess(), context.GetOrganizationReadAccessLevel(organizationId));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Core.ApplicationServices.Model.Result;

namespace Core.ApplicationServices.Interface.ExhibitUsage
{
public interface IInterfaceExhibitUsageService
{
OperationResult Delete(int systemUsageId, int interfaceExhibitId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Core.ApplicationServices.Authorization;
using Core.ApplicationServices.Model.Result;
using Core.DomainModel.ItSystemUsage;
using Core.DomainServices;
using Serilog;

namespace Core.ApplicationServices.Interface.ExhibitUsage
{
public class InterfaceExhibitUsageService : IInterfaceExhibitUsageService
{
private readonly IGenericRepository<ItInterfaceExhibitUsage> _itInterfaceExhibitUsageRepository;
private readonly ILogger _logger;
private readonly IAuthorizationContext _authorizationContext;

public InterfaceExhibitUsageService(
IGenericRepository<ItInterfaceExhibitUsage> itInterfaceExhibitUsageRepository,
ILogger logger,
IAuthorizationContext authorizationContext)
{
_itInterfaceExhibitUsageRepository = itInterfaceExhibitUsageRepository;
_logger = logger;
_authorizationContext = authorizationContext;
}

public OperationResult Delete(int systemUsageId, int interfaceExhibitId)
{
var key = ItInterfaceExhibitUsage.GetKey(systemUsageId, interfaceExhibitId);
var interfaceExhibitUsageToBeDeleted = _itInterfaceExhibitUsageRepository.GetByKey(key);
if (interfaceExhibitUsageToBeDeleted == null)
{
_logger.Error($"Could not find interface exhibit usage with key {key}");
return OperationResult.NotFound;
}

if (!AllowDelete(interfaceExhibitUsageToBeDeleted))
{
return OperationResult.Forbidden;
}

_itInterfaceExhibitUsageRepository.Delete(interfaceExhibitUsageToBeDeleted);
_itInterfaceExhibitUsageRepository.Save();
return OperationResult.Ok;
}

private bool AllowDelete(ItInterfaceExhibitUsage interfaceExhibitUsageToBeDeleted)
{
//ExhibitUsage belongs to a contract, hence a deletion is a modification of the contract
return interfaceExhibitUsageToBeDeleted.ItContract == null ||
_authorizationContext.AllowModify(interfaceExhibitUsageToBeDeleted.ItContract);
}
}
}
18 changes: 18 additions & 0 deletions Core.ApplicationServices/Interface/Usage/IInterfaceUsageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Core.ApplicationServices.Model.Result;
using Core.DomainModel.ItSystemUsage;

namespace Core.ApplicationServices.Interface.Usage
{
public interface IInterfaceUsageService
{
Result<OperationResult, ItInterfaceUsage> Create(
int systemUsageId,
int systemId,
int interfaceId,
bool isWishedFor,
int contractId,
int? infrastructureId = null);

OperationResult Delete(int systemUsageId, int systemId, int interfaceId);
}
}
107 changes: 107 additions & 0 deletions Core.ApplicationServices/Interface/Usage/InterfaceUsageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Core.ApplicationServices.Authorization;
using Core.ApplicationServices.Model.Result;
using Core.DomainModel.ItContract;
using Core.DomainModel.ItSystemUsage;
using Core.DomainServices;
using Core.DomainServices.Repositories.Contract;
using Serilog;

namespace Core.ApplicationServices.Interface.Usage
{
public class InterfaceUsageService : IInterfaceUsageService
{
private readonly IGenericRepository<ItInterfaceUsage> _interfaceUsageRepository;
private readonly ILogger _logger;
private readonly IAuthorizationContext _authorizationContext;
private readonly IItContractRepository _contractRepository;

public InterfaceUsageService(
IGenericRepository<ItInterfaceUsage> interfaceUsageRepository,
ILogger logger,
IAuthorizationContext authorizationContext,
IItContractRepository contractRepository)
{
_interfaceUsageRepository = interfaceUsageRepository;
_logger = logger;
_authorizationContext = authorizationContext;
_contractRepository = contractRepository;
}
public Result<OperationResult, ItInterfaceUsage> Create(
int systemUsageId,
int systemId,
int interfaceId,
bool isWishedFor,
int contractId,
int? infrastructureId = null
)
{
var key = ItInterfaceUsage.GetKey(systemUsageId, systemId, interfaceId);

if (_interfaceUsageRepository.GetByKey(key) != null)
{
_logger.Error($"InterfaceUsage with key {{ " +
$"ItSystemUsageId: {systemUsageId}, " +
$"ItSystemId: {systemId}," +
$"ItInterfaceId: {interfaceId} }} already exists");
return Result<OperationResult, ItInterfaceUsage>.Fail(OperationResult.Conflict);
}

var contract = _contractRepository.GetById(contractId);
if (contract == null)
{
_logger.Error("Contract with id: {id} not found. Cannot create interface usage", contractId);
return Result<OperationResult, ItInterfaceUsage>.Fail(OperationResult.BadInput);
}

if (!AllowCreateInterfaceUsageIn(contract))
{
return Result<OperationResult, ItInterfaceUsage>.Fail(OperationResult.Forbidden);
}

var newInterfaceUsage = _interfaceUsageRepository.Create();
newInterfaceUsage.ItSystemUsageId = systemUsageId;
newInterfaceUsage.ItSystemId = systemId;
newInterfaceUsage.ItInterfaceId = interfaceId;
newInterfaceUsage.ItContractId = contractId;
newInterfaceUsage.InfrastructureId = infrastructureId;
newInterfaceUsage.IsWishedFor = isWishedFor;
_interfaceUsageRepository.Insert(newInterfaceUsage);
_interfaceUsageRepository.Save();

return Result<OperationResult, ItInterfaceUsage>.Ok(newInterfaceUsage);
}

private bool AllowCreateInterfaceUsageIn(ItContract contract)
{
// interface usages belong to contracts so authorize modification access to that
return _authorizationContext.AllowModify(contract);
}

public OperationResult Delete(int systemUsageId, int systemId, int interfaceId)
{
var key = ItInterfaceUsage.GetKey(systemUsageId, systemId, interfaceId);
var interfaceUsageToBeDeleted = _interfaceUsageRepository.GetByKey(key);
if (interfaceUsageToBeDeleted == null)
{
_logger.Error($"Could not find interface usage with key {key}");
return OperationResult.NotFound;
}

if (!AllowDelete(interfaceUsageToBeDeleted))
{
return OperationResult.Forbidden;
}

_interfaceUsageRepository.Delete(interfaceUsageToBeDeleted);
_interfaceUsageRepository.Save();
return OperationResult.Ok;
}

private bool AllowDelete(ItInterfaceUsage interfaceExhibitUsageToBeDeleted)
{
//InterfaceUsage belongs to a contract, hence a deletion is a modification of the contract
return interfaceExhibitUsageToBeDeleted.ItContract == null ||
_authorizationContext.AllowModify(interfaceExhibitUsageToBeDeleted.ItContract);
}
}
}
12 changes: 12 additions & 0 deletions Core.ApplicationServices/Model/Result/OperationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Core.ApplicationServices.Model.Result
{
public enum OperationResult
{
Ok,
BadInput,
NotFound,
Forbidden,
Conflict,
UnknownError
}
}
31 changes: 31 additions & 0 deletions Core.ApplicationServices/Model/Result/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace Core.ApplicationServices.Model.Result
{
public class Result<TStatus, TResult>
{
public TStatus Status { get; }
public TResult Value { get; }

private Result(TStatus status, TResult result)
{
Status = status;
Value = result;
}

public static Result<OperationResult, TResult> Ok(TResult value)
{
return new Result<OperationResult, TResult>(OperationResult.Ok, value);
}

public static Result<OperationResult, TResult> Fail(OperationResult code)
{
if (code == OperationResult.Ok)
{
throw new ArgumentException($"{nameof(code)} cannot be {code:G}");
}
return new Result<OperationResult, TResult>(code, default(TResult));
}
}

}
16 changes: 16 additions & 0 deletions Core.ApplicationServices/Model/Shared/NamedEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Core.DomainModel;

namespace Core.ApplicationServices.Model.Shared
{
public class NamedEntity
{
public int Id { get; }
public string Name { get; }

public NamedEntity(int id, string name)
{
Id = id;
Name = name;
}
}
}
16 changes: 16 additions & 0 deletions Core.ApplicationServices/Model/System/UsingOrganization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Core.ApplicationServices.Model.Shared;

namespace Core.ApplicationServices.Model.System
{
public class UsingOrganization
{
public int ItSystemUsageId { get; }
public NamedEntity Organization { get; }

public UsingOrganization(int usageId, NamedEntity organization)
{
ItSystemUsageId = usageId;
Organization = organization;
}
}
}
Loading

0 comments on commit 040f88f

Please sign in to comment.