-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psp-9256 allow users added to a project to view an acquisition file. (#…
…4555) * psp-9256 allow users added to a project to view an acquisition file. * test corrections. Signed-off-by: devinleighsmith <[email protected]> * snapshot updates. * final snapshot * add the list of project team members to acquisition files. * Remove unecessary mapping for person entity. --------- Signed-off-by: devinleighsmith <[email protected]>
- Loading branch information
1 parent
11bb53f
commit c3a630e
Showing
31 changed files
with
427 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,29 +11,41 @@ namespace Pims.Api.Helpers.Extensions | |
{ | ||
public static class AcquisitionFileExtensions | ||
{ | ||
public static void ThrowMissingContractorInTeam(this PimsAcquisitionFile acquisitionFile, ClaimsPrincipal principal, IUserRepository userRepository) | ||
public static void ThrowMissingContractorInTeam(this PimsAcquisitionFile acquisitionFile, ClaimsPrincipal principal, IUserRepository userRepository, IProjectRepository projectRepository) | ||
{ | ||
ArgumentNullException.ThrowIfNull(acquisitionFile); | ||
|
||
ArgumentNullException.ThrowIfNull(principal); | ||
|
||
var pimsUser = userRepository.GetUserInfoByKeycloakUserId(principal.GetUserKey()); | ||
|
||
if (pimsUser?.IsContractor == true && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.PersonId == pimsUser.PersonId)) | ||
PimsProject project = null; | ||
if (acquisitionFile.ProjectId.HasValue) | ||
{ | ||
project = projectRepository.TryGet(acquisitionFile.ProjectId.Value); | ||
} | ||
|
||
if (pimsUser?.IsContractor == true && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.PersonId == pimsUser.PersonId) && (project == null || !project.PimsProjectPeople.Any(x => x.PersonId == pimsUser.PersonId))) | ||
{ | ||
throw new ContractorNotInTeamException("As a Contractor your user contact information should be assigned to the Acquisition File's team"); | ||
} | ||
} | ||
|
||
public static void ThrowContractorRemovedFromTeam(this PimsAcquisitionFile acquisitionFile, ClaimsPrincipal principal, IUserRepository userRepository) | ||
public static void ThrowContractorRemovedFromTeam(this PimsAcquisitionFile acquisitionFile, ClaimsPrincipal principal, IUserRepository userRepository, IProjectRepository projectRepository) | ||
{ | ||
ArgumentNullException.ThrowIfNull(acquisitionFile); | ||
|
||
ArgumentNullException.ThrowIfNull(principal); | ||
|
||
var pimsUser = userRepository.GetUserInfoByKeycloakUserId(principal.GetUserKey()); | ||
|
||
if (pimsUser?.IsContractor == true && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.PersonId == pimsUser.PersonId)) | ||
PimsProject project = null; | ||
if (acquisitionFile.ProjectId.HasValue) | ||
{ | ||
project = projectRepository.TryGet(acquisitionFile.ProjectId.Value); | ||
} | ||
|
||
if (pimsUser?.IsContractor == true && !acquisitionFile.PimsAcquisitionFileTeams.Any(x => x.PersonId == pimsUser.PersonId) && (project == null || !project.PimsProjectPeople.Any(x => x.PersonId == pimsUser.PersonId))) | ||
{ | ||
throw new UserOverrideException(UserOverrideCode.ContractorSelfRemoved, "Contractors cannot remove themselves from a file. Please contact the admin at [email protected]"); | ||
} | ||
|
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
26 changes: 26 additions & 0 deletions
26
source/backend/apimodels/Models/Concepts/Project/ProjectPersonMap.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,26 @@ | ||
using Mapster; | ||
using Pims.Api.Models.Base; | ||
using Entity = Pims.Dal.Entities; | ||
|
||
namespace Pims.Api.Models.Concepts.Project | ||
{ | ||
public class ProjectPersonMap : IRegister | ||
{ | ||
public void Register(TypeAdapterConfig config) | ||
{ | ||
config.NewConfig<Entity.PimsProjectPerson, ProjectPersonModel>() | ||
.Map(dest => dest.Id, src => src.ProjectPersonId) | ||
.Map(dest => dest.ProjectId, src => src.ProjectId) | ||
.Map(dest => dest.Person, src => src.Person) | ||
.Map(dest => dest.PersonId, src => src.PersonId) | ||
.Map(dest => dest.Project, src => src.Project) | ||
.Inherits<Entity.IBaseEntity, BaseConcurrentModel>(); | ||
|
||
config.NewConfig<ProjectPersonModel, Entity.PimsProjectPerson>() | ||
.Map(dest => dest.ProjectPersonId, src => src.Id) | ||
.Map(dest => dest.ProjectId, src => src.ProjectId) | ||
.Map(dest => dest.PersonId, src => src.PersonId) | ||
.Inherits<BaseConcurrentModel, Entity.IBaseEntity>(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
source/backend/apimodels/Models/Concepts/Project/ProjectPersonModel.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,22 @@ | ||
using Pims.Api.Models.Base; | ||
using Pims.Api.Models.Concepts.Person; | ||
|
||
namespace Pims.Api.Models.Concepts.Project | ||
{ | ||
public class ProjectPersonModel : BaseAuditModel | ||
{ | ||
#region Properties | ||
|
||
public long? Id { get; set; } | ||
|
||
public long? ProjectId { get; set; } | ||
|
||
public ProjectModel Project { get; set; } | ||
|
||
public long PersonId { get; set; } | ||
|
||
public PersonModel Person { get; set; } | ||
|
||
#endregion | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Pims.Dal.Entities | ||
{ | ||
/// <summary> | ||
/// PimsProjectPerson class, provides an entity for the datamodel to manage project persons. | ||
/// </summary> | ||
public partial class PimsProjectPerson : StandardIdentityBaseAppEntity<long>, IBaseAppEntity | ||
{ | ||
[NotMapped] | ||
public override long Internal_Id { get => this.ProjectPersonId; set => this.ProjectPersonId = value; } | ||
} | ||
} |
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
Oops, something went wrong.