Skip to content

Commit

Permalink
Merge pull request #1681 from Crown-Commercial-Service/p3sprint8
Browse files Browse the repository at this point in the history
P3sprint8
  • Loading branch information
boobalanmurugan-bc authored May 11, 2023
2 parents a1472f9 + b279e83 commit d9c1607
Show file tree
Hide file tree
Showing 40 changed files with 4,602 additions and 280 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace CcsSso.Core.DbMigrations.Migrations
{
public partial class Add_UserAccessRolePending_OrganisationUserGroupId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "OrganisationUserGroupId",
table: "UserAccessRolePending",
type: "integer",
nullable: true);

migrationBuilder.CreateIndex(
name: "IX_UserAccessRolePending_OrganisationUserGroupId",
table: "UserAccessRolePending",
column: "OrganisationUserGroupId");

migrationBuilder.AddForeignKey(
name: "FK_UserAccessRolePending_OrganisationUserGroup_OrganisationUse~",
table: "UserAccessRolePending",
column: "OrganisationUserGroupId",
principalTable: "OrganisationUserGroup",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_UserAccessRolePending_OrganisationUserGroup_OrganisationUse~",
table: "UserAccessRolePending");

migrationBuilder.DropIndex(
name: "IX_UserAccessRolePending_OrganisationUserGroupId",
table: "UserAccessRolePending");

migrationBuilder.DropColumn(
name: "OrganisationUserGroupId",
table: "UserAccessRolePending");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("OrganisationEligibleRoleId")
.HasColumnType("integer");

b.Property<int?>("OrganisationUserGroupId")
.HasColumnType("integer");

b.Property<bool>("SendEmailNotification")
.HasColumnType("boolean");

Expand All @@ -1902,6 +1905,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("OrganisationEligibleRoleId");

b.HasIndex("OrganisationUserGroupId");

b.HasIndex("UserId");

b.ToTable("UserAccessRolePending");
Expand Down Expand Up @@ -2603,6 +2608,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("CcsSso.DbModel.Entity.OrganisationUserGroup", "OrganisationUserGroup")
.WithMany()
.HasForeignKey("OrganisationUserGroupId");

b.HasOne("CcsSso.DbModel.Entity.User", "User")
.WithMany("UserAccessRolePending")
.HasForeignKey("UserId")
Expand All @@ -2611,6 +2620,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("OrganisationEligibleRole");

b.Navigation("OrganisationUserGroup");

b.Navigation("User");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ UPDATE "CcsService" SET "ServiceCode"= null WHERE "ServiceCode" ='LOGIN_DIRECTOR
UPDATE "CcsService" SET "Description"='The eSourcing tool will help you supply to, or buy for, the public sector, compliantly.'
WHERE "ServiceCode" ='JAEGGER_BUYER_DS';

UPDATE "CcsService" SET "Description"='Find and contract suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.'
UPDATE "CcsService" SET "Description"='Find and contact suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.'
WHERE "ServiceCode" ='CAT_USER_DS';


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IF NOT EXISTS (SELECT "Id" FROM "CcsServiceRoleGroup" WHERE "Key" = 'CAS_USER_GR
INSERT INTO public."CcsServiceRoleGroup"(
"Key", "Name", "Description", "OrgTypeEligibility", "SubscriptionTypeEligibility", "TradeEligibility","DisplayOrder","MfaEnabled",
"DefaultEligibility", "ApprovalRequired","CreatedUserId", "LastUpdatedUserId", "CreatedOnUtc", "LastUpdatedOnUtc","IsDeleted")
VALUES ('CAS_USER_GROUP','Contract Award Service', 'Find and contract suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.', 2, 1, 1,1, false, null,0,0,0,now(),now(),false);
VALUES ('CAS_USER_GROUP','Contract Award Service', 'Find and contact suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.', 2, 1, 1,1, false, null,0,0,0,now(),now(),false);
END IF;

IF NOT EXISTS (SELECT "Id" FROM "CcsServiceRoleGroup" WHERE "Key" = 'FP_USER_GROUP') THEN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

UPDATE "CcsServiceRoleGroup" set "Key"= 'MANAGE_SUBSCRIPTIONS' WHERE "Key" = 'MANAGE_SUBSCRIPTIONS_GROUP';

UPDATE "CcsServiceRoleGroup" set "Key"= 'CAT_USER', "Description"='Find and contract suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.'
UPDATE "CcsServiceRoleGroup" set "Key"= 'CAT_USER', "Description"='Find and contact suitable suppliers for your procurement project, and ask them about the services they can provide. Progress to one stage further competition.'
WHERE "Key" in ('CAS_USER_GROUP','CAT_USER_GROUP','CAS_USER','CAT_USER','CAS_GROUP');

UPDATE "CcsServiceRoleGroup" set "Key"= 'FP_USER',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
START TRANSACTION;

ALTER TABLE "UserAccessRolePending" ADD "OrganisationUserGroupId" integer NULL;

CREATE INDEX "IX_UserAccessRolePending_OrganisationUserGroupId" ON "UserAccessRolePending" ("OrganisationUserGroupId");

ALTER TABLE "UserAccessRolePending" ADD CONSTRAINT "FK_UserAccessRolePending_OrganisationUserGroup_OrganisationUse~" FOREIGN KEY ("OrganisationUserGroupId") REFERENCES "OrganisationUserGroup" ("Id") ON DELETE RESTRICT;

INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20230327094219_Add_UserAccessRolePending_OrganisationUserGroupId', '5.0.10');

COMMIT;

4 changes: 4 additions & 0 deletions api/CcsSso.Core.DbModel/Entity/UserAccessRolePending.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ public class UserAccessRolePending : BaseEntity
public int Status { get; set; }

public bool SendEmailNotification { get; set; } = true;

public OrganisationUserGroup OrganisationUserGroup { get; set; }

public int? OrganisationUserGroupId { get; set; }
}
}
2 changes: 2 additions & 0 deletions api/CcsSso.Core.Domain/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public static class ErrorConstant
public const string ErrorLinkExpired = "ERROR_LINK_EXPIRED";
public const string ErrorUserAlreadyExists = "ERROR_USER_ALREADY_EXISTS";

public const string ErrorUserRoleAlreadyExists = "ERROR_USER_ROLE_ALREADY_EXISTS";

}

public static class VirtualContactTypeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface IOrganisationGroupService

Task<OrganisationServiceRoleGroupResponseInfo> GetServiceRoleGroupAsync(string ciiOrganisationId, int groupId);

Task<GroupUserListResponse> GetGroupUsersPendingRequestSummary(int groupId, string ciiOrgId, ResultSetCriteria resultSetCriteria, bool isPendingApproval);


Task UpdateServiceRoleGroupAsync(string ciiOrganisationId, int groupId, OrganisationServiceRoleGroupRequestInfo organisationServiceRoleGroupRequestInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IUserProfileRoleApprovalService

Task<UserAccessRolePendingTokenDetails> VerifyAndReturnRoleApprovalTokenDetailsAsync(string token);

Task RemoveApprovalPendingRolesAsync(string userName, string roles);
Task RemoveApprovalPendingRolesAsync(string userName, string roles, int? groupId = null);

Task CreateUserRolesPendingForApprovalAsync(UserProfileEditRequestInfo userProfileRequestInfo, bool sendEmailNotification = true);

Expand Down
12 changes: 12 additions & 0 deletions api/CcsSso.Core.Domain/Dtos/External/OrganisationGroupInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CcsSso.Core.DbModel.Constants;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -74,13 +75,24 @@ public class GroupServiceRoleGroup
public string Description { get; set; }
}

public class GroupUserListResponse:PaginationInfo
{
public int groupId { get; set; }

public List<GroupUser> GroupUser { get; set; }

}

public class GroupUser
{
public string UserId { get; set; }

public string Name { get; set; }

public bool IsAdmin { get; set; } = false;

public UserPendingRoleStaus? UserPendingRoleStatus { get; set; }

}

public class OrganisationGroupRolePatchInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class UserRequestMain

public class UserRequestDetail : UserRequestMain
{
public int? GroupId { get; set; }

public List<int> RoleIds { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,40 @@ public async Task UpdateOrganisationServiceRoleGroup(string organisationId, int
{
await _organisationGroupService.UpdateServiceRoleGroupAsync(organisationId, groupId, organisationServiceRoleGroupRequestInfo);
}

/// <summary>
/// Get organisation group users and their role approval status
/// </summary>
/// <response code="200">Ok</response>
/// <response code="401">Unauthorised</response>
/// <response code="403">Forbidden</response>
/// <response code="404">Resource not found</response>
/// <remarks>
/// Sample request:
///
/// GET /organisations/1/groups/1/groupusers
///
/// </remarks>
[HttpGet("{organisationId}/groups/{groupId}/groupusers")]
[ClaimAuthorise("ORG_ADMINISTRATOR")]
[OrganisationAuthorise("ORGANISATION")]
[SwaggerOperation(Tags = new[] { "Organisation Group" })]
[ProducesResponseType(typeof(GroupUserListResponse), 200)]
public async Task<GroupUserListResponse> GetGroupUsersPendingRequestSummary(string organisationId, int groupId,
[FromQuery] ResultSetCriteria resultSetCriteria,
[FromQuery(Name = "is-pending-approval")] bool isPendingApproval = false)
{
resultSetCriteria ??= new ResultSetCriteria
{
CurrentPage = 1,
PageSize = 10
};
resultSetCriteria.CurrentPage = resultSetCriteria.CurrentPage <= 0 ? 1 : resultSetCriteria.CurrentPage;
resultSetCriteria.PageSize = resultSetCriteria.PageSize <= 0 ? 10 : resultSetCriteria.PageSize;

return await _organisationGroupService.GetGroupUsersPendingRequestSummary(groupId, organisationId, resultSetCriteria,isPendingApproval);
}

#endregion

#region Organisation IdentityProviders
Expand Down Expand Up @@ -1431,7 +1465,7 @@ public async Task AutoValidateOrganisationTypeswitch(string organisationId, Orga
[HttpPost("{ciiOrganisationId}/autovalidationjob")]
[SwaggerOperation(Tags = new[] { "AutoValidation" })]
[ProducesResponseType(typeof(string), 200)]
public async Task<Tuple<bool,string>> AutovalidationJob(string ciiOrganisationId)
public async Task<Tuple<bool, string>> AutovalidationJob(string ciiOrganisationId)
{
return await _organisationService.AutoValidateOrganisationJob(ciiOrganisationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<List<UserAccessRolePendingDetails>> GetUserRolesPendingForAppr
/// <remarks>
/// Sample request:
///
/// DELETE /approve/role?user-id=user@mail.com&roles=1,2
/// DELETE /approve/role?user-id=user@mail.com&roles=1,2&groupId=1
///
///
/// </remarks>
Expand All @@ -72,9 +72,9 @@ public async Task<List<UserAccessRolePendingDetails>> GetUserRolesPendingForAppr
[OrganisationAuthorise("USER")]
[SwaggerOperation(Tags = new[] { "User" })]
[ProducesResponseType(typeof(void), 200)]
public async Task RemoveApprovalPendingRoles([FromQuery(Name = "user-id")] string userId, [FromQuery(Name = "roles")] string roleIds)
public async Task RemoveApprovalPendingRoles([FromQuery(Name = "user-id")] string userId, [FromQuery(Name = "roles")] string roleIds, [FromQuery(Name = "groupId")] int? groupId)
{
await _userProfileRoleApprovalService.RemoveApprovalPendingRolesAsync(userId, roleIds);
await _userProfileRoleApprovalService.RemoveApprovalPendingRolesAsync(userId, roleIds, groupId);
}

/// <summary>
Expand Down Expand Up @@ -115,7 +115,8 @@ public async Task<UserAccessRolePendingTokenDetails> VerifyRoleApprovalToken([Fr
/// {
/// "userName": "user@mail.com",
/// "detail": {
/// "roleIds": { 1, 2 }
/// "roleIds": { 1, 2 },
/// "groupId": null
/// }
/// }
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public async Task<List<UserAccessRolePending>> GetPendingRoleApproval()
var userAccessRolePendingAllList = await _dataContext.UserAccessRolePending
.Include(u => u.OrganisationEligibleRole).ThenInclude(or => or.CcsAccessRole)
.Where(u => !u.IsDeleted && u.Status == (int)UserPendingRoleStaus.Pending)
.OrderBy(u => u.CreatedOnUtc)
.ToListAsync();

return userAccessRolePendingAllList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,52 @@ public RoleApprovalLinkExpiredService(IServiceScopeFactory factory,

public async Task PerformJobAsync(List<UserAccessRolePending> pendingRoles)
{

var approvalRoleConfig = await _dataContext.RoleApprovalConfiguration.Where(x => !x.IsDeleted).ToListAsync();

List<UserAccessRolePending> expiredUserAccessRolePendingList = new();
List<UserAccessRolePending> relatedExpiredUserAccessRolePendingList = new();

foreach (var role in pendingRoles)
{
var roleExpireTime = role.LastUpdatedOnUtc.AddMinutes(approvalRoleConfig.FirstOrDefault(x => x.CcsAccessRoleId ==
role.OrganisationEligibleRole.CcsAccessRole.Id).LinkExpiryDurationInMinute);
var roleConfig = approvalRoleConfig.FirstOrDefault(x => x.CcsAccessRoleId ==
role.OrganisationEligibleRole.CcsAccessRole.Id);

if(roleConfig == null)
continue;

var roleExpireTime = role.LastUpdatedOnUtc.AddMinutes(roleConfig.LinkExpiryDurationInMinute);

if (roleExpireTime < DateTime.UtcNow)
{
expiredUserAccessRolePendingList.Add(role);
var isExistInRelatedList = relatedExpiredUserAccessRolePendingList.Any(x => x.Id == role.Id);

if (!isExistInRelatedList)
{
expiredUserAccessRolePendingList.Add(role);

var relatedPendingRoles = pendingRoles.Where(x => x.Id != role.Id && x.UserId == role.UserId).ToList();
relatedExpiredUserAccessRolePendingList.AddRange(relatedPendingRoles);
}
}
}

await ProcessRelatedExpiredUserAccessRolePending(relatedExpiredUserAccessRolePendingList);
await ProcessExpiredUserAccessRolePending(expiredUserAccessRolePendingList);
}

private async Task ProcessRelatedExpiredUserAccessRolePending(List<UserAccessRolePending> relatedExpiredUserAccessRolePendingList)
{
_logger.LogInformation($"Total number of related expired Roles: {relatedExpiredUserAccessRolePendingList.Count()}");

if (relatedExpiredUserAccessRolePendingList.Any())
{
await RemoveExpiredApprovalPendingRolesAsync(relatedExpiredUserAccessRolePendingList);
_logger.LogInformation($"Successfully updated the related expired roles");
}
}

private async Task ProcessExpiredUserAccessRolePending(List<UserAccessRolePending> expiredUserAccessRolePendingList)
{
_logger.LogInformation($"Total number of expired Roles: {expiredUserAccessRolePendingList.Count()}");

if (expiredUserAccessRolePendingList.Any())
Expand All @@ -67,7 +97,6 @@ public async Task PerformJobAsync(List<UserAccessRolePending> pendingRoles)
_logger.LogInformation($"Sending email if it is eligible");
await SendEmail(expiredUserAccessRolePendingList);
_logger.LogInformation($"Finished sending email");

}
}

Expand All @@ -78,9 +107,7 @@ private async Task RemoveExpiredApprovalPendingRolesAsync(List<UserAccessRolePen
if (userAccessRolePendingExpiredList.Any())
{
userAccessRolePendingExpiredList.ForEach(l => { l.IsDeleted = true; l.Status = (int)UserPendingRoleStaus.Expired; });
await _dataContext.SaveChangesAsync();


await _dataContext.SaveChangesAsync();
}
}

Expand Down
19 changes: 19 additions & 0 deletions api/CcsSso.Core.PPONScheduler/CcsSso.Core.PPONScheduler.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CcsSso.Core.DbPersistence\CcsSso.Core.DbPersistence.csproj" />
<ProjectReference Include="..\CcsSso.Core.Domain\CcsSso.Core.Domain.csproj" />
<ProjectReference Include="..\CcsSso.Core.Service\CcsSso.Core.Service.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit d9c1607

Please sign in to comment.