| Line 542... |
Line 542... |
| 542 |
boolean isAdmin = roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()));
|
542 |
boolean isAdmin = roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()));
|
| 543 |
AuthUser currentAuthUser = isAdmin ? authRepository.selectByEmailOrMobile(loginDetails.getEmailId()) : null;
|
543 |
AuthUser currentAuthUser = isAdmin ? authRepository.selectByEmailOrMobile(loginDetails.getEmailId()) : null;
|
| 544 |
|
544 |
|
| 545 |
// Check if user is CRM category - CRM users see ALL tickets to handle partner communications
|
545 |
// Check if user is CRM category - CRM users see ALL tickets to handle partner communications
|
| 546 |
boolean isCrmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
546 |
boolean isCrmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| - |
|
547 |
// Check if user is Sales category - Sales users can resolve their own Sales tickets
|
| - |
|
548 |
boolean isSalesUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| - |
|
549 |
// Check if user is RBM category - RBM users can resolve their own RBM tickets
|
| - |
|
550 |
boolean isRbmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| 547 |
|
551 |
|
| 548 |
if (isAdmin) {
|
552 |
if (isAdmin) {
|
| 549 |
int authUserId = currentAuthUser.getId();
|
553 |
int authUserId = currentAuthUser.getId();
|
| 550 |
|
554 |
|
| 551 |
if (isCrmUser) {
|
555 |
if (isCrmUser) {
|
| Line 601... |
Line 605... |
| 601 |
|
605 |
|
| 602 |
model.addAttribute("size", size);
|
606 |
model.addAttribute("size", size);
|
| 603 |
model.addAttribute("roleType", isAdmin);
|
607 |
model.addAttribute("roleType", isAdmin);
|
| 604 |
// isCrmUser already calculated at start of method
|
608 |
// isCrmUser already calculated at start of method
|
| 605 |
model.addAttribute("isCrmUser", isCrmUser);
|
609 |
model.addAttribute("isCrmUser", isCrmUser);
|
| - |
|
610 |
model.addAttribute("isSalesUser", isSalesUser);
|
| - |
|
611 |
model.addAttribute("salesCategoryId", ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| - |
|
612 |
model.addAttribute("isRbmUser", isRbmUser);
|
| - |
|
613 |
model.addAttribute("rbmCategoryId", ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| 606 |
|
614 |
|
| 607 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
615 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
| 608 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
616 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 609 |
if (subCategoryIdAndSubCategoryMap == null) {
|
617 |
if (subCategoryIdAndSubCategoryMap == null) {
|
| 610 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
618 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| Line 1249... |
Line 1257... |
| 1249 |
}
|
1257 |
}
|
| 1250 |
|
1258 |
|
| 1251 |
Activity activity = new Activity();
|
1259 |
Activity activity = new Activity();
|
| 1252 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
1260 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
| 1253 |
if (isAdmin) {
|
1261 |
if (isAdmin) {
|
| 1254 |
// Only CRM team members can mark tickets as resolved
|
1262 |
// CRM team members can resolve any ticket
|
| - |
|
1263 |
// Sales team members can resolve their own Sales category tickets
|
| - |
|
1264 |
// RBM team members can resolve their own RBM category tickets
|
| 1255 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
1265 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 1256 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
1266 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| - |
|
1267 |
boolean isSalesUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| - |
|
1268 |
boolean isRbmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| - |
|
1269 |
|
| 1257 |
if (!isCrmUser) {
|
1270 |
// Check if ticket belongs to Sales or RBM category
|
| - |
|
1271 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
| - |
|
1272 |
boolean isSalesTicket = ticketSubCategory != null && ticketSubCategory.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES;
|
| - |
|
1273 |
boolean isRbmTicket = ticketSubCategory != null && ticketSubCategory.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM;
|
| - |
|
1274 |
|
| - |
|
1275 |
// Allow if CRM user OR (Sales user AND Sales ticket) OR (RBM user AND RBM ticket)
|
| - |
|
1276 |
if (!isCrmUser && !(isSalesUser && isSalesTicket) && !(isRbmUser && isRbmTicket)) {
|
| 1258 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only CRM team members can mark tickets as resolved");
|
1277 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only CRM, Sales (for Sales tickets), or RBM (for RBM tickets) team can mark tickets as resolved");
|
| 1259 |
}
|
1278 |
}
|
| 1260 |
ticket.setLastActivity(lastActivity);
|
1279 |
ticket.setLastActivity(lastActivity);
|
| 1261 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
1280 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
| 1262 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
1281 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
| 1263 |
activity.setMessage(message);
|
1282 |
activity.setMessage(message);
|