From c865fcc7a7674342556a70fa20a12e3eca04cc64 Mon Sep 17 00:00:00 2001 From: HanZiyao Date: Sat, 11 Jan 2025 21:36:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E6=9C=BA=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E9=97=AE=E9=A2=98=E3=80=81=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7bug=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9E=E9=AA=8C=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/models/CreateUserRequest.kt | 5 ++++- .../scs/controller/models/PatchUserRequest.kt | 4 +++- .../scs/kube/crd/v1alpha1/VirtualMachine.kt | 2 ++ .../kotlin/cn/edu/buaa/scs/route/Admin.kt | 3 ++- .../cn/edu/buaa/scs/route/Experiment.kt | 6 +++++ .../kotlin/cn/edu/buaa/scs/service/Admin.kt | 4 ++-- .../cn/edu/buaa/scs/service/Experiment.kt | 4 ++++ .../kotlin/cn/edu/buaa/scs/service/User.kt | 6 ++++- .../edu/buaa/scs/vm/vcenter/VCenterClient.kt | 9 +++++--- openapi/cloudapi_v2.yaml | 22 +++++++++++++++++++ 10 files changed, 56 insertions(+), 9 deletions(-) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/CreateUserRequest.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/CreateUserRequest.kt index 04d6a3a..d5c4ae8 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/CreateUserRequest.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/CreateUserRequest.kt @@ -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( /* 学工号 */ @@ -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 ) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/PatchUserRequest.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/PatchUserRequest.kt index fc55485..9081152 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/PatchUserRequest.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/models/PatchUserRequest.kt @@ -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 ) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/VirtualMachine.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/VirtualMachine.kt index 31600f9..295b6df 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/VirtualMachine.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/VirtualMachine.kt @@ -168,6 +168,8 @@ class VirtualMachineReconciler(val client: KubernetesClient) : Reconciler() 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 { diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Experiment.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Experiment.kt index 95eb0e9..08483fa 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Experiment.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/route/Experiment.kt @@ -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( diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt index b25e924..a87d6ee 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Admin.kt @@ -17,12 +17,12 @@ val ApplicationCall.admin: AdminService class AdminService(val call: ApplicationCall) : IService { companion object : IService.Caller() - 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) { diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Experiment.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Experiment.kt index 2b97ea6..172d079 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Experiment.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Experiment.kt @@ -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?, diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/User.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/User.kt index 61c94f7..6463b65 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/User.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/User.kt @@ -24,11 +24,12 @@ fun User.Companion.getUerListByIdList(idList: List): List { 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) @@ -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() } diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/vm/vcenter/VCenterClient.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/vm/vcenter/VCenterClient.kt index 34acb48..bd79d23 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/vm/vcenter/VCenterClient.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/vm/vcenter/VCenterClient.kt @@ -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.* @@ -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 { @@ -52,9 +57,7 @@ object VCenterClient : IVMClient { } override suspend fun getVMByName(name: String, applyId: String): Result = 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 = runCatching { diff --git a/openapi/cloudapi_v2.yaml b/openapi/cloudapi_v2.yaml index d7f963a..ec7320f 100644 --- a/openapi/cloudapi_v2.yaml +++ b/openapi/cloudapi_v2.yaml @@ -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: @@ -4731,6 +4747,9 @@ components: type: integer format: int32 description: '所在单位' + email: + type: string + description: '邮箱' role: type: integer format: int32 @@ -4806,6 +4825,9 @@ components: type: string nickname: type: string + departmentId: + type: integer + format: int32 ChangePasswordRequest: title: ChangePasswordRequest x-stoplight: From 12fe39e143bc845588eb50067884ff29f467fee8 Mon Sep 17 00:00:00 2001 From: HanZiyao Date: Sat, 11 Jan 2025 21:46:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E6=9C=BA=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E9=97=AE=E9=A2=98=E3=80=81=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7bug=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9E=E9=AA=8C=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Course.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Course.kt b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Course.kt index bbe7d4d..39442fc 100644 --- a/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Course.kt +++ b/cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/service/Course.kt @@ -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) } }