mirror of https://github.com/usbharu/Hideout.git
Merge pull request #272 from usbharu/bugfix/get-loginuser
Bugfix/get loginuser
This commit is contained in:
commit
f011e43379
|
@ -424,6 +424,23 @@ class AccountApiTest {
|
|||
.andExpect { status { isUnauthorized() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `apiV1AccountsIdStatusesGet read権限で取得できる`() {
|
||||
mockMvc
|
||||
.get("/api/v1/accounts/1/statuses")
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithAnonymousUser
|
||||
fun `apiV1AccountsIdStatusesGet 匿名でもpublic投稿を取得できる`() {
|
||||
mockMvc
|
||||
.get("/api/v1/accounts/1/statuses")
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@AfterAll
|
||||
|
|
|
@ -2,4 +2,6 @@ package dev.usbharu.hideout.core.infrastructure.springframework.security
|
|||
|
||||
interface LoginUserContextHolder {
|
||||
fun getLoginUserId(): Long
|
||||
|
||||
fun getLoginUserIdOrNull(): Long?
|
||||
}
|
||||
|
|
|
@ -11,4 +11,13 @@ class OAuth2JwtLoginUserContextHolder : LoginUserContextHolder {
|
|||
|
||||
return principal.getClaim<String>("uid").toLong()
|
||||
}
|
||||
|
||||
override fun getLoginUserIdOrNull(): Long? {
|
||||
val principal = SecurityContextHolder.getContext()?.authentication?.principal
|
||||
if (principal !is Jwt) {
|
||||
return null
|
||||
}
|
||||
|
||||
return principal.getClaim<String>("uid").toLongOrNull()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class MastodonAccountApiController(
|
|||
pinned: Boolean,
|
||||
tagged: String?
|
||||
): ResponseEntity<Flow<Status>> = runBlocking {
|
||||
val userid = loginUserContextHolder.getLoginUserId()
|
||||
val userid = loginUserContextHolder.getLoginUserIdOrNull()
|
||||
val statuses = accountApiService.accountsStatuses(
|
||||
userid = id.toLong(),
|
||||
onlyMedia = onlyMedia,
|
||||
|
|
Loading…
Reference in New Issue