Skip to content

Commit

Permalink
merge with 177
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabruno91 committed Feb 13, 2024
2 parents f37c803 + 42fbe83 commit ea3a53c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@

namespace Ermes.Web.Controllers.Dto
{
public class CreateOrUpdateReportForExternalsInput : ICustomValidate
public class CreateOrUpdateReportForExternalsInput : ExternalBase
{
[Required]
public ReportDto Report { get; set; }
public IFormFileCollection Files { get; set; }
public int VolterId { get; set; }

public void AddValidationErrors(CustomValidationContext context)
{
if(VolterId == 0) {
context.Results.Add(new ValidationResult("Invalid VolterId"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

namespace Ermes.Web.Controllers.Dto
{
public class CreatePersonActionForExternalsInput : ICustomValidate
public class CreatePersonActionForExternalsInput : ExternalBase
{
[Required]
public PersonActionDto PersonAction { get; set; }
public int VolterId { get; set; }

public void AddValidationErrors(CustomValidationContext context)
{
if (VolterId == 0)
{
context.Results.Add(new ValidationResult("Invalid VolterId"));
}
}
}
}
19 changes: 19 additions & 0 deletions src/Ermes.Web/Controllers/Dto/ExternalBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Abp.Runtime.Validation;
using System.ComponentModel.DataAnnotations;

namespace Ermes.Web.Controllers.Dto
{
public class ExternalBase: ICustomValidate
{
public int VolterId { get; set; }
public string CreatorFullName { get; set; }

public void AddValidationErrors(CustomValidationContext context)
{
if (VolterId == 0)
{
context.Results.Add(new ValidationResult("Invalid VolterId"));
}
}
}
}
6 changes: 3 additions & 3 deletions src/Ermes.Web/Controllers/ErmesControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected async Task<Person> CreateOrUpdatePersonInternalAsync(Person person, Us
await CurrentUnitOfWork.SaveChangesAsync();
return person;
}
protected async Task<User> CreateUserInternalAsync(int volterId, IOptions<FusionAuthSettings> _fusionAuthSettings, IOptions<ErmesSettings> _ermesSettings)
protected async Task<User> CreateUserInternalAsync(int volterId, string username, IOptions<FusionAuthSettings> _fusionAuthSettings, IOptions<ErmesSettings> _ermesSettings)
{
var client = FusionAuth.GetFusionAuthClient(_fusionAuthSettings.Value);
//Set the password based on current project
Expand All @@ -95,8 +95,8 @@ protected async Task<User> CreateUserInternalAsync(int volterId, IOptions<Fusion
var user = new User()
{
active = true,
email = string.Format("{0}@{1}.eu", volterId.ToString(), project.ToLower()),
username = volterId.ToString(),
email = string.Format("{0}@{1}.eu", username, project.ToLower()),
username = username,
password = string.Concat(project.ToLower(), ErmesConsts.DefaultYear),
preferredLanguages = new List<string> { "it" }
};
Expand Down
8 changes: 4 additions & 4 deletions src/Ermes.Web/Controllers/ExternalsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public virtual async Task<CreateOrUpdateReportForExternalsOutput> CreateOrUpdate
var media = request.Form.Files;

var res = new CreateOrUpdateReportForExternalsOutput();
var (creator, organizationId, roleList) = await GetExternalPersonAsync(input.VolterId);
var (creator, organizationId, roleList) = await GetExternalPersonAsync(input.VolterId, input.CreatorFullName);

if (input.Report.Id == 0)
{
Expand Down Expand Up @@ -202,7 +202,7 @@ public virtual async Task<CreatePersonActionOutput> CreatePersonAction([FromBody
{
var res = new CreatePersonActionOutput();

var (creator, organizationId, roleList) = await GetExternalPersonAsync(input.VolterId);
var (creator, organizationId, roleList) = await GetExternalPersonAsync(input.VolterId, input.CreatorFullName);

long personId = creator.Id;
var lastAction = await _personManager.GetLastPersonActionAsync(personId);
Expand Down Expand Up @@ -300,7 +300,7 @@ public virtual async Task<CreatePersonActionOutput> CreatePersonAction([FromBody
return res;
}

private async Task<Tuple<Person, int, List<string>>> GetExternalPersonAsync(int volterId)
private async Task<Tuple<Person, int, List<string>>> GetExternalPersonAsync(int volterId, string creatorFullName)
{
var roleList = new List<string>() { AppRoles.FIRST_RESPONDER };

Expand All @@ -311,7 +311,7 @@ private async Task<Tuple<Person, int, List<string>>> GetExternalPersonAsync(int
var creator = _personManager.GetPersonByLegacyId(volterId);
if (creator == null)
{
var currentUser = await CreateUserInternalAsync(volterId, _fusionAuthSettings, _ermesSettings);
var currentUser = await CreateUserInternalAsync(volterId, creatorFullName, _fusionAuthSettings, _ermesSettings);
var roles = await _personManager.GetRolesByName(roleList);
creator = await CreateOrUpdatePersonInternalAsync(creator, currentUser, externalOrg.Id, null, true, true, volterId, roles, _personManager);
}
Expand Down
1 change: 1 addition & 0 deletions src/Ermes.Web/Release-Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Ver.
--------------------------------
- Feature - Read property added to Report and ReportDto class (migration added)(#175)
- Feature - new API for person action batch insert added (#176)
- Feature - CreatorFullName property added in APIs for externals (#177)

Ver. 4.18.1 - 2024-01-22
--------------------------------
Expand Down

0 comments on commit ea3a53c

Please sign in to comment.