Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zitrone44 committed Oct 29, 2024
2 parents ff2df6f + 591df37 commit 1ecacbc
Show file tree
Hide file tree
Showing 50 changed files with 2,110 additions and 472 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build Docker images
run: docker-compose build
run: docker compose build
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ services:
context: modules/fbs-eat/eat
restart: always
ports:
- 5000:8050
- 5001:8050
networks:
- fbs
environment:
Expand Down
7 changes: 4 additions & 3 deletions modules/fbs-core/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:jdk18 AS BUILD
FROM gradle:jdk18 AS build

RUN mkdir /build
WORKDIR /build
Expand All @@ -14,6 +14,7 @@ COPY modules/fbs-runner/checker/*.gradle /build/modules/fbs-runner/checker/

# Build web
COPY modules/fbs-core/web /build/modules/fbs-core/web/
RUN apt-get update && apt-get install -y build-essential curl
RUN gradle fbs-core.web:installDist

# Copy math-parser
Expand All @@ -23,9 +24,9 @@ COPY modules/fbs-core/math-parser /build/modules/fbs-core/math-parser/
COPY modules/fbs-core/api /build/modules/fbs-core/api/
RUN gradle fbs-core.web:copyWebToWS fbs-core.api:installDist

FROM eclipse-temurin:18.0.2_9-jre-alpine
FROM eclipse-temurin:18-jre

RUN apk add --no-cache curl
RUN apt-get update && apt-get install -y curl

COPY --from=build /build/modules/fbs-core/api/build/install/fbs-core.api /usr/local/fbs-core.api

Expand Down
2 changes: 1 addition & 1 deletion modules/fbs-core/api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ compile:
jwt:
secret: ${JWT_SECRET:8Dsupersecurekeydf0}
expiration:
time: 300
time: 43200
ldap:
enabled: ${LDAP_ENABLED:false}
allowLogin: ${LDAP_ALLOW_LOGIN:false}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

alter table `fbs`.`course`
ADD `group_selection` BOOLEAN NULL DEFAULT NULL;

INSERT INTO migration (number) VALUES (22);

COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,31 @@ class CourseController {
case _ => throw new ForbiddenException()
}
}

/**
* Update only the group selection of a course
*
* @param cid Course id
* @param req http request
* @param res http response
* @param body Request Body
*/
@PutMapping(value = Array("/{cid}/groupSelection"))
def updateGroupSelection(@PathVariable("cid") cid: Integer, req: HttpServletRequest, res: HttpServletResponse,
@RequestBody body: JsonNode): Unit = {
val user = authService.authorize(req, res)
val someCourseRole = courseRegistrationService.getParticipants(cid).find(_.user.id == user.id).map(_.role)

(user.globalRole, someCourseRole) match {
case (GlobalRole.ADMIN | GlobalRole.MODERATOR, _) | (_, Some(CourseRole.DOCENT)) =>
(
body.retrive("groupSelection").asBool(),
) match {
case (Some(groupSelection)) =>
courseService.updateGroupSelection(cid, groupSelection)
case _ => throw new BadRequestException("Malformed Request Body")
}
case _ => throw new ForbiddenException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.thm.ii.fbs.services.security.AuthService

import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.http.{MediaType, ResponseEntity}
import org.springframework.web.bind.annotation._

/**
Expand Down Expand Up @@ -142,4 +142,17 @@ class GroupRegistrationController {
throw new ForbiddenException()
}
}

/**
* Get current number of members of a group
*
* @param cid Course id
* @param gid Group id
* @return Number of members
*/
@GetMapping(Array("/courses/{cid}/groups/{gid}/membership"))
def getGroupMembership(@PathVariable("cid") cid: Integer, @PathVariable("gid") gid: Int): ResponseEntity[Int] = {
val membership = groupRegistrationService.getGroupMembership(cid, gid)
ResponseEntity.ok(membership)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HomeController {
* Forward every access that is not defined to the index page.
* @return Forward undefined access to index.
*/
@RequestMapping(value = Array("/courses", "/sqlplayground", "/analytics", "/modelling")) // TODO: Remove as soon as possible
@RequestMapping(value = Array("/courses", "/sqlplayground", "/analytics", "/modelling", "/kanban")) // TODO: Remove as soon as possible
def redirectRoot: String = "forward:/"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ package de.thm.ii.fbs.model
* @param description The description of this course
* @param visible The visibility of the course, false = invisible
* @param id The id of the course, if 0, then none was assigned.
* @param groupSelection Whether registration for groups is possible
*/
case class Course(name: String, description: String = "", visible: Boolean = true, id: Int = 0, semesterId: Option[Int] = None)
case class Course(name: String, description: String = "", visible: Boolean = true, id: Int = 0, semesterId: Option[Int] = None,
groupSelection: Option[Boolean] = None)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CourseService {
* @return List of courses
*/
def getAll(ignoreHidden: Boolean = true): List[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course" + (if (ignoreHidden) " WHERE visible = 1" else ""),
"SELECT course_id, group_selection, semester_id, name, description, visible FROM course" + (if (ignoreHidden) " WHERE visible = 1" else ""),
(res, _) => parseResult(res))

/**
Expand All @@ -35,7 +35,7 @@ class CourseService {
* @return List of courses
*/
def findByPattern(pattern: String, ignoreHidden: Boolean = true): List[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course WHERE name like ?" + (if (ignoreHidden) " AND visible = 1" else ""),
"SELECT course_id, group_selection, semester_id, name, description, visible FROM course WHERE name like ?" + (if (ignoreHidden) " AND visible = 1" else ""),
(res, _) => parseResult(res), "%" + pattern + "%")

/**
Expand All @@ -45,7 +45,7 @@ class CourseService {
* @return The found course
*/
def find(id: Int): Option[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course WHERE course_id = ?",
"SELECT course_id, group_selection, semester_id, name, description, visible, group_selection FROM course WHERE course_id = ?",
(res, _) => parseResult(res), id).headOption

/**
Expand Down Expand Up @@ -86,6 +86,7 @@ class CourseService {

private def parseResult(res: ResultSet): Course = Course(
semesterId = maybeInt(res, "semester_id"),
groupSelection = maybeBoolean(res, "group_selection"),
name = res.getString("name"),
description = res.getString("description"),
visible = res.getBoolean("visible"),
Expand All @@ -100,4 +101,25 @@ class CourseService {
Some(tmp)
}
}

private def maybeBoolean(res: ResultSet, columnName: String): Option[Boolean] = {
val tmp = res.getBoolean(columnName)
if (res.wasNull()) {
null
} else {
Some(tmp)
}
}

/**
* Update only the group selection of a course
*
* @param cid The course id
* @param groupSelection The new group selection status
* @return True if successful
*/
def updateGroupSelection(cid: Int, groupSelection: Boolean): Boolean = {
1 == DB.update("UPDATE course SET group_selection = ? WHERE course_id = ?",
groupSelection, cid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ mulFactor : expo // higher presedence!
| mulFactor ' '* expo
;

expo : expo ' '* EXP ' '* SUB? factor
expo : expo ' '* EXP ' '* SUB? factor
| expo unicode_expo
| factor
;

factor : LEFT? OPENING_ROUND_BRACKET ' '* expr ' '* RIGHT? CLOSING_ROUND_BRACKET
| OPENING_CURLY_BRACKET ' '* expr ' '* CLOSING_CURLY_BRACKET
| EMPTY_CURLY_BRACKETS
| (NUMBER|VAR)
;

Expand Down Expand Up @@ -63,6 +64,7 @@ OPENING_ROUND_BRACKET: '(';
CLOSING_ROUND_BRACKET: ')';
OPENING_CURLY_BRACKET: '{';
CLOSING_CURLY_BRACKET: '}';
EMPTY_CURLY_BRACKETS: '{}';
OPENING_SQUARE_BRACKET: '[';
CLOSING_SQUARE_BRACKET: ']';
LEFT: '\\left';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class AstBuilder(val eq: MathParser.EqContext) {
factor.expr() !== null -> buildExpr(factor.expr())
factor.NUMBER() !== null -> Num(germanFormat.parse(factor.NUMBER().text.replace("{,}", ",")))
factor.VAR() !== null -> Var(factor.VAR().text)
factor.EMPTY_CURLY_BRACKETS() !== null -> Num(1)
else -> throw IllegalArgumentException("not a legal factor: ${factor.text}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,16 @@ internal class MathParserHelperTest {
)
}

@Test
fun parseEmptyExp() {
assertEquals(
Ast(
Operation(Operator.ADD, Operation(Operator.EXP, Num(2), Num(1)), Operation(Operator.EXP, Num(2), Num(1)))
),
MathParserHelper.parse("2^{}+2^{}")
)
}

@Test
fun parseLatexRad() {
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,14 @@ internal class SemanticAstComparatorTest {
)
)
}

@Test
fun emptyExponentTest() {
assertTrue(
semanticAstComparator.compare(
MathParserHelper.parse("a^{}"),
MathParserHelper.parse("a")
)
)
}
}
Loading

0 comments on commit 1ecacbc

Please sign in to comment.