Skip to content

Commit

Permalink
Merge pull request #47 from galliumplus/fix/hotfix-2
Browse files Browse the repository at this point in the history
halloween midnight merge 🎃
  • Loading branch information
louisdevie authored Oct 31, 2023
2 parents fbcfbdd + d17a2dd commit ce9ef47
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

if __name__ == "__main__":
decimal.DefaultContext.prec = 2
Launcher.launch("0.6.0")
Launcher.launch("0.8.2")
12 changes: 11 additions & 1 deletion .tests/tests/user_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,17 @@ def test_user_delete(self):
response = self.get("users/ar113926")
self.expect(response.status_code).to.be.equal_to(200)

# On le supprime
# On ne peut pas le supprimer : il a un acompte non vide

response = self.delete("users/ar113926")
self.expect(response.status_code).to.be.equal_to(403)

# On retire l'argent de son acompte

user["deposit"] = 0
self.put("users/ar113926", user)

# Cette fois-ci, on peut bien le supprimer

response = self.delete("users/ar113926")
self.expect(response.status_code).to.be.equal_to(200)
Expand Down
4 changes: 4 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<PackageReference Include="Stubble.Core" Version="1.10.8" />
</ItemGroup>

<ItemGroup>
<Folder Include="Data\HistorySearch\" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion CoreTest/CoreTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\FakeDatabase\FakeDatabase.csproj" />
<ProjectReference Include="..\FakeServices\FakeServices.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions CoreTest/Orders/OrderTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GalliumPlus.WebApi.Core.Exceptions;
using System.Reflection;

namespace CoreTest.Orders
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ override public User Update(string key, User item)
{
try
{
User old = this.Items[key];
item.Password = old.Password;
if (GetKey(item) == key)
{
if (!this.Items.ContainsKey(key)) throw new ItemNotFoundException();
Expand Down Expand Up @@ -95,7 +97,7 @@ protected override void SetKey(ref User item, string key)

protected override bool CheckConstraints(User item)
{
return item.Deposit > 0;
return item.Deposit == null || item.Deposit >= 0;
}

public void ChangePassword(string id, PasswordInformation newPassword)
Expand Down
36 changes: 36 additions & 0 deletions FakeServices/Email/FakeEmailService/FakeEmailSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using GalliumPlus.WebApi.Core.Email;
using System.Text;

namespace GalliumPlus.WebApi.Email.FakeEmailService
{
public class FakeEmailSender : IEmailSender
{
private static string Repeat(string text, int times)
{
StringBuilder sb = new();
for (int i = 0; i < times; i++) sb.Append(text);
return sb.ToString();
}

public void Send(string recipient, string subject, string content)
{
int width = Console.WindowWidth;

Console.WriteLine("== Envoi de mail ==" + Repeat("=", width - 19));
Console.WriteLine();
Console.WriteLine(" De : Gallium+ <no-reply@etiq-dijon.fr>");
Console.WriteLine(" À : {0}", recipient);
Console.WriteLine(" Sujet : {0}", subject);
Console.WriteLine();
Console.Write(content);
Console.WriteLine();
Console.WriteLine(Repeat("=", width));
}

public Task SendAsync(string recipient, string subject, string content, CancellationToken ct = default)
{
this.Send(recipient, subject, content);
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>GalliumPlus.WebApi.Data.FakeDatabase</RootNamespace>
<RootNamespace>GalliumPlus.WebApi</RootNamespace>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

Expand All @@ -13,15 +13,15 @@
</PropertyGroup>

<ItemGroup>
<None Remove="images\serial-designation-n.png" />
<None Remove="Data\FakeDatabase\images\serial-designation-n.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="images\serial-designation-n.png" />
<EmbeddedResource Include="Data\FakeDatabase\images\serial-designation-n.png" />
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions Gallium+ API.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{2FBF183A-5654-484C-8F60-6D6A1EA2F75C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeDatabase", "FakeDatabase\FakeDatabase.csproj", "{46987A9A-07DC-4CBF-8491-70EE86754046}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{2FD09829-C865-4CFF-BD3E-557FAA1CD3C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreTest", "CoreTest\CoreTest.csproj", "{902C447E-38D6-4EA3-97DF-05CD5B8E7C7F}"
Expand All @@ -21,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MariaDb", "MariaDb\MariaDb.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MailKitClient", "MailKitClient\MailKitClient.csproj", "{28D2F1D5-BC2B-4C00-992F-3C4B0AD3D9DF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeServices", "FakeServices\FakeServices.csproj", "{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,12 +34,6 @@ Global
{2FBF183A-5654-484C-8F60-6D6A1EA2F75C}.Release|Any CPU.Build.0 = Release|Any CPU
{2FBF183A-5654-484C-8F60-6D6A1EA2F75C}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{2FBF183A-5654-484C-8F60-6D6A1EA2F75C}.Test|Any CPU.Build.0 = Debug|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Release|Any CPU.Build.0 = Release|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{46987A9A-07DC-4CBF-8491-70EE86754046}.Test|Any CPU.Build.0 = Debug|Any CPU
{2FD09829-C865-4CFF-BD3E-557FAA1CD3C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FD09829-C865-4CFF-BD3E-557FAA1CD3C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FD09829-C865-4CFF-BD3E-557FAA1CD3C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -64,6 +58,12 @@ Global
{28D2F1D5-BC2B-4C00-992F-3C4B0AD3D9DF}.Release|Any CPU.Build.0 = Release|Any CPU
{28D2F1D5-BC2B-4C00-992F-3C4B0AD3D9DF}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{28D2F1D5-BC2B-4C00-992F-3C4B0AD3D9DF}.Test|Any CPU.Build.0 = Debug|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Release|Any CPU.Build.0 = Release|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{C2F60092-E6D7-41D0-9903-A5EE953EAAD8}.Test|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 4 additions & 2 deletions Service/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public IActionResult Delete(string id)
{
User userToDelete = this.userDao.Read(id);

if (userToDelete.MayBeDeleted)
if (!userToDelete.MayBeDeleted)
{
throw new PermissionDeniedException(Permissions.NONE);
}
Expand Down Expand Up @@ -239,7 +239,9 @@ public IActionResult CanResetPassword(string id)
{
User user = this.userDao.Read(id);

return Json(user.Identity.Email.Length > 0);
bool canResetPassword = user.Identity.Email.Length > 0 && user.Identity.Email != "UKN";

return Json(canResetPassword);
}

[HttpPost("{id}/reset-password")]
Expand Down
2 changes: 1 addition & 1 deletion Service/Dto/OrderSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static User BuildAnonymousMember()
new UserIdentity("Anonyme", "", "", ""),
new Role(-1, "Membre anonyme", Permissions.NONE),
0.00m,
false
true
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Service/GalliumOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GalliumPlus.WebApi.Email.MailKit;
#if !TEST
#if !TEST
using GalliumPlus.WebApi.Email.MailKit;
using GalliumPlus.WebApi.Data.MariaDb;
#endif

Expand All @@ -23,9 +23,9 @@ public class GalliumOptions

public string WebApplicationHost { get; set; } = "gallium.etiq-dijon.fr";

#if !TEST
public MailKitOptions MailKit { get; set; } = new();

#if !TEST
public MariaDbOptions MariaDb { get; set; } = new();
#endif
}
Expand Down
11 changes: 8 additions & 3 deletions Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
using System.Text.Json.Serialization;
using GalliumPlus.WebApi.Scheduling;
using GalliumPlus.WebApi.Core.Email;
using GalliumPlus.WebApi.Email.MailKit;
#if FAKE_DB
#if FAKE_DB && FAKE_EMAIL
using GalliumPlus.WebApi.Data.FakeDatabase;
using GalliumPlus.WebApi.Email.FakeEmailService;
#else
using GalliumPlus.WebApi.Data.MariaDb;
using GalliumPlus.WebApi.Email.MailKit;
#endif

#endregion
Expand Down Expand Up @@ -95,7 +96,11 @@
.AddSingleton<IEmailTemplateLoader, CachedLocalEmailTemplateLoader>(
services => new CachedLocalEmailTemplateLoader(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "templates"))
)
#if FAKE_EMAIL
.AddSingleton<IEmailSender, FakeEmailSender>(services => new FakeEmailSender());
#else
.AddSingleton<IEmailSender, EmailSender>(services => new EmailSender(galliumOptions.MailKit));
#endif

#endregion

Expand Down Expand Up @@ -170,7 +175,7 @@
app.UseAuthorization();
app.MapControllers();

ServerInfo.Current.SetVersion(0, 8, 1, "alpha");
ServerInfo.Current.SetVersion(0, 8, 2, "alpha");
Console.WriteLine(ServerInfo.Current);

app.Run();
6 changes: 3 additions & 3 deletions Service/Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Test|AnyCPU'">
<DefineConstants>$(DefineConstants);FAKE_DB;TEST</DefineConstants>
<DefineConstants>$(DefineConstants);FAKE_DB;FAKE_EMAIL;TEST</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,15 +18,15 @@

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\MailKitClient\MailKitClient.csproj" />
</ItemGroup>

<ItemGroup Condition="$(Configuration) == 'Test'">
<ProjectReference Include="..\FakeDatabase\FakeDatabase.csproj" />
<ProjectReference Include="..\FakeServices\FakeServices.csproj" />
</ItemGroup>

<ItemGroup Condition="($(Configuration) == 'Debug') Or ($(Configuration) == 'Release')">
<ProjectReference Include="..\MariaDb\MariaDb.csproj" />
<ProjectReference Include="..\MailKitClient\MailKitClient.csproj" />
</ItemGroup>

<Target Name="Date" BeforeTargets="BeforeBuild">
Expand Down

0 comments on commit ce9ef47

Please sign in to comment.