-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from Strongminds/release-2.8.1
Release 2.8.1
- Loading branch information
Showing
167 changed files
with
7,102 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Core.ApplicationServices/Extensions/IAuthorizationContextExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Core.ApplicationServices/Interface/ExhibitUsage/IInterfaceExhibitUsageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Core.ApplicationServices/Interface/ExhibitUsage/InterfaceExhibitUsageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
Core.ApplicationServices/Interface/Usage/IInterfaceUsageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
107
Core.ApplicationServices/Interface/Usage/InterfaceUsageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
Core.ApplicationServices/Model/System/UsingOrganization.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.