mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 19:09:32 +00:00
Merge pull request #1942 from eikek/fix/1941-delete-user
Fix/1941 delete user
This commit is contained in:
commit
97d1c80944
@ -1584,9 +1584,9 @@ paths:
|
|||||||
$ref: "#/components/schemas/BasicResult"
|
$ref: "#/components/schemas/BasicResult"
|
||||||
/sec/user/{username}:
|
/sec/user/{username}:
|
||||||
delete:
|
delete:
|
||||||
operationId: "sec-user-delete-by-username"
|
operationId: "sec-user-delete-by-userid-or-login"
|
||||||
tags: [ Collective ]
|
tags: [ Collective ]
|
||||||
summary: Delete a user.
|
summary: Delete a user by its id or login name.
|
||||||
description: |
|
description: |
|
||||||
Deletes a user.
|
Deletes a user.
|
||||||
security:
|
security:
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package docspell.restserver.routes
|
package docspell.restserver.routes
|
||||||
|
|
||||||
|
import cats.data.OptionT
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import cats.implicits._
|
import cats.implicits._
|
||||||
|
|
||||||
@ -73,8 +74,13 @@ object UserRoutes {
|
|||||||
for {
|
for {
|
||||||
users <- backend.collective.listUser(user.account.collectiveId)
|
users <- backend.collective.listUser(user.account.collectiveId)
|
||||||
ar <-
|
ar <-
|
||||||
if (users.exists(_.uid == id)) backend.collective.deleteUser(id)
|
OptionT
|
||||||
else UpdateResult.notFound.pure[F]
|
.fromOption[F](
|
||||||
|
users
|
||||||
|
.find(u => u.uid == id || u.login == id)
|
||||||
|
)
|
||||||
|
.semiflatMap(u => backend.collective.deleteUser(u.uid))
|
||||||
|
.getOrElse(UpdateResult.notFound)
|
||||||
resp <- Ok(basicResult(ar, "User deleted."))
|
resp <- Ok(basicResult(ar, "User deleted."))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ object FromExprBuilder {
|
|||||||
|
|
||||||
def buildTable(table: TableDef): Fragment =
|
def buildTable(table: TableDef): Fragment =
|
||||||
Fragment.const(table.tableName) ++ table.alias
|
Fragment.const(table.tableName) ++ table.alias
|
||||||
.map(a => Fragment.const0(a))
|
.map(a => Fragment.const(a))
|
||||||
.getOrElse(Fragment.empty)
|
.getOrElse(Fragment.empty)
|
||||||
|
|
||||||
def buildRelation(rel: FromExpr.Relation): Fragment =
|
def buildRelation(rel: FromExpr.Relation): Fragment =
|
||||||
|
@ -17,6 +17,11 @@ class DSLTest extends FunSuite {
|
|||||||
val course = CourseRecord.as("c")
|
val course = CourseRecord.as("c")
|
||||||
val person = PersonRecord.as("p")
|
val person = PersonRecord.as("p")
|
||||||
|
|
||||||
|
test("delete") {
|
||||||
|
val frag = DML.deleteFragment(course, course.ownerId === 15L)
|
||||||
|
assertEquals(frag.internals.sql, "DELETE FROM course c WHERE c.owner_id = ? ")
|
||||||
|
}
|
||||||
|
|
||||||
test("and") {
|
test("and") {
|
||||||
val c = course.lessons > 4 && person.id === 3 && person.name.like("%a%")
|
val c = course.lessons > 4 && person.id === 3 && person.name.like("%a%")
|
||||||
val expect =
|
val expect =
|
||||||
|
@ -32,8 +32,8 @@ class SelectBuilderTest extends FunSuite with TestLoggingConfig {
|
|||||||
val q = Select(proj, table, cond)
|
val q = Select(proj, table, cond)
|
||||||
val frag = SelectBuilder(q)
|
val frag = SelectBuilder(q)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
frag.toString,
|
frag.internals.sql,
|
||||||
"""Fragment("SELECT c.id, c.name, c.owner_id, c.lecturer_id, c.lessons FROM course c INNER JOIN person o ON c.owner_id = o.id LEFT JOIN person l ON c.lecturer_id = l.id WHERE (LOWER(c.name) LIKE ? AND o.name = ? )")"""
|
"""SELECT c.id, c.name, c.owner_id, c.lecturer_id, c.lessons FROM course c INNER JOIN person o ON c.owner_id = o.id LEFT JOIN person l ON c.lecturer_id = l.id WHERE (LOWER(c.name) LIKE ? AND o.name = ? )"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user