Ver a proveniência

1. add authority for normal staff to view/edit timesheet amendment

pull/3/head
cyril.tsui há 6 meses
ascendente
cometimento
c8ad56f707
3 ficheiros alterados com 37 adições e 27 eliminações
  1. +9
    -3
      src/main/java/com/ffii/tsms/modules/timesheet/service/LeaveService.kt
  2. +23
    -24
      src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt
  3. +5
    -0
      src/main/resources/db/changelog/changes/20250218_01_cyril/01_add_authority.sql

+ 9
- 3
src/main/java/com/ffii/tsms/modules/timesheet/service/LeaveService.kt Ver ficheiro

@@ -101,18 +101,24 @@ open class LeaveService(

open fun getTeamMemberLeave(): Map<Long, TeamMemberLeaveEntries> {
val authorities = staffsService.currentAuthorities() ?: return emptyMap()
if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
val authMaintainTimesheet = authorities.any { it.authority.equals("MAINTAIN_TIMESHEET") }
val authMaintainTimesheetSelf = authorities.any { it.authority.equals("MAINTAIN_TIMESHEET_SELF") }

// if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
if (authMaintainTimesheet || authMaintainTimesheetSelf) {
val currentStaff = staffsService.currentStaff()

// Get team where current staff is team lead
val myTeam = if (currentStaff != null) teamService.getMyTeamForStaff(currentStaff) else null
val teamMembers = if (myTeam != null) {
val teamMembers = if (myTeam != null && authMaintainTimesheet) {
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList())
} else if (authMaintainTimesheetSelf) {
staffsService.findAllByIdIn(listOf(currentStaff?.id!!)).getOrDefault(emptyList())
} else {
staffsService.findAll().getOrDefault(emptyList())
}

return teamMembers.filter { it.departDate == null }.associate { member ->
return teamMembers.filter { it.departDate == null || it.departDate > LocalDate.now() }.sortedBy { it.staffId }.associate { member ->
Pair(
member.id!!,
TeamMemberLeaveEntries(


+ 23
- 24
src/main/java/com/ffii/tsms/modules/timesheet/service/TimesheetsService.kt Ver ficheiro

@@ -129,33 +129,32 @@ open class TimesheetsService(

open fun getTeamMemberTimesheet(): Map<Long, TeamMemberTimeEntries> {
val authorities = staffsService.currentAuthorities() ?: return emptyMap()

if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
val authMaintainTimesheet = authorities.any { it.authority.equals("MAINTAIN_TIMESHEET") }
val authMaintainTimesheetSelf = authorities.any { it.authority.equals("MAINTAIN_TIMESHEET_SELF") }
// if (authorities.stream().anyMatch { it.authority.equals("MAINTAIN_TIMESHEET") }) {
if (authMaintainTimesheet || authMaintainTimesheetSelf) {
val currentStaff = staffsService.currentStaff()
if (currentStaff != null) {
val isTeamLead = currentStaff.team.staff.id?.equals(currentStaff.id)
// Get team where current staff is team lead

val myTeam = teamService.getMyTeamForStaff(currentStaff)
val teamMembers = if (myTeam != null && isTeamLead == true) {
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList())
} else if (isTeamLead != true) {
staffsService.findAllByIdIn(listOf(currentStaff.id!!)).getOrDefault(emptyList())
} else {
staffsService.findAll().getOrDefault(emptyList())
}

return teamMembers.filter { it.departDate == null || it.departDate > LocalDate.now() }.sortedBy { it.staffId }.associate { member ->
Pair(
member.id!!,
TeamMemberTimeEntries(
staffId = member.staffId,
name = member.name,
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)),
employType = member.employType
)
// Get team where current staff is team lead
val myTeam = if (currentStaff != null) teamService.getMyTeamForStaff(currentStaff) else null
val teamMembers = if (myTeam != null && authMaintainTimesheet) {
staffsService.findAllByTeamId(myTeam.id!!).getOrDefault(emptyList())
} else if (authMaintainTimesheetSelf) {
staffsService.findAllByIdIn(listOf(currentStaff?.id!!)).getOrDefault(emptyList())
} else {
staffsService.findAll().getOrDefault(emptyList())
}

return teamMembers.filter { it.departDate == null || it.departDate > LocalDate.now() }.sortedBy { it.staffId }.associate { member ->
Pair(
member.id!!,
TeamMemberTimeEntries(
staffId = member.staffId,
name = member.name,
timeEntries = transformToTimeEntryMap(timesheetRepository.findAllByStaff(member)),
employType = member.employType
)
}
)
}
}



+ 5
- 0
src/main/resources/db/changelog/changes/20250218_01_cyril/01_add_authority.sql Ver ficheiro

@@ -0,0 +1,5 @@
-- liquibase formatted sql
-- changeset cyril:add_authority

INSERT INTO `authority` (`authority`, `name`) VALUES
('MAINTAIN_TIMESHEET_SELF', 'Maintain Self Timesheet');

Carregando…
Cancelar
Guardar