fix: enable and manage customize checkout options in client menu

This commit is contained in:
MahanCh
2025-08-18 11:55:34 +03:30
parent b82456f172
commit b92aaaffa0
9 changed files with 62 additions and 13 deletions

View File

@@ -42,6 +42,7 @@ public class AuthHelper : IAuthHelper
result.WorkshopName = claims.FirstOrDefault(x => x is { Type: "WorkshopName" })?.Value;
result.Permissions = Tools.DeserializeFromBsonList<int>(claims.FirstOrDefault(x => x is { Type: "permissions" })?.Value);
result.RoleName = claims.FirstOrDefault(x => x is { Type: "RoleName" })?.Value;
result.WorkshopId = long.Parse(claims.FirstOrDefault(x => x.Type == "WorkshopId")?.Value??"0");
return result;
}
@@ -76,7 +77,7 @@ public class AuthHelper : IAuthHelper
#region Vafa
public void UpdateWorkshopSlugClaim(string newWorkshopSlug, string newWorkshopName)
public void UpdateWorkshopSlugClaim(string newWorkshopSlug, string newWorkshopName,long newWorkshopId)
{
var user = _contextAccessor.HttpContext.User;
@@ -85,6 +86,7 @@ public class AuthHelper : IAuthHelper
var claimsIdentity = (ClaimsIdentity)user.Identity;
var existingClaimSlug = claimsIdentity.FindFirst("WorkshopSlug");
var existingClaimName = claimsIdentity.FindFirst("WorkshopName");
var existingWorkshopId = claimsIdentity.FindFirst("WorkshopId");
if (existingClaimSlug != null)
{
@@ -96,9 +98,14 @@ public class AuthHelper : IAuthHelper
claimsIdentity.RemoveClaim(existingClaimName);
}
if (existingWorkshopId != null)
{
claimsIdentity.RemoveClaim(existingWorkshopId);
}
claimsIdentity.AddClaim(new Claim("WorkshopSlug", newWorkshopSlug));
claimsIdentity.AddClaim(new Claim("WorkshopName", newWorkshopName));
claimsIdentity.AddClaim(new Claim("WorkshopId",newWorkshopId.ToString()));
var authProperties = new AuthenticationProperties
@@ -128,8 +135,16 @@ public class AuthHelper : IAuthHelper
return "";
}
#endregion
public long GetWorkshopId()
{
return long.Parse(_contextAccessor.HttpContext?.User.Claims.FirstOrDefault(x => x.Type == "WorkshopId")?.Value ?? "0");
}
public string CurrentAccountRole()
{
@@ -182,6 +197,7 @@ public class AuthHelper : IAuthHelper
//mahanChanges
new("workshopList",workshopBson),
new("WorkshopSlug",slug),
new("WorkshopId", account.WorkshopId.ToString()),
new("WorkshopName",account.WorkshopName??"")
};

View File

@@ -20,6 +20,7 @@ public class AuthViewModel
public int? PositionValue { get; set; }
public string WorkshopSlug { get; set; }
public long WorkshopId { get; set; }
public string WorkshopName { get; set; }
public List<WorkshopClaim> WorkshopList { get; set; }

View File

@@ -17,11 +17,12 @@ public interface IAuthHelper
#region Vafa
void UpdateWorkshopSlugClaim(string workshopSlug, string workshopName);
void UpdateWorkshopSlugClaim(string workshopSlug, string workshopName, long workshopId);
#endregion
long CurrentSubAccountId();
string GetWorkshopSlug();
string GetWorkshopName();
long GetWorkshopId();
(long Id, UserType userType, long roleId) GetUserTypeWithId();
}

View File

@@ -259,7 +259,8 @@ public class AccountApplication : IAccountApplication
var workshop = workshopList.First();
authViewModel.WorkshopName = workshop.Name;
authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id);
}
authViewModel.WorkshopId = workshop.Id;
}
}
_authHelper.Signin(authViewModel);
@@ -317,6 +318,7 @@ public class AccountApplication : IAccountApplication
var workshop = workshopList.First();
authViewModel.WorkshopName = workshop.WorkshopName;
authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.WorkshopId);
authViewModel.WorkshopId = workshop.WorkshopId;
}
_authHelper.Signin(authViewModel);
idAutoriz = 2;
@@ -368,6 +370,7 @@ public class AccountApplication : IAccountApplication
var workshop = workshopList.First();
authViewModel.WorkshopName = workshop.Name;
authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id);
authViewModel.WorkshopId = workshop.Id;
}
}
@@ -515,6 +518,7 @@ public class AccountApplication : IAccountApplication
var workshop = authViewModel.WorkshopList.First();
authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id);
authViewModel.WorkshopName = workshop.Name;
authViewModel.WorkshopId = workshop.Id;
}
_authHelper.Signin(authViewModel);
return operation.Succcedded(2);

View File

@@ -1,22 +1,27 @@
using _0_Framework.Application;
using CompanyManagment.App.Contracts.FinancialStatment;
using CompanyManagment.App.Contracts.RollCallService;
using CompanyManagment.App.Contracts.Workshop;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Client.Controllers;
public record GetClientProfileDetails(long Id, string Fullname, string Mobile, List<int> Permissions, List<WorkshopClaim> Workshops, string WorkshopSlug, double DebtAmount,UserType UserType);
public record GetClientProfileDetails(long Id, string Fullname, string Mobile,
List<int> Permissions, List<WorkshopClaim> Workshops,
string WorkshopSlug, double DebtAmount,UserType UserType,bool HasRollCallService,bool HasCustomizeCheckout);
public class LoginController : ClientBaseController
{
private readonly IAuthHelper _authHelper;
private readonly IFinancialStatmentApplication _financialStatmentApplication;
private readonly IRollCallServiceApplication _rollCallServiceApplication;
public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication)
public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication, IRollCallServiceApplication rollCallServiceApplication)
{
_authHelper = authHelper;
_financialStatmentApplication = financialStatmentApplication;
_rollCallServiceApplication = rollCallServiceApplication;
}
/// <summary>
/// جزئیات پروفایل کاربر کلاینت را برمی گرداند
@@ -37,6 +42,12 @@ public class LoginController : ClientBaseController
return Unauthorized();
var debtAmount = await _financialStatmentApplication.GetClientDebtAmount(data.Id);
var rollCallService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(_authHelper.GetWorkshopId());
var hasRollCallService = rollCallService != null;
var hasCustomizeCheckout = rollCallService?.HasCustomizeCheckoutService=="true";
var details = new GetClientProfileDetails(
data.Id,
data.Fullname,
@@ -45,7 +56,9 @@ public class LoginController : ClientBaseController
data.WorkshopList,
data.WorkshopSlug,
debtAmount,
userTypeWithId.userType
userTypeWithId.userType,
hasRollCallService,
hasCustomizeCheckout
);
return details;
}
@@ -61,7 +74,7 @@ public class LoginController : ClientBaseController
var selectedWorkshop = _authHelper.CurrentAccountInfo().WorkshopList.FirstOrDefault(x => x.Slug == slug);
if (selectedWorkshop != null)
{
_authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug, selectedWorkshop.Name);
_authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug, selectedWorkshop.Name, selectedWorkshop.Id);
return new JsonResult(new
{

View File

@@ -108,12 +108,14 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall
var hasRollCallService = activeService != null;
bool hasCameraAccount;
bool hasCustomizeCheckout = false;
if (hasRollCallService)
{
var accountId = _authHelper.CurrentAccountId();
var cameraAccountExists = _cameraAccountApplication.HasCameraAccount(workshopId, accountId);
hasCameraAccount = cameraAccountExists && hasPreviousService;
hasCustomizeCheckout = activeService.HasCustomizeCheckoutService=="true";
}
else
{
@@ -124,7 +126,8 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall
{
hasRollCallWorkshopSetting,
hasCameraAccount,
hasRollCallService
hasRollCallService,
hasCustomizeCheckout,
});
}

View File

@@ -230,7 +230,7 @@ namespace ServiceHost.Areas.Client.Pages
if (selectedWorkshop != null)
{
_authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug,selectedWorkshop.WorkshopFullName);
_authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug,selectedWorkshop.WorkshopFullName,selectedWorkshop.Id);
}
return new JsonResult(new
@@ -248,7 +248,7 @@ namespace ServiceHost.Areas.Client.Pages
var workshop = _workshopApplication.SearchForClient(searchModel).FirstOrDefault(x => x.Id == workshopId);
if (workshop != null)
{
_authHelper.UpdateWorkshopSlugClaim(workshop.Slug,workshop.WorkshopFullName);
_authHelper.UpdateWorkshopSlugClaim(workshop.Slug,workshop.WorkshopFullName, workshop.Id);
}
return new JsonResult(new

View File

@@ -141,6 +141,17 @@
} else {
$('#RollCallSubMenu').addClass('disable');
}
const customizeCheckoutIds =[
"customize-checkout-grouping",
"customize-checkout-temporary",
"customize-checkout-unofficial",
];
customizeCheckoutIds.forEach(id => {
$(`#${id}`).toggleClass('disable',!response.hasCustomizeCheckout);
})
});
}

View File

@@ -160,9 +160,9 @@
</span>
</a>
<ul class="submenu">
<li Permission="@SubAccountPermissionHelper.CustomizeCheckoutSetGroupAndSalaryPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/Grouping"><span>گروه‌بندی فیش حقوقی</span></a></li>
<li Permission="@SubAccountPermissionHelper.CustomizeCheckoutTempListPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/CheckoutTemporary"><span>لیست فیش حقوقی موقت</span></a></li>
<li Permission="@SubAccountPermissionHelper.CustomizeCheckoutListPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/CheckoutUnofficial"><span>لیست فیش حقوقی نهایی</span></a></li>
<li id="customize-checkout-grouping" Permission="@SubAccountPermissionHelper.CustomizeCheckoutSetGroupAndSalaryPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/Grouping"><span>گروه‌بندی فیش حقوقی</span></a></li>
<li id="customize-checkout-temporary" Permission="@SubAccountPermissionHelper.CustomizeCheckoutTempListPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/CheckoutTemporary"><span>لیست فیش حقوقی موقت</span></a></li>
<li id="customize-checkout-unofficial" Permission="@SubAccountPermissionHelper.CustomizeCheckoutListPermissionCode"><a class="selectLi" asp-page="/Company/CustomizeCheckout/CheckoutUnofficial"><span>لیست فیش حقوقی نهایی</span></a></li>
</ul>
</li>