Skip to content

Commit 8ea20af

Browse files
authored
Added authorisation status to roleuser model. (#640)
1 parent 507ac45 commit 8ea20af

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/NoFrixion.MoneyMoov/ApiClients/MerchantClient.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Task<RestApiResponse<MerchantPageResponse>> GetChildMerchantsAsync(string userAc
6262
int pageSize = 20,
6363
string? search = null,
6464
string? sort = null);
65+
66+
Task<RestApiResponse<RoleUser>> GetRoleUserAssignmentAsync(string userAccessToken, Guid roleUserID);
67+
68+
Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserAccessToken, Guid roleUserID);
6569
}
6670

6771
public class MerchantClient : IMerchantClient
@@ -403,4 +407,44 @@ public Task<RestApiResponse<MerchantPageResponse>> GetChildMerchantsAsync(string
403407
_ => Task.FromResult(new RestApiResponse<MerchantPageResponse>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
404408
};
405409
}
410+
411+
/// <summary>
412+
/// Gets a specific role user assignment by its ID.
413+
/// </summary>
414+
/// <param name="userAccessToken">A user scoped JWT access token.</param>
415+
/// <param name="roleUserID">The ID of the role user assignment to get.</param>
416+
/// <returns>If successful, the role user assignment.</returns>
417+
public Task<RestApiResponse<RoleUser>> GetRoleUserAssignmentAsync(string userAccessToken, Guid roleUserID)
418+
{
419+
var url = MoneyMoovUrlBuilder.MerchantsApi.MerchantRoleUserAssignmentsUrl(_apiClient.GetBaseUri().ToString(), roleUserID);
420+
421+
var prob = _apiClient.CheckAccessToken(userAccessToken, nameof(GetRolesAsync));
422+
423+
return prob switch
424+
{
425+
var p when p.IsEmpty => _apiClient.GetAsync<RoleUser>(url, userAccessToken),
426+
_ => Task.FromResult(new RestApiResponse<RoleUser>(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
427+
};
428+
}
429+
430+
/// <summary>
431+
/// Calls the MoneyMoov merchant endpoint to authorise a role user assignment.
432+
/// </summary>
433+
/// <param name="strongUserAccessToken">The strong user access token acquired to authorise the role suer assignment. Strong
434+
/// tokens can only be acquired from a strong customer authentication flow, are short lived (typically 5 minute expiry)
435+
/// and are specific to the role user assignment.</param>
436+
/// <param name="roleUserID">The ID of the role user assignment to authorise.</param>
437+
/// <returns>An API response indicating the result of the authorise attempt.</returns>
438+
public Task<RestApiResponse> AuthoriseRoleUserAssignmentAsync(string strongUserAccessToken, Guid roleUserID)
439+
{
440+
var url = MoneyMoovUrlBuilder.MerchantsApi.MerchantRoleUserAssignmentsUrl(_apiClient.GetBaseUri().ToString(), roleUserID);
441+
442+
var prob = _apiClient.CheckAccessToken(strongUserAccessToken, nameof(AuthoriseRoleUserAssignmentAsync));
443+
444+
return prob switch
445+
{
446+
var p when p.IsEmpty => _apiClient.PostAsync(url, strongUserAccessToken),
447+
_ => Task.FromResult(new RestApiResponse(HttpStatusCode.PreconditionFailed, new Uri(url), prob))
448+
};
449+
}
406450
}

src/NoFrixion.MoneyMoov/Models/Roles/Role.cs

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class Role
2727

2828
public Guid MerchantID { get; set; }
2929

30+
public string? MerchantName { get; set; }
31+
3032
public List<string> MerchantPermissions { get; set; } = null!;
3133

3234
public List<string> AccountPermissions { get; set; } = null!;

src/NoFrixion.MoneyMoov/Models/Roles/RoleUser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public class RoleUser
4141

4242
public Role? Role { get; set; }
4343

44+
/// <summary>
45+
/// The authorisation status for the role user assignment. It is used for assignments
46+
/// that require authorisation before they can be enabled. It will not be populated in the
47+
/// case authorisation is not required.
48+
/// </summary>
49+
public AuthorisationStatus? AuthorisationStatus { get; set; }
50+
4451
/// <summary>
4552
/// Gets a hash of the critical fields for the role user. This hash is
4653
/// used to ensure a role user's details are not modified between the time the

src/NoFrixion.MoneyMoov/MoneyMoovUrlBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public enum MoneyMoovResources
5858
roles,
5959

6060
users,
61+
62+
roleusers
6163
}
6264

6365

@@ -153,6 +155,9 @@ public static string ChildMerchantsUrl(string moneyMoovBaseUrl, Guid parentMerch
153155
string? sort)
154156
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.merchants}/{parentMerchantID}/childmerchants" +
155157
$"?pageNumber={pageNumber}&pageSize={pageSize}&search={search}&sort={sort}";
158+
159+
public static string MerchantRoleUserAssignmentsUrl(string moneyMoovBaseUrl, Guid roleUserID)
160+
=> $"{moneyMoovBaseUrl}/{MoneyMoovResources.merchants}/{MoneyMoovResources.roleusers}/{roleUserID}";
156161
}
157162

158163
/// <summary>

0 commit comments

Comments
 (0)