Skip to content

Commit

Permalink
Merge pull request #586 from SavageLearning/feature/more-timezone-fixes
Browse files Browse the repository at this point in the history
Resolves:
#583 Validate new user email
#577 Fixes Print view TZ
#586 adds unique email validation for create/edit user contain spaces, but the user is not informed

Mitigates:
#581 by providing an activities report (requires DB script) fix here
#580 by Adding feedback on validation fail - first or last have space

I created the new activities report before I noticed the fix, but the new V2 report can't hurt.
  • Loading branch information
esteban-gs authored Feb 19, 2020
2 parents 3d90152 + 8ec8fa3 commit 25478bb
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
21 changes: 21 additions & 0 deletions Machete.Data/Initialize/MacheteReportDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,27 @@ join lookups l on (ev.eventType = l.id)
WHERE (w.dwccardnum = @dwccardnum)",
inputsJson = "{\"beginDate\":false,\"endDate\":false,\"memberNumber\":true}"
},
// Worker Details -- activities
new ReportDefinition
{
name = "WorkerDetailsActivities",
commonName = "Worker Details, Activities attended",
description =
" A list of activities that a given worker attended",
category = "WorkerDetail",
sqlquery =
@"SELECT
a.nameEN as [Activity Name],
a.typeEN as [Activity Type],
a.teacher as [Teacher],
CONVERT(varchar, a.dateStart, 22) as [Start Time]
FROM ActivitySignins asi
JOIN Activities a
on asi.ActivityID = a.ID
WHERE asi.dwccardnum = @dwccardnum
",
inputsJson = "{\"beginDate\":false,\"endDate\":false,\"memberNumber\":true}"
},
// Worker details -- jobs summary
new ReportDefinition
{
Expand Down
9 changes: 6 additions & 3 deletions Machete.Data/Repositories/AllRepositories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface IEmailRepository : IRepository<Email>

public interface IWorkOrderRepository : IRepository<WorkOrder>
{
IEnumerable<WorkOrder> GetActiveOrders(DateTime date);
IEnumerable<WorkOrder> GetActiveOrders(DateTime date, TimeZoneInfo clientTimeZoneInfo);
}
public interface IWorkerRequestRepository : IRepository<WorkerRequest> {
WorkerRequest GetByID(int woid, int workerID);
Expand Down Expand Up @@ -163,10 +163,13 @@ public class WorkOrderRepository : RepositoryBase<WorkOrder>, IWorkOrderReposito
{
public WorkOrderRepository(IDatabaseFactory databaseFactory) : base(databaseFactory) { }

public IEnumerable<WorkOrder> GetActiveOrders(DateTime date)
public IEnumerable<WorkOrder> GetActiveOrders(DateTime date, TimeZoneInfo clientTimeZoneInfo)
{
// date parameter comes in as Utc datetime, so convert before comparing
DateTime clientDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(date, DateTimeKind.Unspecified), clientTimeZoneInfo);

return dbset.Where(wo => wo.statusID == WorkOrder.iActive
&& wo.dateTimeofWork.Date == date.Date)
&& TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(wo.dateTimeofWork, DateTimeKind.Unspecified), clientTimeZoneInfo).Date == clientDate.Date)
.Include(a => a.Employer)
.Include(a => a.workerRequestsDDD)
.ThenInclude(a => a.workerRequested)
Expand Down
2 changes: 1 addition & 1 deletion Machete.Service/WorkOrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ITenantService tenantService
/// <returns>WorkOrders associated with a given date that are active</returns>
public IEnumerable<WorkOrder> GetActiveOrders(DateTime date, bool assignedOnly)
{
var matching = repo.GetActiveOrders(date);
var matching = repo.GetActiveOrders(date, _clientTimeZoneInfo);
// .Where(wo => wo.statusID == WorkOrder.iActive
// && wo.dateTimeofWork.Date == date.Date).ToList();

Expand Down
16 changes: 15 additions & 1 deletion Machete.Web/Controllers/Legacy/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ public async Task<ActionResult> Register(RegisterViewModel model)
{
if (!ModelState.IsValid) return View(model);
var newUserName = model.FirstName.Trim() + "." + model.LastName.Trim();
var dupeUser = await _userManager.FindByEmailAsync(model.Email);
if (dupeUser != null && dupeUser.Email == model.Email)
{
ModelState.AddModelError("", ValidationStrings.dupeEmail);
return View(model);
}
var user = new MacheteUser { UserName = newUserName, LoweredUserName = newUserName.ToLower(), ApplicationId = GetApplicationId(), Email = model.Email.Trim(), LoweredEmail = model.Email.Trim() };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
Expand All @@ -224,7 +230,9 @@ public async Task<ActionResult> Register(RegisterViewModel model)

foreach (var error in result.Errors)
{
ModelState.AddModelError(error.Code, error.Description);
ModelState.AddModelError("", error.Description);
if (error.Description.Contains("is invalid, can only contain letters or digits") && newUserName.Contains(" "))
ModelState.AddModelError("", ValidationStrings.NameHasSpace);
}

// If we got this far, something failed, redisplay form
Expand Down Expand Up @@ -354,8 +362,14 @@ public async Task<ActionResult> Edit([Bind]EditUserViewModel model)
{
var user = _context.Users.First(u => u.Id == model.Id);
var macheteUserName = model.FirstName.Trim() + "." + model.LastName.Trim();
var dupeUser = await _userManager.FindByEmailAsync(model.Email);
user.UserName = macheteUserName;
user.LoweredUserName = macheteUserName.ToLower();
if (dupeUser != null && dupeUser.Email == model.Email)
{
ModelState.AddModelError("ErrorMessage", ValidationStrings.dupeEmail);
return View(model);
}
user.Email = model.Email.Trim();
user.LoweredEmail = model.Email.Trim().ToLower();
user.IsApproved = model.IsApproved;
Expand Down
18 changes: 18 additions & 0 deletions Machete.Web/Resources/ValidationStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Machete.Web/Resources/ValidationStrings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<data name="PasswordNew" xml:space="preserve">
<value>Contraseña nueva</value>
</data>
<data name="NameHasSpace" xml:space="preserve">
<value>Nombre y apellido no pueden contener espacios. Por favor, usar un guión "-" para unir dos palabras</value>
</data>
<data name="Register" xml:space="preserve">
<value>Crear una cuenta</value>
</data>
Expand Down Expand Up @@ -219,6 +222,9 @@
<data name="emailValidation" xml:space="preserve">
<value>The email format is invalid</value>
</data>
<data name="dupeEmail" xml:space="preserve">
<value>Intente denuevo con otro email</value>
</data>
<data name="invalidLogin" xml:space="preserve">
<value>Invalid username or password.</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions Machete.Web/Resources/ValidationStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
<data name="PasswordNew" xml:space="preserve">
<value>New Password</value>
</data>
<data name="NameHasSpace" xml:space="preserve">
<value>Last name and first name must not contain spaces. To enter a name with multiple words, use hyphens "-"</value>
</data>
<data name="Register" xml:space="preserve">
<value>Register</value>
</data>
Expand Down Expand Up @@ -231,6 +234,9 @@
<data name="emailValidation" xml:space="preserve">
<value>The email format is invalid</value>
</data>
<data name="dupeEmail" xml:space="preserve">
<value>Please try a different email</value>
</data>
<data name="invalidLogin" xml:space="preserve">
<value>Invalid username or password.</value>
</data>
Expand Down

0 comments on commit 25478bb

Please sign in to comment.