upgrade kotlin, ktor, sendgrid
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import fr.dcproject.component.citizen.*
|
||||
import fr.dcproject.component.workgroup.WorkgroupCart
|
||||
import fr.dcproject.component.workgroup.WorkgroupCartI
|
||||
import fr.dcproject.component.workgroup.WorkgroupRef
|
||||
import fr.dcproject.component.workgroup.WorkgroupSimple
|
||||
import fr.dcproject.component.citizen.*
|
||||
import fr.dcproject.entity.*
|
||||
import fr.postgresjson.entity.*
|
||||
import org.joda.time.DateTime
|
||||
@@ -128,4 +128,4 @@ interface ArticleAuthI<U : CitizenI> :
|
||||
CreatedBy<U>,
|
||||
EntityDeletedAt {
|
||||
val draft: Boolean
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ class ArticleRepository(override var requester: Requester) : RepositoryI {
|
||||
return requester
|
||||
.getFunction("find_articles")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"sort" to sort?.toSnakeCase(),
|
||||
"direction" to direction,
|
||||
"search" to search,
|
||||
@@ -48,4 +49,4 @@ class ArticleRepository(override var requester: Requester) : RepositoryI {
|
||||
val createdById: String? = null,
|
||||
val workgroupId: String? = null
|
||||
) : Parameter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package fr.dcproject.component.article
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.views.ViewManager
|
||||
import fr.dcproject.entity.ViewAggregation
|
||||
import fr.dcproject.utils.contentToString
|
||||
import fr.dcproject.utils.getJsonField
|
||||
import fr.dcproject.utils.toIso
|
||||
import fr.dcproject.component.views.ViewManager
|
||||
import org.elasticsearch.client.Request
|
||||
import org.elasticsearch.client.Response
|
||||
import org.elasticsearch.client.RestClient
|
||||
@@ -27,7 +27,8 @@ class ArticleViewManager(private val restClient: RestClient) : ViewManager<Artic
|
||||
"/views/_doc/"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity("""
|
||||
setJsonEntity(
|
||||
"""
|
||||
{
|
||||
"logged": $isLogged,
|
||||
"type": "article",
|
||||
@@ -38,7 +39,8 @@ class ArticleViewManager(private val restClient: RestClient) : ViewManager<Artic
|
||||
"citizen_id": "${citizen?.id}",
|
||||
"view_at": "${dateTime.toIso()}"
|
||||
}
|
||||
""".trimIndent())
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
return restClient.performRequest(request)
|
||||
@@ -53,7 +55,8 @@ class ArticleViewManager(private val restClient: RestClient) : ViewManager<Artic
|
||||
"/views/_search"
|
||||
).apply {
|
||||
//language=JSON
|
||||
setJsonEntity("""
|
||||
setJsonEntity(
|
||||
"""
|
||||
{
|
||||
"size": 0,
|
||||
"query": {
|
||||
@@ -81,7 +84,8 @@ class ArticleViewManager(private val restClient: RestClient) : ViewManager<Artic
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
return restClient
|
||||
@@ -92,4 +96,4 @@ class ArticleViewManager(private val restClient: RestClient) : ViewManager<Artic
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ class ArticleVoter(private val articleRepo: ArticleRepository) : Voter() {
|
||||
/* The new Article must by created by the same citizen of the connected citizen */
|
||||
if (subject.createdBy.id == citizen.id) {
|
||||
/* The creator must be the same of the creator of preview version of article */
|
||||
val lastVersionId = articleRepo
|
||||
.findVersionsByVersionId(1, 1, subject.versionId)
|
||||
.result
|
||||
.firstOrNull()?.createdBy?.id
|
||||
val lastVersionId = articleRepo
|
||||
.findVersionsByVersionId(1, 1, subject.versionId)
|
||||
.result
|
||||
.firstOrNull()?.createdBy?.id
|
||||
|
||||
return when (lastVersionId) {
|
||||
null -> granted("You can create a new Article")
|
||||
@@ -46,4 +46,4 @@ class ArticleVoter(private val articleRepo: ArticleRepository) : Voter() {
|
||||
}
|
||||
return denied("This article must be yours for update it", "article.update.notYours")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +65,4 @@ fun Route.getOneArticle(viewManager: ArticleViewManager, voter: ArticleVoter) {
|
||||
viewManager.addView(call.request.local.remoteHost, it.article, citizenOrNull)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,4 @@ class PasswordlessAuth(
|
||||
}
|
||||
|
||||
private fun noEmail(email: String): Nothing = throw EmailNotFound(email)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ class User(
|
||||
blockedAt: DateTime? = null,
|
||||
override var plainPassword: String? = null,
|
||||
override var roles: List<Roles> = emptyList()
|
||||
) : UserFull, UserBasic(id, username, blockedAt),
|
||||
) : UserFull,
|
||||
UserBasic(id, username, blockedAt),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
|
||||
|
||||
@@ -12,4 +12,4 @@ fun UserI.makeToken(): String = JWT.create()
|
||||
.withIssuer(JwtConfig.issuer)
|
||||
.withClaim("id", id.toString())
|
||||
.withExpiresAt(JwtConfig.getExpiration())
|
||||
.sign(JwtConfig.algorithm)
|
||||
.sign(JwtConfig.algorithm)
|
||||
|
||||
@@ -22,4 +22,4 @@ object JwtConfig {
|
||||
* Calculate the expiration Date based on current time + the given validity
|
||||
*/
|
||||
fun getExpiration() = Date(System.currentTimeMillis() + validityInMs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,4 @@ fun jwtInstallation(userRepo: UserRepository): Authentication.Configuration.() -
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ class CitizenRepository(override var requester: Requester) : RepositoryI {
|
||||
): Paginated<CitizenBasic> = requester
|
||||
.getFunction("find_citizens")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"sort" to sort?.toSnakeCase(),
|
||||
"direction" to direction,
|
||||
"search" to search
|
||||
|
||||
@@ -23,4 +23,4 @@ class CitizenVoter : Voter() {
|
||||
if (connectedCitizen == null) return denied("You must be connected to change your password", "citizen.changePassword.notConnected")
|
||||
return if (subject.id == connectedCitizen.id) granted() else denied("You can only change your password", "citizen.password.notYours")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,4 @@ fun Route.changeMyPassword(voter: CitizenVoter, userRepository: UserRepository)
|
||||
call.respond(HttpStatusCode.BadRequest, "Request format is not correct")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ fun Route.findCitizen(voter: CitizenVoter, repo: CitizenRepository) {
|
||||
voter.assert { canView(citizens.result, citizenOrNull) }
|
||||
call.respond(citizens)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,4 @@ fun Route.getCurrentCitizen(voter: CitizenVoter) {
|
||||
call.respond(citizen)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,4 @@ fun Route.getOneCitizen(voter: CitizenVoter) {
|
||||
|
||||
call.respond(it.citizen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ class CommentArticleRepository(requester: Requester) : CommentRepositoryAbs<Arti
|
||||
return requester.run {
|
||||
getFunction("find_comments_by_citizen")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"created_by_id" to citizen.id,
|
||||
"reference" to TargetI.getReference(ArticleRef::class)
|
||||
)
|
||||
@@ -42,7 +43,8 @@ class CommentArticleRepository(requester: Requester) : CommentRepositoryAbs<Arti
|
||||
): Paginated<CommentForView<ArticleForView, CitizenRef>> = requester
|
||||
.getFunction("find_comments_by_target")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"target_id" to target.id,
|
||||
"sort" to sort.sql
|
||||
)
|
||||
@@ -57,4 +59,4 @@ class CommentArticleRepository(requester: Requester) : CommentRepositoryAbs<Arti
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,4 @@ fun Route.createCommentArticle(repo: CommentArticleRepository, voter: CommentVot
|
||||
call.respond(HttpStatusCode.Created, comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ fun Route.getCitizenArticleComments(repo: CommentArticleRepository, voter: Comme
|
||||
call.respond(comments)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ abstract class CommentRepositoryAbs<T : TargetI>(override var requester: Request
|
||||
return requester.run {
|
||||
getFunction("find_comments_by_parent")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"parent_id" to parentId
|
||||
)
|
||||
}
|
||||
@@ -60,7 +61,8 @@ abstract class CommentRepositoryAbs<T : TargetI>(override var requester: Request
|
||||
return requester.run {
|
||||
getFunction("find_comments_by_target")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"target_id" to targetId,
|
||||
"sort" to sort.sql
|
||||
)
|
||||
@@ -101,7 +103,8 @@ class CommentRepository(requester: Requester) : CommentRepositoryAbs<TargetRef>(
|
||||
return requester.run {
|
||||
getFunction("find_comments_by_citizen")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"created_by_id" to citizen.id
|
||||
)
|
||||
}
|
||||
@@ -115,7 +118,8 @@ class CommentRepository(requester: Requester) : CommentRepositoryAbs<TargetRef>(
|
||||
return requester.run {
|
||||
getFunction("find_comments_by_parent")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"parent_id" to parentId
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,4 +30,4 @@ fun Route.editComment(repo: CommentRepository, voter: CommentVoter) {
|
||||
|
||||
call.respond(HttpStatusCode.OK, comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,4 @@ fun Route.getChildrenComments(repo: CommentRepository, voter: CommentVoter) {
|
||||
|
||||
call.respond(HttpStatusCode.OK, comments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ fun Route.getOneComment(repo: CommentRepository, voter: CommentVoter) {
|
||||
|
||||
call.respond(HttpStatusCode.OK, comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ object ConfigViews {
|
||||
private fun waitElasticsearchIsUp(client: RestClient) {
|
||||
val logger: Logger = LoggerFactory.getLogger("fr.dcproject.elasticsearch")
|
||||
val request = Request("GET", "/_cluster/health")
|
||||
repeat(5*60 / 2) { // 5 minutes
|
||||
repeat(5 * 60 / 2) { // 5 minutes
|
||||
runCatching {
|
||||
client.performRequest(request).statusLine.statusCode
|
||||
}.onSuccess {
|
||||
@@ -74,7 +74,7 @@ object ConfigViews {
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent()
|
||||
)
|
||||
}.let {
|
||||
performRequest(it)
|
||||
|
||||
@@ -15,4 +15,4 @@ interface ViewManager <T> {
|
||||
* Get Views aggregations
|
||||
*/
|
||||
fun getViewsCount(entity: T): ViewAggregation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,4 +104,4 @@ fun <Z : CitizenWithUserI> List<Member<Z>>.getRoles(user: UserI): List<Role> =
|
||||
fun <Z : CitizenWithUserI> List<Member<Z>>.getRoles(citizen: CitizenI): List<Role> =
|
||||
firstOrNull { it.citizen.id == citizen.id }?.roles ?: emptyList()
|
||||
|
||||
interface WorkgroupI : UuidEntityI
|
||||
interface WorkgroupI : UuidEntityI
|
||||
|
||||
@@ -30,7 +30,8 @@ class WorkgroupRepository(override var requester: Requester) : RepositoryI {
|
||||
return requester
|
||||
.getFunction("find_workgroups")
|
||||
.select(
|
||||
page, limit,
|
||||
page,
|
||||
limit,
|
||||
"sort" to sort?.toSnakeCase(),
|
||||
"direction" to direction,
|
||||
"search" to search,
|
||||
@@ -43,8 +44,8 @@ class WorkgroupRepository(override var requester: Requester) : RepositoryI {
|
||||
.selectOne("resource" to workgroup) ?: error("query 'upsert_workgroup' return null")
|
||||
|
||||
fun <W : WorkgroupRef> delete(workgroup: W) = requester
|
||||
.getFunction("delete_workgroup")
|
||||
.perform("id" to workgroup.id)
|
||||
.getFunction("delete_workgroup")
|
||||
.perform("id" to workgroup.id)
|
||||
|
||||
fun addMember(workgroup: WorkgroupI, member: Member<CitizenI>): Member<CitizenBasic>? =
|
||||
addMember(workgroup, member.citizen, member.roles)
|
||||
|
||||
@@ -32,7 +32,12 @@ object GetWorkgroups {
|
||||
fun Route.getWorkgroups(repo: WorkgroupRepository, voter: WorkgroupVoter) {
|
||||
get<WorkgroupsRequest> {
|
||||
val workgroups =
|
||||
repo.find(it.page, it.limit, it.sort, it.direction, it.search,
|
||||
repo.find(
|
||||
it.page,
|
||||
it.limit,
|
||||
it.sort,
|
||||
it.direction,
|
||||
it.search,
|
||||
WorkgroupRepository.Filter(createdById = it.createdBy, members = it.members)
|
||||
)
|
||||
voter.assert { canView(workgroups.result, citizenOrNull) }
|
||||
|
||||
@@ -41,10 +41,10 @@ object DeleteMembersOfWorkgroup {
|
||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||
call.getMembersFromRequest().let { members ->
|
||||
voter.assert { canView(workgroup, citizenOrNull) }
|
||||
repo.removeMembers(workgroup, members)
|
||||
}.let { members ->
|
||||
call.respond(HttpStatusCode.OK, members)
|
||||
}
|
||||
repo.removeMembers(workgroup, members)
|
||||
}.let { members ->
|
||||
call.respond(HttpStatusCode.OK, members)
|
||||
}
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ object UpdateMemberOfWorkgroup {
|
||||
repo.findById(it.workgroupId)?.let { workgroup ->
|
||||
call.getMembersFromRequest().let { members ->
|
||||
voter.assert { canUpdateMembers(workgroup, citizenOrNull) }
|
||||
repo.updateMembers(workgroup, members)
|
||||
}.let { members ->
|
||||
call.respond(HttpStatusCode.OK, members)
|
||||
}
|
||||
repo.updateMembers(workgroup, members)
|
||||
}.let { members ->
|
||||
call.respond(HttpStatusCode.OK, members)
|
||||
}
|
||||
} ?: call.respond(HttpStatusCode.NotFound)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user