-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automations, CDN, Webhooks (#1905)
Co-authored-by: Štěpán Granát <granat.stepan@gmail.com>
- Loading branch information
Showing
282 changed files
with
11,881 additions
and
1,123 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...in/kotlin/io/tolgee/api/v2/controllers/contentDelivery/ContentDeliveryConfigController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.tolgee.api.v2.controllers.contentDelivery | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import io.tolgee.api.v2.controllers.IController | ||
import io.tolgee.component.contentDelivery.ContentDeliveryUploader | ||
import io.tolgee.dtos.request.ContentDeliveryConfigRequest | ||
import io.tolgee.hateoas.contentDelivery.ContentDeliveryConfigModel | ||
import io.tolgee.hateoas.contentDelivery.ContentDeliveryConfigModelAssembler | ||
import io.tolgee.model.contentDelivery.ContentDeliveryConfig | ||
import io.tolgee.model.enums.Scope | ||
import io.tolgee.security.ProjectHolder | ||
import io.tolgee.security.authentication.AllowApiAccess | ||
import io.tolgee.security.authorization.RequiresProjectPermissions | ||
import io.tolgee.service.contentDelivery.ContentDeliveryConfigService | ||
import org.springdoc.api.annotations.ParameterObject | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.web.PagedResourcesAssembler | ||
import org.springframework.hateoas.PagedModel | ||
import org.springframework.web.bind.annotation.CrossOrigin | ||
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 | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import javax.validation.Valid | ||
|
||
@Suppress("MVCPathVariableInspection") | ||
@RestController | ||
@CrossOrigin(origins = ["*"]) | ||
@RequestMapping( | ||
value = [ | ||
"/v2/projects/{projectId}/content-delivery-configs", | ||
] | ||
) | ||
@Tag(name = "Content Delivery", description = "Endpoints for Content Delivery management") | ||
class ContentDeliveryConfigController( | ||
private val contentDeliveryService: ContentDeliveryConfigService, | ||
private val projectHolder: ProjectHolder, | ||
private val contentDeliveryConfigModelAssembler: ContentDeliveryConfigModelAssembler, | ||
@Suppress("SpringJavaInjectionPointsAutowiringInspection") | ||
private val pagedContentDeliveryConfigModelAssemblerExporter: PagedResourcesAssembler<ContentDeliveryConfig>, | ||
private val contentDeliveryUploader: ContentDeliveryUploader | ||
) : IController { | ||
@PostMapping("") | ||
@Operation(description = "Create Content Delivery Config") | ||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_MANAGE]) | ||
@AllowApiAccess | ||
fun create(@Valid @RequestBody dto: ContentDeliveryConfigRequest): ContentDeliveryConfigModel { | ||
val contentDeliveryConfig = contentDeliveryService.create(projectHolder.project.id, dto) | ||
return contentDeliveryConfigModelAssembler.toModel(contentDeliveryConfig) | ||
} | ||
|
||
@PutMapping("/{id}") | ||
@Operation(description = "Updates Content Delivery Config") | ||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_MANAGE]) | ||
@AllowApiAccess | ||
fun update( | ||
@PathVariable id: Long, | ||
@Valid @RequestBody dto: ContentDeliveryConfigRequest | ||
): ContentDeliveryConfigModel { | ||
val contentDeliveryConfig = contentDeliveryService.update(projectId = projectHolder.project.id, id, dto) | ||
return contentDeliveryConfigModelAssembler.toModel(contentDeliveryConfig) | ||
} | ||
|
||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_PUBLISH]) | ||
@GetMapping("") | ||
@Operation(description = "List existing Content Delivery Configs") | ||
@AllowApiAccess | ||
fun list(@ParameterObject pageable: Pageable): PagedModel<ContentDeliveryConfigModel> { | ||
val page = contentDeliveryService.getAllInProject(projectHolder.project.id, pageable) | ||
return pagedContentDeliveryConfigModelAssemblerExporter.toModel(page, contentDeliveryConfigModelAssembler) | ||
} | ||
|
||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_MANAGE]) | ||
@DeleteMapping("/{id}") | ||
@Operation(description = "Delete Content Delivery Config") | ||
@AllowApiAccess | ||
fun delete(@PathVariable id: Long) { | ||
contentDeliveryService.delete(projectHolder.project.id, id) | ||
} | ||
|
||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_PUBLISH]) | ||
@GetMapping("/{id}") | ||
@Operation(description = "Get Content Delivery Config") | ||
@AllowApiAccess | ||
fun get(@PathVariable id: Long): ContentDeliveryConfigModel { | ||
return contentDeliveryConfigModelAssembler.toModel(contentDeliveryService.get(projectHolder.project.id, id)) | ||
} | ||
|
||
@RequiresProjectPermissions([Scope.CONTENT_DELIVERY_PUBLISH]) | ||
@PostMapping("/{id}") | ||
@Operation(description = "Publish to Content Delivery") | ||
@AllowApiAccess | ||
fun post(@PathVariable id: Long) { | ||
val exporter = contentDeliveryService.get(projectHolder.project.id, id) | ||
contentDeliveryUploader.upload(exporter.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
backend/api/src/main/kotlin/io/tolgee/hateoas/activity/ProjectActivityAuthorModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package io.tolgee.hateoas.activity | ||
|
||
import io.tolgee.api.IProjectActivityAuthorModel | ||
import io.tolgee.dtos.Avatar | ||
import org.springframework.hateoas.RepresentationModel | ||
|
||
data class ProjectActivityAuthorModel( | ||
val id: Long, | ||
val username: String?, | ||
var name: String?, | ||
var avatar: Avatar?, | ||
var deleted: Boolean | ||
) : RepresentationModel<ProjectActivityAuthorModel>() | ||
override val id: Long, | ||
override val username: String?, | ||
override var name: String?, | ||
override var avatar: Avatar?, | ||
override var deleted: Boolean | ||
) : RepresentationModel<ProjectActivityAuthorModel>(), IProjectActivityAuthorModel |
19 changes: 10 additions & 9 deletions
19
backend/api/src/main/kotlin/io/tolgee/hateoas/activity/ProjectActivityModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
package io.tolgee.hateoas.activity | ||
|
||
import io.tolgee.activity.data.ActivityType | ||
import io.tolgee.api.IProjectActivityModel | ||
import org.springframework.hateoas.RepresentationModel | ||
import org.springframework.hateoas.server.core.Relation | ||
import java.io.Serializable | ||
|
||
@Suppress("unused") | ||
@Relation(collectionRelation = "activities", itemRelation = "activity") | ||
class ProjectActivityModel( | ||
val revisionId: Long, | ||
val timestamp: Long, | ||
val type: ActivityType, | ||
val author: ProjectActivityAuthorModel?, | ||
val modifiedEntities: Map<String, List<ModifiedEntityModel>>?, | ||
val meta: Map<String, Any?>?, | ||
val counts: MutableMap<String, Long>?, | ||
val params: Any?, | ||
) : RepresentationModel<ProjectActivityModel>(), Serializable | ||
override val revisionId: Long, | ||
override val timestamp: Long, | ||
override val type: ActivityType, | ||
override val author: ProjectActivityAuthorModel?, | ||
override val modifiedEntities: Map<String, List<ModifiedEntityModel>>?, | ||
override val meta: Map<String, Any?>?, | ||
override val counts: MutableMap<String, Long>?, | ||
override val params: Any?, | ||
) : RepresentationModel<ProjectActivityModel>(), Serializable, IProjectActivityModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/api/src/main/kotlin/io/tolgee/hateoas/automation/AutomationActionModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.tolgee.hateoas.automation | ||
|
||
import io.tolgee.hateoas.contentDelivery.ContentDeliveryConfigModel | ||
import io.tolgee.model.automations.AutomationActionType | ||
|
||
class AutomationActionModel( | ||
var id: Long, | ||
var type: AutomationActionType, | ||
) { | ||
var contentDeliveryConfig: ContentDeliveryConfigModel? = null | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/api/src/main/kotlin/io/tolgee/hateoas/automation/AutomationActionModelFiller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.tolgee.hateoas.automation | ||
|
||
import io.tolgee.model.automations.AutomationAction | ||
import io.tolgee.model.automations.AutomationActionType | ||
|
||
interface AutomationActionModelFiller { | ||
fun fill(model: AutomationActionModel, entity: AutomationAction) | ||
|
||
val type: AutomationActionType | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/api/src/main/kotlin/io/tolgee/hateoas/automation/AutomationModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.tolgee.hateoas.automation | ||
|
||
import org.springframework.hateoas.RepresentationModel | ||
import org.springframework.hateoas.server.core.Relation | ||
import java.io.Serializable | ||
|
||
@Suppress("unused") | ||
@Relation(collectionRelation = "automations", itemRelation = "automation") | ||
class AutomationModel( | ||
val id: Long, | ||
val name: String, | ||
val triggers: List<AutomationTriggerModel>, | ||
val actions: List<AutomationActionModel>, | ||
) : RepresentationModel<AutomationModel>(), Serializable |
11 changes: 11 additions & 0 deletions
11
backend/api/src/main/kotlin/io/tolgee/hateoas/automation/AutomationTriggerModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.tolgee.hateoas.automation | ||
|
||
import io.tolgee.activity.data.ActivityType | ||
import io.tolgee.model.automations.AutomationTriggerType | ||
|
||
class AutomationTriggerModel( | ||
var id: Long, | ||
var type: AutomationTriggerType = AutomationTriggerType.TRANSLATION_DATA_MODIFICATION, | ||
var activityType: ActivityType? = null, | ||
var debounceDurationInMs: Long? = null | ||
) |
31 changes: 31 additions & 0 deletions
31
backend/api/src/main/kotlin/io/tolgee/hateoas/contentDelivery/ContentDeliveryConfigModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.tolgee.hateoas.contentDelivery | ||
|
||
import io.tolgee.dtos.IExportParams | ||
import io.tolgee.dtos.request.export.ExportFormat | ||
import io.tolgee.ee.api.v2.hateoas.contentStorage.ContentStorageModel | ||
import io.tolgee.model.enums.TranslationState | ||
import org.springframework.hateoas.RepresentationModel | ||
import org.springframework.hateoas.server.core.Relation | ||
import java.io.Serializable | ||
|
||
@Suppress("unused") | ||
@Relation(collectionRelation = "contentDeliveryConfigs", itemRelation = "contentDeliveryConfig") | ||
class ContentDeliveryConfigModel( | ||
val id: Long, | ||
val name: String, | ||
val slug: String, | ||
val storage: ContentStorageModel?, | ||
val publicUrl: String?, | ||
val autoPublish: Boolean, | ||
val lastPublished: Long? | ||
) : RepresentationModel<ContentDeliveryConfigModel>(), Serializable, IExportParams { | ||
override var languages: Set<String>? = null | ||
override var format: ExportFormat = ExportFormat.JSON | ||
override var structureDelimiter: Char? = null | ||
override var filterKeyId: List<Long>? = null | ||
override var filterKeyIdNot: List<Long>? = null | ||
override var filterTag: String? = null | ||
override var filterKeyPrefix: String? = null | ||
override var filterState: List<TranslationState>? = null | ||
override var filterNamespace: List<String?>? = null | ||
} |
37 changes: 37 additions & 0 deletions
37
.../src/main/kotlin/io/tolgee/hateoas/contentDelivery/ContentDeliveryConfigModelAssembler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.tolgee.hateoas.contentDelivery | ||
|
||
import io.tolgee.api.v2.controllers.contentDelivery.ContentDeliveryConfigController | ||
import io.tolgee.configuration.tolgee.TolgeeProperties | ||
import io.tolgee.ee.api.v2.hateoas.contentStorage.ContentStorageModelAssembler | ||
import io.tolgee.model.contentDelivery.ContentDeliveryConfig | ||
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ContentDeliveryConfigModelAssembler( | ||
private val contentStorageModelAssembler: ContentStorageModelAssembler, | ||
private val tolgeeProperties: TolgeeProperties | ||
) : RepresentationModelAssemblerSupport<ContentDeliveryConfig, ContentDeliveryConfigModel>( | ||
ContentDeliveryConfigController::class.java, ContentDeliveryConfigModel::class.java | ||
) { | ||
override fun toModel(entity: ContentDeliveryConfig): ContentDeliveryConfigModel { | ||
return ContentDeliveryConfigModel( | ||
id = entity.id, | ||
name = entity.name, | ||
slug = entity.slug, | ||
storage = entity.contentStorage?.let { contentStorageModelAssembler.toModel(it) }, | ||
publicUrl = getPublicUrl(entity), | ||
autoPublish = entity.automationActions.isNotEmpty(), | ||
lastPublished = entity.lastPublished?.time | ||
).also { | ||
it.copyPropsFrom(entity) | ||
} | ||
} | ||
|
||
private fun getPublicUrl(entity: ContentDeliveryConfig): String? { | ||
if (entity.contentStorage != null) { | ||
return entity.contentStorage?.publicUrlPrefix?.let { it.removeSuffix("/") + "/" + entity.slug } | ||
} | ||
return tolgeeProperties.contentDelivery.publicUrlPrefix?.let { it.removeSuffix("/") + "/" + entity.slug } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.