Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cn.edu.buaa.scs.controller.models
* @param departmentId 所在单位
* @param role 1 for student, 2 for teacher, 4 for admin
* @param name 姓名
* @param email 邮箱
*/
data class CreateUserRequest(
/* 学工号 */
Expand All @@ -27,6 +28,8 @@ data class CreateUserRequest(
/* 1 for student, 2 for teacher, 4 for admin */
val role: kotlin.Int,
/* 姓名 */
val name: kotlin.String? = null
val name: kotlin.String? = null,
/* 邮箱 */
val email: kotlin.String? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package cn.edu.buaa.scs.controller.models
* @param name
* @param email
* @param nickname
* @param departmentId
*/
data class PatchUserRequest(
val name: kotlin.String? = null,
val email: kotlin.String? = null,
val nickname: kotlin.String? = null
val nickname: kotlin.String? = null,
val departmentId: kotlin.Int? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class VirtualMachineReconciler(val client: KubernetesClient) : Reconciler<Virtua
if (createVmProcessMutex.tryLock(vm)) {
try {
vmClient.createVM(vm.spec.toCreateVmOptions()).getOrThrow()
} catch (e: Throwable) {
null
} finally {
createVmProcessMutex.unlock(vm)
}
Expand Down
3 changes: 2 additions & 1 deletion cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Admin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ fun Route.adminRoute() {
val req = call.receive<CreateUserRequest>()
val role = UserRole.fromLevel(req.role)
val name = req.name
val email = req.email
val departmentId = req.departmentId
call.respond(convertUserModel(call.admin.addUser(req.id, name, role, departmentId)))
call.respond(convertUserModel(call.admin.addUser(req.id, name, role, email, departmentId)))
}

delete {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ fun Route.experimentRoute() {
call.respond(call.convertExperimentResponse(experiment))
}

delete {
val experimentId = call.getExpIdFromPath()
call.experiment.deleteById(experimentId)
call.respond("OK")
}

route("/assignments") {
get {
call.respond(
Expand Down
4 changes: 2 additions & 2 deletions cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ val ApplicationCall.admin: AdminService
class AdminService(val call: ApplicationCall) : IService {
companion object : IService.Caller<AdminService>()

fun addUser(id: String, name: String?, role: UserRole, departmentId: Int): User {
fun addUser(id: String, name: String?, role: UserRole, email: String?, departmentId: Int): User {
if (!call.user().isAdmin()) {
throw AuthorizationException("only admin can add user")
}

return User.createNewUnActiveUser(id, name, role, departmentId)
return User.createNewUnActiveUser(id, name, role, email, departmentId)
}

fun deleteUsers(userIds: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class CourseService(val call: ApplicationCall) : IService {
// make sure students exist
studentIdList.forEachAsync { studentId ->
if (!mysql.users.exists { it.id.inList(studentId.lowerUpperNormal()) }) {
User.createNewUnActiveUser(studentId, null, UserRole.STUDENT, 0)
User.createNewUnActiveUser(studentId, null, UserRole.STUDENT, "", 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class ExperimentService(val call: ApplicationCall) : IService, FileService.FileD
return experiment
}

fun deleteById(expId: Int) {
mysql.delete(Experiments) { it.id eq expId }
}

private fun patchExperimentPeerInfo(
experiment: Experiment,
peerDescription: String?,
Expand Down
6 changes: 5 additions & 1 deletion cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ fun User.Companion.getUerListByIdList(idList: List<String>): List<User> {
else mysql.users.filter { it.id.inList(idList) }.toList()
}

fun User.Companion.createNewUnActiveUser(id: String, name: String?, role: UserRole, departmentId: Int): User {
fun User.Companion.createNewUnActiveUser(id: String, name: String?, role: UserRole, email: String?, departmentId: Int): User {
val user = User {
this.id = id
this.name = name ?: "未激活用户"
this.role = role
this.email = email ?: ""
this.departmentId = departmentId
}
mysql.users.add(user)
Expand Down Expand Up @@ -102,6 +103,9 @@ class UserService(val call: ApplicationCall) : IService {
if (req.nickname != null) {
user.nickName = req.nickname
}
if (req.departmentId != null) {
user.departmentId = req.departmentId
}

user.flushChanges()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import cn.edu.buaa.scs.config.globalConfig
import cn.edu.buaa.scs.error.NotFoundException
import cn.edu.buaa.scs.model.Host
import cn.edu.buaa.scs.model.VirtualMachine
import cn.edu.buaa.scs.model.virtualMachines
import cn.edu.buaa.scs.storage.mysql
import cn.edu.buaa.scs.utils.HttpClientWrapper
import cn.edu.buaa.scs.utils.schedule.waitForDone
import cn.edu.buaa.scs.vm.*
Expand All @@ -14,6 +16,9 @@ import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.jackson.*
import org.ktorm.dsl.and
import org.ktorm.dsl.eq
import org.ktorm.entity.find
import org.ktorm.jackson.KtormModule

object VCenterClient : IVMClient {
Expand Down Expand Up @@ -52,9 +57,7 @@ object VCenterClient : IVMClient {
}

override suspend fun getVMByName(name: String, applyId: String): Result<VirtualMachine> = runCatching {
getAllVMs().getOrElse { listOf() }.find { vm ->
vm.name == name && vm.applyId == applyId
} ?: throw vmNotFound(name)
mysql.virtualMachines.find { (it.name eq name) and (it.applyId eq applyId) }?: throw vmNotFound(name)
}

override suspend fun powerOnSync(uuid: String): Result<Unit> = runCatching {
Expand Down
22 changes: 22 additions & 0 deletions openapi/cloudapi_v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ paths:
$ref: '#/components/schemas/PutExperimentRequest'
security:
- Authorization: []
delete:
summary: 删除一项实验(作业)
tags:
- 作业
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ExperimentResponse'
operationId: delete-experiment-experimentId
description: 删除一项实验(作业)
security:
- Authorization: [ ]
parameters: [ ]
'/experiment/{experimentId}/assignment':
parameters:
- schema:
Expand Down Expand Up @@ -4731,6 +4747,9 @@ components:
type: integer
format: int32
description: '所在单位'
email:
type: string
description: '邮箱'
role:
type: integer
format: int32
Expand Down Expand Up @@ -4806,6 +4825,9 @@ components:
type: string
nickname:
type: string
departmentId:
type: integer
format: int32
ChangePasswordRequest:
title: ChangePasswordRequest
x-stoplight:
Expand Down