Skip to content

Commit

Permalink
Merge pull request #94 from SageSeekerSociety/dev
Browse files Browse the repository at this point in the history
Release: 0.7.0
  • Loading branch information
Nictheboy authored Nov 3, 2024
2 parents 5ddca7a + fd851b7 commit e3fe347
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 168 deletions.
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ updates:
- package-ecosystem: 'maven'
directory: '/'
schedule:
interval: 'monthly'
interval: 'daily'

- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'monthly'
interval: 'daily'

- package-ecosystem: 'docker'
directory: '/'
schedule:
interval: 'monthly'
interval: 'daily'

- package-ecosystem: 'devcontainers'
directory: '/'
schedule:
interval: 'monthly'
interval: 'daily'
7 changes: 3 additions & 4 deletions design/API/NT-API.yml
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ paths:
rank:
type: integer
approved:
type: boolean
$ref: '#/components/schemas/ApproveType'
rejectReason:
type: string
summary: Update Task
Expand Down Expand Up @@ -686,7 +686,7 @@ paths:
name: team
description: Team ID
- schema:
type: boolean
$ref: '#/components/schemas/ApproveType'
in: query
name: approved
description: Distinguish task status
Expand Down Expand Up @@ -794,7 +794,6 @@ paths:
deadline:
type: integer
format: int64
default: null
defaultDeadline:
type: integer
format: int64
Expand Down Expand Up @@ -2139,7 +2138,7 @@ components:
rank:
type: integer
approved:
type: boolean
$ref: '#/components/schemas/ApproveType'
rejectReason:
type: string
TaskSubmitterType:
Expand Down
6 changes: 4 additions & 2 deletions design/DB/CREATE.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ CREATE
CREATE
TABLE
task(
approved BOOLEAN NOT NULL,
approved SMALLINT NOT NULL CHECK(
approved BETWEEN 0 AND 2
),
"creator_id" INTEGER NOT NULL,
editable BOOLEAN NOT NULL,
RANK INTEGER,
Expand All @@ -181,7 +183,7 @@ CREATE
description TEXT NOT NULL,
intro VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
reject_reason VARCHAR(255),
reject_reason VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
);

Expand Down
34 changes: 34 additions & 0 deletions design/DB/MIGRATION/MIGRATE_TO_0_7_0_FROM_0_6_0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- PostgreSQL Migration Script for Cheese Backend NT (0.6.0 -> 0.7.0)
-- Backup Before Executing This in Production Database

ALTER TABLE task
ALTER COLUMN approved SET DATA TYPE SMALLINT USING
CASE
WHEN approved = TRUE THEN 0
WHEN approved = FALSE THEN 1
END;

ALTER TABLE task
ALTER COLUMN approved SET NOT NULL;

ALTER TABLE task
ADD CONSTRAINT approved_check CHECK (approved BETWEEN 0 AND 2);

UPDATE task
SET reject_reason = ''
WHERE reject_reason IS NULL;

ALTER TABLE task
ALTER COLUMN reject_reason SET NOT NULL;

UPDATE task
SET approved =
CASE
WHEN approved = 0 THEN 0
WHEN approved = 1 AND reject_reason != '' THEN 1
ELSE 2
END;




15 changes: 15 additions & 0 deletions design/DB/PATCH/PATCH_0_5_0_ANNOUNCEMENT_AND_TEMPLATE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- PostgreSQL Patch Script for Cheese Backend NT (0.5.0)
-- Backup Before Executing This in Production Database

-- Description:
-- Replace all invalid announcements and templates with "[]"

-- This script can be executed several times safely without any side effects.

UPDATE SPACE
SET announcements = '[]'
WHERE announcements NOT LIKE '[%]';

UPDATE SPACE
SET task_templates = '[]'
WHERE task_templates NOT LIKE '[%]';
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<version>3.3.5</version>
<relativePath/>
</parent>

<!-- Project Info -->
<groupId>org.rucca</groupId>
<artifactId>cheese</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
<name>backend</name>
<description>Backend for Cheese Web Application</description>
<url/>
Expand All @@ -31,7 +31,7 @@
</scm>
<properties>
<java.version>21</java.version>
<kotlin.version>2.0.20</kotlin.version>
<kotlin.version>2.0.21</kotlin.version>
</properties>

<!-- Project Dependencies -->
Expand Down Expand Up @@ -136,23 +136,23 @@
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.parboiled</groupId>
Expand Down Expand Up @@ -194,14 +194,14 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>2.0.20</version>
<version>2.0.21</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.8.0</version>
<version>7.9.0</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -287,7 +287,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<configuration>
<systemPropertyVariables>
<spring.jpa.hibernate.ddl-auto>update</spring.jpa.hibernate.ddl-auto>
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/rucca/cheese/api/SpacesApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.9.0).
* https://openapi-generator.tech Do not edit the class manually.
*/
package org.rucca.cheese.api
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/org/rucca/cheese/api/TasksApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.9.0).
* https://openapi-generator.tech Do not edit the class manually.
*/
package org.rucca.cheese.api
Expand Down Expand Up @@ -331,10 +331,13 @@ interface TasksApi {
@Valid
@RequestParam(value = "team", required = false)
team: kotlin.Int?,
@Parameter(description = "Distinguish task status")
@Parameter(
description = "Distinguish task status",
schema = Schema(allowableValues = ["APPROVED", "DISAPPROVED", "NONE"])
)
@Valid
@RequestParam(value = "approved", required = false)
approved: kotlin.Boolean?,
approved: ApproveTypeDTO?,
@Parameter(description = "Owner's User ID")
@Valid
@RequestParam(value = "owner", required = false)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/rucca/cheese/api/TeamsApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0).
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.9.0).
* https://openapi-generator.tech Do not edit the class manually.
*/
package org.rucca.cheese.api
Expand Down
22 changes: 19 additions & 3 deletions src/main/kotlin/org/rucca/cheese/auth/CustomAuthLogics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,20 @@ class CustomAuthLogics {
customLogicData: Any?,
): Boolean {
val handler = logics[name] ?: throw RuntimeException("Custom auth logic '$name' not found.")
return handler(
val result =
handler(
userId,
action,
resourceType,
resourceId,
authInfo,
resourceOwnerIdGetter,
customLogicData
)
logger.debug(
"Invoked custom auth logic '{}'. Result: {}, userId: {}, action: {}, resourceType: {}, resourceId: {}, authInfo: {}, resourceOwnerIdGetter: {}, customLogicData: {}",
name,
result,
userId,
action,
resourceType,
Expand All @@ -55,6 +68,7 @@ class CustomAuthLogics {
resourceOwnerIdGetter,
customLogicData
)
return result
}

fun evaluate(
Expand All @@ -80,8 +94,10 @@ class CustomAuthLogics {
root = result.parseTreeRoot.getValue()
}
if (root !is CustomAuthLogicsVariableNode)
logger.info(
"Parsed complex custom auth logic expression. Original: '$expression', parsed: $root"
logger.debug(
"Parsed complex custom auth logic expression. Original: '{}', parsed: {}",
expression,
root
)
fun evaluator(node: CustomAuthLogicsExpressionNode): Boolean {
return when (node) {
Expand Down
23 changes: 0 additions & 23 deletions src/main/kotlin/org/rucca/cheese/common/Utils.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.rucca.cheese.common.error
import org.slf4j.LoggerFactory
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.converter.HttpMessageConversionException
import org.springframework.web.bind.MissingServletRequestParameterException
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
Expand Down Expand Up @@ -36,6 +37,17 @@ class GlobalErrorHandler {
.body(BadRequestError(e.message ?: "Method argument type mismatch"))
}

@ExceptionHandler(HttpMessageConversionException::class)
@ResponseBody
fun handleHttpMessageConversionException(
e: HttpMessageConversionException
): ResponseEntity<BaseError> {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(
BadRequestError(e.message ?: "Invalid request caused http message conversion error")
)
}

@ExceptionHandler(Exception::class)
@ResponseBody
fun handleException(e: Exception): ResponseEntity<BaseError> {
Expand Down
35 changes: 35 additions & 0 deletions src/main/kotlin/org/rucca/cheese/common/persistent/ApproveType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.rucca.cheese.common.persistent

import org.rucca.cheese.model.ApproveTypeDTO

/*
*
* Do not delete any row of this enum,
* because it is stored in database as an integer.
*
* If you want to add a new row, add it to the end of the enum.
* This will prevent changing the values of the existing rows.
*
*/

enum class ApproveType {
APPROVED,
DISAPPROVED,
NONE,
}

fun ApproveType.convert(): ApproveTypeDTO {
return when (this) {
ApproveType.APPROVED -> ApproveTypeDTO.APPROVED
ApproveType.DISAPPROVED -> ApproveTypeDTO.DISAPPROVED
ApproveType.NONE -> ApproveTypeDTO.NONE
}
}

fun ApproveTypeDTO.convert(): ApproveType {
return when (this) {
ApproveTypeDTO.APPROVED -> ApproveType.APPROVED
ApproveTypeDTO.DISAPPROVED -> ApproveType.DISAPPROVED
ApproveTypeDTO.NONE -> ApproveType.NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ data class PatchTaskRequestDTO(
@Schema(example = "null", description = "")
@get:JsonProperty("rank")
val rank: kotlin.Int? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("approved")
val approved: kotlin.Boolean? = null,
val approved: ApproveTypeDTO? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("rejectReason")
val rejectReason: kotlin.String? = null
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/rucca/cheese/model/TaskDTO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ data class TaskDTO(
@Schema(example = "null", description = "")
@get:JsonProperty("rank")
val rank: kotlin.Int? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("approved")
val approved: kotlin.Boolean? = null,
val approved: ApproveTypeDTO? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("rejectReason")
val rejectReason: kotlin.String? = null
Expand Down
Loading

0 comments on commit e3fe347

Please sign in to comment.