Skip to content

Commit 1b9803c

Browse files
committed
Pushed fixes down from commercial editions
1 parent c1e2fae commit 1b9803c

File tree

47 files changed

+504
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+504
-425
lines changed

src/Server/Coderr.Server.Abstractions/Security/ClaimsExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public static int GetAccountId(this ClaimsPrincipal principal)
4848
throw ex;
4949
}
5050

51+
/// <summary>
52+
/// Get account id (<see cref="ClaimTypes.NameIdentifier" />).
53+
/// </summary>
54+
/// <param name="principal">principal to search in</param>
55+
/// <returns>id</returns>
56+
/// <exception cref="InvalidOperationException">Claim is not found in the identity/ies.</exception>
57+
public static int FindAccountId(this ClaimsPrincipal principal)
58+
{
59+
var claim = principal.FindFirst(x => x.Type == ClaimTypes.NameIdentifier);
60+
if (claim == null)
61+
return 0;
62+
63+
if (int.TryParse(claim.Value, out var userId))
64+
return userId;
65+
66+
return -1;
67+
}
68+
5169
/// <summary>
5270
/// Get account id (<see cref="ClaimTypes.NameIdentifier" />).
5371
/// </summary>
@@ -148,7 +166,7 @@ public static bool IsSysAdmin(this IPrincipal principal)
148166
public static string ToFriendlyString(this IPrincipal principal)
149167
{
150168
var cc = principal as ClaimsPrincipal;
151-
if (cc == null || !principal.Identity.IsAuthenticated)
169+
if (cc == null || principal.Identity?.IsAuthenticated != true)
152170
{
153171
return "Anonymous";
154172
}

src/Server/Coderr.Server.Abstractions/Security/IPrincipalAccessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ namespace Coderr.Server.Abstractions.Security
88
public interface IPrincipalAccessor
99
{
1010
ClaimsPrincipal Principal { get; set; }
11+
12+
ClaimsPrincipal FindPrincipal();
1113
}
1214
}

src/Server/Coderr.Server.Api/Core/Accounts/Commands/RegisterAccount.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,14 @@ public void Activate(int accountId)
6868
ActivateDirectly = true;
6969
AccountId = accountId;
7070
}
71+
72+
/// <summary>
73+
/// Activate this account directly
74+
/// </summary>
75+
public void Activate()
76+
{
77+
ActivateDirectly = true;
78+
AccountId = 0;
79+
}
7180
}
7281
}

src/Server/Coderr.Server.Api/Core/Applications/ApplicationListItem.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ public class ApplicationListItem
1515
/// <param name="name">name of the application</param>
1616
public ApplicationListItem(int id, string name)
1717
{
18-
if (name == null) throw new ArgumentNullException("name");
1918
if (id <= 0) throw new ArgumentOutOfRangeException("id");
2019

2120
Id = id;
22-
Name = name;
21+
Name = name ?? throw new ArgumentNullException("name");
2322
}
2423

2524
/// <summary>
@@ -30,20 +29,30 @@ protected ApplicationListItem()
3029
}
3130

3231
/// <summary>
33-
/// Id of the application (primary key)
32+
/// Group that this application belongs to.
3433
/// </summary>
35-
public int Id { get; set; }
34+
public int GroupId { get; set; }
3635

3736
/// <summary>
38-
/// Application name as entered by the user.
37+
/// Name of the group
3938
/// </summary>
40-
public string Name { get; set; }
39+
public string GroupName { get; set; }
40+
41+
/// <summary>
42+
/// Id of the application (primary key)
43+
/// </summary>
44+
public int Id { get; set; }
4145

4246
/// <summary>
4347
/// User that requested this list is the admin of the specified application.
4448
/// </summary>
4549
public bool IsAdmin { get; set; }
4650

51+
/// <summary>
52+
/// Application name as entered by the user.
53+
/// </summary>
54+
public string Name { get; set; }
55+
4756
/// <summary>
4857
/// Number of full time developers.
4958
/// </summary>

src/Server/Coderr.Server.Api/Core/Incidents/Queries/FindIncidentsResultItem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace Coderr.Server.Api.Core.Incidents.Queries
77
/// </summary>
88
public class FindIncidentsResultItem
99
{
10-
1110
/// <summary>
1211
/// Creates new instance of <see cref="FindIncidentsResultItem" />.
1312
/// </summary>
@@ -72,7 +71,7 @@ protected FindIncidentsResultItem()
7271
/// <summary>
7372
/// Incident name
7473
/// </summary>
75-
public string Name { get; set; }
74+
public string Name { set; get; }
7675

7776
/// <summary>
7877
/// Total number of received reports (increased even if the number of stored reports are at the limit)

src/Server/Coderr.Server.Api/Core/Incidents/Queries/GetCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ protected GetCollection()
2222
/// <summary>
2323
/// Collection name like "ErrorProperties" or "HttpRequest".
2424
/// </summary>
25-
public string CollectionName { get; }
25+
public string CollectionName { get; private set; }
2626

2727
/// <summary>
2828
/// Incident that the collection belongs to.
2929
/// </summary>
30-
public int IncidentId { get; }
30+
public int IncidentId { get; private set; }
3131

3232
/// <summary>
3333
/// Collection limit.

src/Server/Coderr.Server.App/Core/Accounts/AccountService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ public async Task<ClaimsIdentity> Login(string userName, string password)
162162
return identity;
163163
}
164164

165+
public async Task<Account> CreateAsync(string userName, string email)
166+
{
167+
var password = Guid.NewGuid().ToString("N").Substring(0, 10);
168+
var account = new Account(userName, password);
169+
account.Activate();
170+
account.SetVerifiedEmail(email);
171+
await _repository.CreateAsync(account);
172+
await _messageBus.SendAsync(new AccountRegistered(account.Id, userName));
173+
return account;
174+
}
165175

166176
/// <summary>
167177
/// Accepts and deletes the invitation. Sends an event which is picked up by the application domain (which transforms

src/Server/Coderr.Server.App/Core/Accounts/IAccountService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Coderr.Server.Api.Core.Accounts.Events;
44
using Coderr.Server.Api.Core.Accounts.Requests;
5+
using Coderr.Server.Domain.Core.Account;
56

67
namespace Coderr.Server.App.Core.Accounts
78
{
@@ -61,5 +62,11 @@ public interface IAccountService
6162
/// Task which will contain the reply once completed.
6263
/// </returns>
6364
Task<ClaimsIdentity> Login(string userName, string password);
65+
66+
/// <summary>
67+
/// Create a new account for the given userName
68+
/// </summary>
69+
/// <param name="userName"></param>
70+
Task<Account> CreateAsync(string userName, string email);
6471
}
6572
}

src/Server/Coderr.Server.App/Core/ApiKeys/ApiKey.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public void Add(int applicationId)
7373
if (applicationId <= 0) throw new ArgumentOutOfRangeException("applicationId");
7474

7575
_claims.Add(new Claim(CoderrClaims.Application, applicationId.ToString(), ClaimValueTypes.Integer32));
76+
77+
// Api clients typically are allowed to manage everything. Let's do that!
78+
_claims.Add(new Claim(CoderrClaims.ApplicationAdmin, applicationId.ToString(), ClaimValueTypes.Integer32));
7679
}
7780

7881
/// <summary>

src/Server/Coderr.Server.App/Core/Incidents/Commands/CloseIncidentHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task HandleAsync(IMessageContext context, CloseIncident command)
5050
!string.IsNullOrEmpty(command.NotificationText))
5151
{
5252
var emails = await _feedbackRepository.GetEmailAddressesAsync(command.IncidentId);
53-
if (emails.Any())
53+
if (emails.Distinct().Any())
5454
{
5555
var emailMessage = new EmailMessage(emails)
5656
{

0 commit comments

Comments
 (0)