Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauffin committed Sep 26, 2020
2 parents 6e0491f + 93d3da3 commit de95241
Show file tree
Hide file tree
Showing 120 changed files with 1,742 additions and 828 deletions.
6 changes: 3 additions & 3 deletions src/DockerCompose/Windows/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ version: "3.7"
services:

coderr-server-web:
image: "coderrio/win_coderrserverweb:latest"
container_name: coderr-server-web
hostname: coderr-server-web
image: "coderrio/communityserver-win:latest"
container_name: coderr-communityserver
hostname: coderr-communityserver
ports:
- "2500:80"

Expand Down
25 changes: 0 additions & 25 deletions src/Server/BuildAndPushWinImage.bat

This file was deleted.

6 changes: 0 additions & 6 deletions src/Server/BuildFrontend.bat

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static void AssignProperties(this IConfigurationSection section, IDiction
foreach (var kvp in settings)
{
var property = type.GetProperty(kvp.Key);
if (property == null)
continue;

var propertyType = property.PropertyType;
if (propertyType == typeof(Uri))
{
Expand Down
20 changes: 20 additions & 0 deletions src/Server/Coderr.Server.Abstractions/HostConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Coderr.Server.Abstractions
{
/// <summary>
/// Wraps either the configuration file or the Docker environment variables.
/// </summary>
public class HostConfig
{
public static HostConfig Instance = new HostConfig();

public bool IsRunningInDocker { get; set; }
public string ConnectionString { get; set; }
public bool IsConfigured { get; set; }
public string ConfigurationPassword { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private ClaimsPrincipal CreateUserPrincipal()
var claims = new List<Claim>
{
};
var identity = new ClaimsIdentity(claims);
var identity = new ClaimsIdentity(claims, AuthenticationTypes.Default);
return new ClaimsPrincipal(identity);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Server/Coderr.Server.App.Tests/PrincipalHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Security.Claims;
using Coderr.Server.Infrastructure.Security;

namespace Coderr.Server.App.Tests
{
Expand All @@ -12,7 +13,7 @@ public static ClaimsPrincipal Create(int userId, string userName)
new Claim(ClaimTypes.Name, userName),
new Claim(ClaimTypes.NameIdentifier, userId.ToString(), ClaimValueTypes.Integer32),
};
var identity = new ClaimsIdentity(claims);
var identity = new ClaimsIdentity(claims, AuthenticationTypes.Default);
return new ClaimsPrincipal(identity);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Server/Coderr.Server.App/Core/Accounts/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<bool> ResetPassword(string activationKey, string newPassword)
/// <returns>
/// Task which will contain the reply once completed.
/// </returns>
public async Task<ClaimsIdentity> ActivateAccount(ClaimsPrincipal user, string activationKey)
public async Task<ClaimsIdentity> ActivateAccount(ClaimsPrincipal messagingPrincipal, string activationKey)
{
var account = await _repository.FindByActivationKeyAsync(activationKey);
if (account == null)
Expand All @@ -91,13 +91,13 @@ public async Task<ClaimsIdentity> ActivateAccount(ClaimsPrincipal user, string a
await _repository.UpdateAsync(account);


if (!user.IsCurrentAccount(account.Id))
if (!messagingPrincipal.IsCurrentAccount(account.Id))
{
var evt = new AccountActivated(account.Id, account.UserName)
{
EmailAddress = account.Email
};
await _messageBus.SendAsync(user, evt);
await _messageBus.SendAsync(messagingPrincipal, evt);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public async Task HandleAsync(IMessageContext context, RegisterAccount command)

if (!string.IsNullOrEmpty(command.UserName) && await _repository.IsUserNameTakenAsync(command.UserName))
{
await SendAccountInfo(context, command.UserName);
_logger.Warn("UserName is taken: " + command.UserName);
await SendAccountInfo(context, command.UserName);
return;
}

Expand All @@ -60,7 +60,10 @@ public async Task HandleAsync(IMessageContext context, RegisterAccount command)
account.SetVerifiedEmail(command.Email);

if (command.ActivateDirectly)
{
_logger.Debug("Activating directly");
account.Activate();
}

var accountCount = await _repository.CountAsync();
if (accountCount == 0)
Expand Down Expand Up @@ -122,7 +125,7 @@ private Task SendVerificationEmail(IMessageContext context, Account account)
You can activate your account by clicking on: {1}/account/activate/{0}
Good luck,
Coderr Team", account.ActivationKey, config.BaseUrl),
Coderr Team", account.ActivationKey, config.BaseUrl.ToString().TrimEnd('/')),
Subject = "Coderr activation"
};
msg.Recipients = new[] { new EmailAddress(account.Email) };
Expand Down
11 changes: 10 additions & 1 deletion src/Server/Coderr.Server.App/Core/Accounts/IAccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface IAccountService
/// Accepts and deletes the invitation. Sends an event which is picked up by the application domain (which transforms
/// the pending invite to a membership)
/// </summary>
/// <param name="messagingPrincipal">Logged in user.</param>
/// <param name="request">Information about the accept invitation request</param>
/// <returns>Updated identity with permission to the applications that the user was invited to.</returns>
/// <remarks>
/// <para>
/// Do note that an invitation can be accepted by using another email address than the one that the invitation was
Expand All @@ -20,8 +23,14 @@ public interface IAccountService
/// invitation.
/// </para>
/// </remarks>
Task<ClaimsIdentity> AcceptInvitation(ClaimsPrincipal user, AcceptInvitation request);
Task<ClaimsIdentity> AcceptInvitation(ClaimsPrincipal messagingPrincipal, AcceptInvitation request);

/// <summary>
/// Validate login information (check if the specified information is available).
/// </summary>
/// <param name="emailAddress">Email address as specified by the user.</param>
/// <param name="userName">Wanted userName</param>
/// <returns></returns>
Task<ValidateNewLoginReply> ValidateLogin(string emailAddress, string userName);

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Server/Coderr.Server.App/Core/ApiKeys/ApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Security.Cryptography;
using System.Text;
using Coderr.Server.Abstractions.Security;
using Coderr.Server.Infrastructure.Security;

namespace Coderr.Server.App.Core.ApiKeys
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Coderr.Server.Domain.Core.User;
using DotNetCqs;


namespace Coderr.Server.App.Core.Applications.CommandHandlers
{
internal class CreateApplicationHandler : IMessageHandler<CreateApplication>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ from x in apps
}
else
result = (await _applicationRepository.GetAllAsync())
.Select(x => new ApplicationListItem(x.Id, x.Name) { IsAdmin = isSysAdmin })
.Select(x => new ApplicationListItem(x.Id, x.Name)
{
IsAdmin = isSysAdmin,
NumberOfDevelopers = x.NumberOfFtes,
})
.ToArray();

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Coderr.Server.Domain.Core.Applications;
using Coderr.Server.Domain.Core.User;
using Coderr.Server.Infrastructure.Configuration;
using Coderr.Server.Infrastructure.Security;
using DotNetCqs;

using log4net;
Expand All @@ -31,14 +30,15 @@ public class InviteUserHandler : IMessageHandler<InviteUser>
private readonly IInvitationRepository _invitationRepository;
private readonly IUserRepository _userRepository;
private readonly ILog _logger = LogManager.GetLogger(typeof(InviteUserHandler));
private BaseConfiguration _baseConfiguration;
private readonly BaseConfiguration _baseConfiguration;

/// <summary>
/// Creates a new instance of <see cref="InviteUserHandler" />.
/// </summary>
/// <param name="invitationRepository">Store invitations</param>
/// <param name="userRepository">To load inviter and invitee</param>
/// <param name="applicationRepository">Add pending member</param>
/// <param name="invitationRepository">Store invitations.</param>
/// <param name="userRepository">To load invited and invitee.</param>
/// <param name="applicationRepository">Add pending member.</param>
/// <param name="baseConfig">To get the base url.</param>
public InviteUserHandler(IInvitationRepository invitationRepository,
IUserRepository userRepository, IApplicationRepository applicationRepository, IConfiguration<BaseConfiguration> baseConfig)
{
Expand Down Expand Up @@ -127,6 +127,7 @@ public async Task HandleAsync(IMessageContext context, InviteUser command)
protected virtual async Task SendInvitationEmailAsync(IMessageContext context, Invitation invitation, string reason)
{
var url = _baseConfiguration.BaseUrl.ToString().TrimEnd('/');

if (string.IsNullOrEmpty(reason))
reason = "";
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public async Task<GetReportResult> HandleAsync(IMessageContext context, GetRepor
var collections = (
from x in report.ContextCollections
where x.Properties.Count > 0
let properties = Enumerable.Select(x.Properties, y => new KeyValuePair(y.Key, y.Value))
select new GetReportResultContextCollection(x.Name, Enumerable.ToArray(properties))
let properties = x.Properties.Select(y => new KeyValuePair(y.Key, y.Value))
select new GetReportResultContextCollection(x.Name, properties.ToArray())
).ToList();

//TODO: Fix feedback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public async Task HandleAsync(IMessageContext context, IncidentReOpened message)
{
int? accountId;

if (context.Principal.IsInRole(CoderrRoles.System))
accountId = null;
else
accountId = context.Principal.GetAccountId();

try
{
if (context.Principal.IsInRole(CoderrRoles.System))
accountId = null;
else
accountId = context.Principal.GetAccountId();
}
catch (Exception ex)
{
ex.Data["Principal"] = context.Principal.ToFriendlyString();
throw;
}

var e = new HistoryEntry(message.IncidentId, accountId, IncidentState.ReOpened)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ public async Task<bool> Validate(string appKey, IPAddress remoteAddress)
/// </summary>
/// <param name="applicationId">Application that the error is reported for.</param>
/// <param name="remoteAddress">IP address of the client reporting the error.</param>
/// <returns></returns>
/// <returns></returns>h
public async Task<bool> Validate(int applicationId, IPAddress remoteAddress)
{
var ipEntry = await _repository.FindIp(applicationId, remoteAddress);
if (ipEntry != null) return ipEntry.IpType != IpType.Denied;
if (ipEntry != null)
{
return ipEntry.IpType != IpType.Denied;
}

var domains = await _repository.FindWhitelists(applicationId);

Expand Down
10 changes: 10 additions & 0 deletions src/Server/Coderr.Server.Domain/Core/Account/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public bool Login(string password)
return false;
}

/// <summary>
/// Mark user as logged in.
/// </summary>
public void SingleSignOn()
{
LastLoginAtUtc = DateTime.UtcNow;
LoginAttempts = 0;
AccountState = AccountState.Active;
}

/// <summary>
/// Want to reset password.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ public class UserFeedback
/// <summary>
/// We've identified which report this feedback belongs to
/// </summary>
/// <param name="reportId">Report PK</param>
/// <param name="reportId">Report PK, can be null if we do not store the report that the feedback came with</param>
/// <param name="incidentId">Incident that the report belongs to</param>
/// <param name="applicationId">Application that the incident belongs to</param>
public void AssignToReport(int reportId, int incidentId, int applicationId)
{
if (reportId <= 0) throw new ArgumentOutOfRangeException("reportId");
if (incidentId <= 0) throw new ArgumentOutOfRangeException("incidentId");
if (applicationId <= 0) throw new ArgumentOutOfRangeException("applicationId");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ namespace Coderr.Server.Domain.Core.Incidents.Events
/// </summary>
public class IncidentCreated
{
public IncidentCreated(int applicationId, int incidentId, string incidentDescription, string exceptionTypeName)
public IncidentCreated(int applicationId, int incidentId, string incidentName, string exceptionTypeName)
{
if (incidentDescription == null) throw new ArgumentNullException(nameof(incidentDescription));
if (incidentName == null) throw new ArgumentNullException(nameof(incidentName));
if (exceptionTypeName == null) throw new ArgumentNullException(nameof(exceptionTypeName));
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
if (applicationId <= 0) throw new ArgumentOutOfRangeException(nameof(applicationId));
ApplicationId = applicationId;
IncidentId = incidentId;

var pos = incidentDescription.IndexOfAny(new[] { '\r', '\n' });
var pos = incidentName.IndexOfAny(new[] { '\r', '\n' });
if (pos != -1)
incidentDescription = incidentDescription.Substring(0, pos);
IncidentName = incidentDescription;
incidentName = incidentName.Substring(0, pos);
IncidentName = incidentName;
ExceptionTypeName = exceptionTypeName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IIncidentRepository
/// <summary>
/// Get specified incidents
/// </summary>
/// <param name="incidentIds">ids to fecth</param>
/// <param name="incidentIds">ids to fetch</param>
/// <returns>All specified (or an exception will be thrown if any of them are missing)</returns>
Task<IList<Incident>> GetManyAsync(IEnumerable<int> incidentIds);

Expand All @@ -43,11 +43,28 @@ public interface IIncidentRepository
/// <summary>
/// Update incident
/// </summary>
/// <param name="incident">incdient</param>
/// <param name="incident">incident</param>
/// <returns>task</returns>
/// <exception cref="ArgumentNullException">incident</exception>
Task UpdateAsync(Incident incident);

/// <summary>
/// Map a correlation id to an incident.
/// </summary>
/// <param name="incidentId">Incident to mark</param>
/// <param name="correlationId">Correlation id to associate it with</param>
/// <returns></returns>
/// <remarks>
/// Correlation ids are used to find related incidents (they are associated with the same correlation id).
/// </remarks>
Task MapCorrelationId(int incidentId, string correlationId);

/// <summary>
/// Get all specified incidents.
/// </summary>
/// <param name="incidentIds">a list if ids</param>
/// <returns></returns>
Task<IList<Incident>> GetAll(IEnumerable<int> incidentIds);

}
}
Loading

0 comments on commit de95241

Please sign in to comment.