deelte useless stuyff
This commit is contained in:
@@ -6,7 +6,6 @@ import com.android.trisolarisserver.controller.dto.PropertyResponse
|
||||
import com.android.trisolarisserver.controller.dto.PropertyUpdateRequest
|
||||
import com.android.trisolarisserver.controller.dto.PropertyUserResponse
|
||||
import com.android.trisolarisserver.controller.dto.PropertyUserRoleRequest
|
||||
import com.android.trisolarisserver.controller.dto.UserCreateRequest
|
||||
import com.android.trisolarisserver.controller.dto.UserResponse
|
||||
import com.android.trisolarisserver.db.repo.AppUserRepo
|
||||
import com.android.trisolarisserver.db.repo.OrganizationRepo
|
||||
@@ -19,6 +18,7 @@ import com.android.trisolarisserver.models.property.Role
|
||||
import com.android.trisolarisserver.security.MyPrincipal
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
@@ -84,36 +84,6 @@ class Properties(
|
||||
return propertyRepo.findAllById(propertyIds).map { it.toResponse() }
|
||||
}
|
||||
|
||||
@PostMapping("/orgs/{orgId}/users")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
fun createUser(
|
||||
@PathVariable orgId: UUID,
|
||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||
@RequestBody request: UserCreateRequest
|
||||
): UserResponse {
|
||||
val user = requireUser(principal)
|
||||
if (user.org.id != orgId) {
|
||||
throw ResponseStatusException(HttpStatus.FORBIDDEN, "No access to org")
|
||||
}
|
||||
requireOrgRole(orgId, user.id!!, Role.ADMIN)
|
||||
|
||||
if (appUserRepo.existsByFirebaseUid(request.firebaseUid)) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "User already exists")
|
||||
}
|
||||
val org = orgRepo.findById(orgId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Org not found")
|
||||
}
|
||||
val newUser = com.android.trisolarisserver.models.property.AppUser(
|
||||
org = org,
|
||||
firebaseUid = request.firebaseUid,
|
||||
phoneE164 = request.phoneE164,
|
||||
name = request.name,
|
||||
disabled = request.disabled ?: false
|
||||
)
|
||||
val saved = appUserRepo.save(newUser)
|
||||
return saved.toUserResponse()
|
||||
}
|
||||
|
||||
@GetMapping("/orgs/{orgId}/users")
|
||||
fun listUsers(
|
||||
@PathVariable orgId: UUID,
|
||||
@@ -157,14 +127,18 @@ class Properties(
|
||||
|
||||
val actorRoles = propertyUserRepo.findRolesByPropertyAndUser(propertyId, principal.userId)
|
||||
val allowedRoles = when {
|
||||
actorRoles.contains(Role.ADMIN) -> Role.entries.toSet()
|
||||
actorRoles.contains(Role.ADMIN) -> setOf(Role.ADMIN, Role.MANAGER, Role.STAFF, Role.AGENT)
|
||||
actorRoles.contains(Role.MANAGER) -> setOf(Role.STAFF, Role.AGENT)
|
||||
else -> emptySet()
|
||||
}
|
||||
if (allowedRoles.isEmpty()) {
|
||||
throw ResponseStatusException(HttpStatus.FORBIDDEN, "Missing role")
|
||||
}
|
||||
val requestedRoles = request.roles.map { Role.valueOf(it) }.toSet()
|
||||
val requestedRoles = try {
|
||||
request.roles.map { Role.valueOf(it) }.toSet()
|
||||
} catch (ex: IllegalArgumentException) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Unknown role")
|
||||
}
|
||||
if (!allowedRoles.containsAll(requestedRoles)) {
|
||||
throw ResponseStatusException(HttpStatus.FORBIDDEN, "Role not allowed")
|
||||
}
|
||||
|
||||
@@ -37,13 +37,6 @@ data class PropertyResponse(
|
||||
val active: Boolean
|
||||
)
|
||||
|
||||
data class UserCreateRequest(
|
||||
val firebaseUid: String,
|
||||
val phoneE164: String? = null,
|
||||
val name: String? = null,
|
||||
val disabled: Boolean? = null
|
||||
)
|
||||
|
||||
data class UserResponse(
|
||||
val id: UUID,
|
||||
val orgId: UUID,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
spring.application.name=TrisolarisServer
|
||||
spring.datasource.username=android
|
||||
spring.datasource.password=${DB_PASSWORD}
|
||||
spring.datasource.password=taddymydoggy!
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.open-in-view=false
|
||||
spring.flyway.enabled=false
|
||||
|
||||
Reference in New Issue
Block a user