From 5573469ce72f87961a8d3098a028e6118d92c498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20Istv=C3=A1n?= Date: Wed, 2 Oct 2024 15:39:49 +0200 Subject: [PATCH] Remove submit diff --- .../sch/cmsch/component/app/DebugComponent.kt | 48 ------------------- .../component/app/DebugComponentController.kt | 30 ------------ .../sch/cmsch/component/form/FormService.kt | 5 +- .../cmsch/component/task/TaskApiController.kt | 6 +-- .../sch/cmsch/component/task/TasksService.kt | 6 +-- .../sch/cmsch/component/team/TeamService.kt | 2 +- .../hu/bme/sch/cmsch/service/TimeService.kt | 21 ++------ 7 files changed, 11 insertions(+), 107 deletions(-) delete mode 100644 backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponent.kt delete mode 100644 backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponentController.kt diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponent.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponent.kt deleted file mode 100644 index f57089f8c..000000000 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponent.kt +++ /dev/null @@ -1,48 +0,0 @@ -package hu.bme.sch.cmsch.component.app - -import hu.bme.sch.cmsch.component.* -import hu.bme.sch.cmsch.model.RoleType -import hu.bme.sch.cmsch.service.ControlPermissions -import org.springframework.core.env.Environment -import org.springframework.stereotype.Service - -@Service -class DebugComponent( - componentSettingService: ComponentSettingService, - env: Environment -) : ComponentBase( - "debug", - "/", - "Fejlesztő beállítások", - ControlPermissions.PERMISSION_DEV_DEBUG, - listOf(), - componentSettingService, env -) { - - final override val allSettings by lazy { - listOf( - debugGroup, - submitDiff - ) - } - - final override val menuDisplayName = null - - final override val minRole = MinRoleSettingProxy(componentSettingService, component, - "minRole", MinRoleSettingProxy.ALL_ROLES, minRoleToEdit = RoleType.NOBODY, - fieldName = "Jogosultságok", description = "Melyik roleokkal nyitható meg az oldal" - ) - - /// ------------------------------------------------------------------------------------------------------------------- - - val debugGroup = SettingProxy(componentSettingService, component, - "debugGroup", "", type = SettingType.COMPONENT_GROUP, persist = false, - fieldName = "DEBUG", description = "Ehhez csak akkor nyúlj, ha tudod mit csinálsz!" - ) - - val submitDiff = SettingProxy(componentSettingService, component, - "submitDiff", "-7200", type = SettingType.NUMBER, - fieldName = "Task beadás diff", serverSideOnly = true - ) - -} \ No newline at end of file diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponentController.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponentController.kt deleted file mode 100644 index 35977ba28..000000000 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/DebugComponentController.kt +++ /dev/null @@ -1,30 +0,0 @@ -package hu.bme.sch.cmsch.component.app - -import hu.bme.sch.cmsch.component.ComponentApiBase -import hu.bme.sch.cmsch.service.AdminMenuService -import hu.bme.sch.cmsch.service.AuditLogService -import hu.bme.sch.cmsch.service.ControlPermissions -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean -import org.springframework.stereotype.Controller -import org.springframework.web.bind.annotation.RequestMapping - -@Controller -@RequestMapping("/admin/control/component/debug") -@ConditionalOnBean(ApplicationComponent::class) -class DebugComponentController( - adminMenuService: AdminMenuService, - component: DebugComponent, - menuService: MenuService, - auditLogService: AuditLogService -) : ComponentApiBase( - adminMenuService, - FooterComponent::class.java, - component, - ControlPermissions.PERMISSION_DEV_DEBUG, - componentMenuName = "Fejlesztő beállítások", - componentMenuIcon = "code_blocks", - menuService = menuService, - insertComponentCategory = false, - componentCategory = ApplicationComponent.DEVELOPER_CATEGORY, - auditLogService = auditLogService -) \ No newline at end of file diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/form/FormService.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/form/FormService.kt index e3895b0a4..ac529bab5 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/form/FormService.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/form/FormService.kt @@ -1,9 +1,7 @@ package hu.bme.sch.cmsch.component.form import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import hu.bme.sch.cmsch.component.app.DebugComponent import hu.bme.sch.cmsch.component.login.CmschUser import hu.bme.sch.cmsch.extending.FormSubmissionListener import hu.bme.sch.cmsch.model.RoleType @@ -26,7 +24,6 @@ open class FormService( private val responseRepository: ResponseRepository, private val userRepository: UserRepository, private val clock: TimeService, - private val debugComponent: DebugComponent, private val listeners: MutableList, private val formComponent: FormComponent, ) { @@ -62,7 +59,7 @@ open class FormService( if ((form.minRole.value > user.role.value || form.maxRole.value < user.role.value) && !user.role.isAdmin) return FormView(status = FormStatus.NOT_FOUND) - val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) + val now = clock.getTimeInSeconds() if (!form.open) return FormView(status = FormStatus.NOT_ENABLED) if (form.availableFrom > now) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskApiController.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskApiController.kt index 7aefff917..ed2bf715b 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskApiController.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskApiController.kt @@ -37,16 +37,16 @@ class TaskApiController( when (startupPropertyConfig.taskOwnershipMode) { OwnershipType.USER -> { user ?: return TasksView() - categories = tasks.getCategoriesForUserInTimeRange(user.id, clock.getNowInSeconds(), user.role) + categories = tasks.getCategoriesForUserInTimeRange(user.id, clock.getTimeInSeconds(), user.role) return TasksView( categories = categories - .filter { clock.inRange(it.availableFrom, it.availableTo, clock.getNowInSeconds()) }, + .filter { clock.inRange(it.availableFrom, it.availableTo, clock.getTimeInSeconds()) }, ) } OwnershipType.GROUP -> { val groupId = user?.groupId ?: return TasksView( ) - categories = tasks.getCategoriesForGroupInRange(groupId, clock.getNowInSeconds(), userRole = user.role) + categories = tasks.getCategoriesForGroupInRange(groupId, clock.getTimeInSeconds(), userRole = user.role) return TasksView( categories = categories diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TasksService.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TasksService.kt index 014016d5d..fc0304bdb 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TasksService.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TasksService.kt @@ -1,6 +1,5 @@ package hu.bme.sch.cmsch.component.task -import hu.bme.sch.cmsch.component.app.DebugComponent import hu.bme.sch.cmsch.component.login.CmschUser import hu.bme.sch.cmsch.extending.TaskSubmissionListener import hu.bme.sch.cmsch.model.RoleType @@ -29,7 +28,6 @@ open class TasksService( private val categories: TaskCategoryRepository, private val clock: TimeService, private val taskComponent: TaskComponent, - private val debugComponent: DebugComponent, private val listeners: List, private val userRepository: UserRepository, private val groupRepository: GroupRepository @@ -191,7 +189,7 @@ open class TasksService( val task = taskRepository.findById(answer.taskId).orElse(null) ?: return TaskSubmissionStatus.INVALID_TASK_ID - val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) + val now = clock.getTimeInSeconds() if (task.availableFrom > now || task.availableTo < now) { return TaskSubmissionStatus.TOO_EARLY_OR_LATE } @@ -219,7 +217,7 @@ open class TasksService( val task = taskRepository.findById(answer.taskId).orElse(null) ?: return TaskSubmissionStatus.INVALID_TASK_ID - val now = clock.getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) + val now = clock.getTimeInSeconds() if (task.availableFrom > now || task.availableTo < now) { return TaskSubmissionStatus.TOO_EARLY_OR_LATE } diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/team/TeamService.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/team/TeamService.kt index 7b32e0f2d..981f4de4e 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/team/TeamService.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/team/TeamService.kt @@ -280,7 +280,7 @@ open class TeamService( private fun mapTasks(team: GroupEntity, user: CmschUser): List { return tasksService.map { tasks -> - tasks.getCategoriesForGroupInRange(team.id, clock.getNowInSeconds(), advertisedOnly = true, user.role) + tasks.getCategoriesForGroupInRange(team.id, clock.getTimeInSeconds(), advertisedOnly = true, user.role) .map { TaskCategoryPreview( name = it.name, completed = it.approved, diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/service/TimeService.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/service/TimeService.kt index 4ee4a2f48..ae59b2293 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/service/TimeService.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/service/TimeService.kt @@ -1,6 +1,5 @@ package hu.bme.sch.cmsch.service -import hu.bme.sch.cmsch.component.app.DebugComponent import hu.bme.sch.cmsch.config.StartupPropertyConfig import org.springframework.stereotype.Service import java.time.ZoneId @@ -9,10 +8,7 @@ import java.time.format.DateTimeFormatter import java.util.* @Service -class TimeService( - startupPropertyConfig: StartupPropertyConfig, - private val debugComponent: DebugComponent -) { +class TimeService(startupPropertyConfig: StartupPropertyConfig) { val timeZone: ZoneId = Objects.requireNonNull(ZoneId.of(startupPropertyConfig.zoneId), "Invalid time zone") private val sqlDateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") @@ -21,19 +17,10 @@ class TimeService( fun getTime() = ZonedDateTime.now(timeZone)?.toInstant()?.toEpochMilli() ?: 0 - fun inRange(availableFrom: Long, availableTo: Long, timeInSeconds: Long): Boolean { - val now = timeInSeconds + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) - return now in availableFrom..availableTo - } + fun inRange(availableFrom: Long, availableTo: Long, timeInSeconds: Long): Boolean = + timeInSeconds in availableFrom..availableTo - fun isTimePassed(timeToBeAfter: Long, timeInSeconds: Long): Boolean { - val now = timeInSeconds + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) - return now > timeToBeAfter - } - - fun getNowInSeconds(): Long { - return getTimeInSeconds() + (debugComponent.submitDiff.getValue().toLongOrNull() ?: 0) - } + fun isTimePassed(timeToBeAfter: Long, timeInSeconds: Long): Boolean = timeInSeconds > timeToBeAfter fun todayInSqlFormat(): String = ZonedDateTime.now(timeZone).format(sqlDateFormatter)