Skip to content

Commit

Permalink
fix: 修改bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Aug 2, 2024
1 parent 3bdb6fd commit e115bf1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/main/kotlin/subit/router/Admin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import kotlinx.serialization.Serializable
import subit.JWTAuth.getLoginUser
import subit.dataClasses.*
import subit.database.*
import subit.router.Context
import subit.router.authenticated
import subit.router.get
import subit.router.paged
import subit.router.*
import subit.utils.HttpStatus
import subit.utils.checkUserInfo
import subit.utils.respond
Expand Down Expand Up @@ -151,8 +148,7 @@ private suspend fun Context.prohibitUser()
private suspend fun Context.prohibitList()
{
checkPermission { checkHasGlobalAdmin() }
val begin = call.parameters["begin"]?.toLongOrNull() ?: return call.respond(HttpStatus.BadRequest)
val count = call.parameters["count"]?.toIntOrNull() ?: return call.respond(HttpStatus.BadRequest)
val (begin, count) = call.getPage()
call.respond(HttpStatus.OK, get<Prohibits>().getProhibitList(begin, count))
}

Expand Down
14 changes: 9 additions & 5 deletions src/main/kotlin/subit/router/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ fun Route.block() = route("/block", {
body<NewBlock>
{
required = true
description = "新板块信息"
description = "新板块信息, parent为null表示创建根板块. 创建根板块需要全局管理员权限, 其他情况需要在父板块中有管理员权限"
example(
"example", NewBlock(
"板块名称",
"板块描述",
BlockId(0),
BlockId(1),
PermissionLevel.ADMIN,
PermissionLevel.ADMIN,
PermissionLevel.ADMIN,
Expand Down Expand Up @@ -139,7 +139,7 @@ private data class WarpBlockId(val block: BlockId)
private data class NewBlock(
val name: String,
val description: String,
val parent: BlockId,
val parent: BlockId?,
val postingPermission: PermissionLevel,
val commentingPermission: PermissionLevel,
val readingPermission: PermissionLevel,
Expand All @@ -150,9 +150,13 @@ private suspend fun Context.newBlock()
{
val loginUser = getLoginUser() ?: return call.respond(HttpStatus.Unauthorized)
val newBlock = receiveAndCheckBody<NewBlock>()
checkPermission { checkHasAdminIn(newBlock.parent) }
val blocks = get<Blocks>()
blocks.getBlock(newBlock.parent) ?: return call.respond(HttpStatus.BadRequest)
if (newBlock.parent != null)
{
checkPermission { checkHasAdminIn(newBlock.parent) }
blocks.getBlock(newBlock.parent) ?: return call.respond(HttpStatus.BadRequest)
}
else checkPermission { checkHasGlobalAdmin() }
val id = blocks.createBlock(
name = newBlock.name,
description = newBlock.description,
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/subit/router/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ private suspend fun Context.searchPost()
{
val key = call.parameters["key"] ?: return call.respond(HttpStatus.BadRequest)
val (begin, count) = call.getPage()
val openAdvancedSearch = call.parameters["openAdvancedSearch"]?.toBoolean() ?: false
val advancedSearchData: AdvancedSearchData = if(openAdvancedSearch) receiveAndCheckBody<AdvancedSearchData>() else AdvancedSearchData()
val openAdvancedSearch = call.parameters["openAdvancedSearch"].toBoolean()
val advancedSearchData =
if(openAdvancedSearch) receiveAndCheckBody<AdvancedSearchData>()
else AdvancedSearchData()
val posts = get<Posts>().searchPosts(getLoginUser()?.id, key, advancedSearchData, begin, count)
call.respond(HttpStatus.OK, posts)
}

0 comments on commit e115bf1

Please sign in to comment.