-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Playground] Add Database sharing (#1525)
* 1483 api sharing of sql playground copy (#1524) * added routing for dump service; added token generation for expiry and scheduled cleanup * updated the controller logic * added share playground args to runner * added runner type and share vertical for testing * 1482 web fronted for sql playground sharing (#1523) * added button and its functionality; Service still needs to be updated * changed uri display to dialog * changed service function * changed service path * refactoring --------- Co-authored-by: Jonas Kuche <Zitrone44@users.noreply.github.com> * 1481 sql runner support for playground sharing (#1522) * copy the database and create a new user * copy database to another instance --------- Co-authored-by: Jonas Kuche <Zitrone44@users.noreply.github.com> * feat(playground): add database sharing * chore: fix style --------- Co-authored-by: Khaled Trabelsi <131378411+trKhaled@users.noreply.github.com> Co-authored-by: Youssef Mellouli <49683272+ymll58@users.noreply.github.com>
- Loading branch information
1 parent
d2eb7d4
commit e4bb270
Showing
33 changed files
with
579 additions
and
25 deletions.
There are no files selected for viewing
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
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
16 changes: 16 additions & 0 deletions
16
...bs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/SqlPlaygroundShareArguments.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,16 @@ | ||
package de.thm.ii.fbs.model.v2.checker | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class SqlPlaygroundShareArguments( | ||
@JsonProperty("user") | ||
val user: RunnerUser, | ||
@JsonProperty("database") | ||
val database: RunnerDatabase, | ||
@JsonProperty("id") | ||
val id: String, | ||
@JsonProperty("password") | ||
val password: String, | ||
@JsonProperty("runner") | ||
val runner: Runner = Runner(RunnerType.SQL_PLAYGROUND_SHARE) | ||
) : RunnerArguments() |
14 changes: 14 additions & 0 deletions
14
...e/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/SqlPlaygroundShareDeleteArguments.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 de.thm.ii.fbs.model.v2.checker | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class SqlPlaygroundShareDeleteArguments( | ||
@JsonProperty("database") | ||
val database: RunnerDatabase, | ||
@JsonProperty("id") | ||
val id: String, | ||
@JsonProperty("delete") | ||
val delete: Boolean = true, | ||
@JsonProperty("runner") | ||
val runner: Runner = Runner(RunnerType.SQL_PLAYGROUND_SHARE) | ||
) : RunnerArguments() |
16 changes: 16 additions & 0 deletions
16
modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/playground/SqlPlaygroundShare.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,16 @@ | ||
package de.thm.ii.fbs.model.v2.playground | ||
import java.time.LocalDateTime | ||
import javax.persistence.* // ktlint-disable no-wildcard-imports | ||
|
||
@Entity | ||
@Table(name = "sql_playground_share") | ||
class SqlPlaygroundShare( | ||
@OneToOne(cascade = [CascadeType.ALL]) | ||
@PrimaryKeyJoinColumn | ||
val database: SqlPlaygroundDatabase, | ||
@Column(nullable = false) | ||
val creationTime: LocalDateTime, | ||
@Id | ||
@Column(name = "database_id") | ||
val id: Int? = null | ||
) |
8 changes: 8 additions & 0 deletions
8
...e/api/src/main/kotlin/de/thm/ii/fbs/model/v2/playground/api/SqlPlaygroundShareResponse.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,8 @@ | ||
package de.thm.ii.fbs.model.v2.playground.api | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class SqlPlaygroundShareResponse( | ||
@JsonProperty("url") | ||
var url: String | ||
) |
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
21 changes: 21 additions & 0 deletions
21
modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/services/v2/misc/IdService.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,21 @@ | ||
package de.thm.ii.fbs.services.v2.misc | ||
|
||
import org.hashids.Hashids | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class IdService( | ||
@Value("\${services.ids.salt}") | ||
salt: String, | ||
@Value("\${services.ids.length}") | ||
length: Int | ||
) { | ||
private val hashids = Hashids(salt, length) | ||
|
||
fun encode(id: Long): String = | ||
hashids.encode(id) | ||
|
||
fun encode(id: Int): String = | ||
encode(id.toLong()) | ||
} |
23 changes: 23 additions & 0 deletions
23
...-core/api/src/main/kotlin/de/thm/ii/fbs/services/v2/misc/SharePlaygroundCleanupService.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,23 @@ | ||
package de.thm.ii.fbs.services.v2.misc | ||
|
||
import de.thm.ii.fbs.model.v2.playground.SqlPlaygroundShare | ||
import de.thm.ii.fbs.services.v2.checker.SqlPlaygroundCheckerService | ||
import de.thm.ii.fbs.services.v2.persistence.SqlSharePlaygroundShareRepository | ||
import org.springframework.scheduling.annotation.Scheduled | ||
import org.springframework.stereotype.Service | ||
import java.time.LocalDateTime | ||
|
||
@Service | ||
class SharePlaygroundCleanupService( | ||
private val sqlSharePlaygroundShareRepository: SqlSharePlaygroundShareRepository, | ||
private val sqlPlaygroundCheckerService: SqlPlaygroundCheckerService | ||
) { | ||
@Scheduled(fixedDelayString = "PT1H") // Runs every hour | ||
fun cleanupExpiredShares() { | ||
val now = LocalDateTime.now() | ||
val expiredShares: List<SqlPlaygroundShare> = sqlSharePlaygroundShareRepository.findAllByCreationTimeLessThan(now.minusDays(1)) | ||
expiredShares.forEach { share -> | ||
sqlPlaygroundCheckerService.deleteDatabaseShare(share) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rc/main/kotlin/de/thm/ii/fbs/services/v2/persistence/SqlSharePlaygroundShareRepository.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,9 @@ | ||
package de.thm.ii.fbs.services.v2.persistence | ||
|
||
import de.thm.ii.fbs.model.v2.playground.SqlPlaygroundShare | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.time.LocalDateTime | ||
|
||
interface SqlSharePlaygroundShareRepository : JpaRepository<SqlPlaygroundShare, String> { | ||
fun findAllByCreationTimeLessThan(creationTime: LocalDateTime): List<SqlPlaygroundShare> | ||
} |
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
16 changes: 16 additions & 0 deletions
16
modules/fbs-core/api/src/main/resources/migrations/19_playground_share_token.sql
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,16 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE sql_playground_share | ||
( | ||
database_id INT NOT NULL, | ||
creation_time TIMESTAMP NOT NULL, | ||
CONSTRAINT sql_playground_share_pk | ||
PRIMARY KEY (database_id), | ||
constraint sql_playground_share_sql_playground_database_id_fk | ||
FOREIGN KEY (database_id) references sql_playground_database (id) | ||
ON UPDATE CASCADE | ||
); | ||
|
||
|
||
INSERT INTO migration (number) VALUES (19); | ||
COMMIT; |
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
23 changes: 23 additions & 0 deletions
23
.../src/app/dialogs/share-playground-link-dialog/share-playground-link-dialog.component.html
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,23 @@ | ||
<div class="container"> | ||
<div matDialogTitle>Temporäre Datenbank URI</div> | ||
<mat-dialog-content style="max-height: 100%; overflow: hidden"> | ||
<mat-card-content class="content"> | ||
<mat-label> | ||
<h3>{{ data.message }}</h3> | ||
</mat-label> | ||
<div class="uri"> | ||
<mat-label | ||
><i>{{ data.uri }}</i></mat-label | ||
> | ||
<button mat-icon-button (click)="copyURI()" matTooltip="URI kopieren"> | ||
<mat-icon>content_copy</mat-icon> | ||
</button> | ||
</div> | ||
</mat-card-content> | ||
</mat-dialog-content> | ||
<mat-dialog-actions class="actions"> | ||
<button mat-flat-button color="warn" (click)="closeDialog()"> | ||
Abbrechen | ||
</button> | ||
</mat-dialog-actions> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
.../src/app/dialogs/share-playground-link-dialog/share-playground-link-dialog.component.scss
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,25 @@ | ||
.container { | ||
height: 100%; | ||
} | ||
|
||
.actions { | ||
display: flex; | ||
justify-content: flex-end; | ||
button { | ||
margin-left: 16px; | ||
} | ||
} | ||
|
||
.content { | ||
display: block; | ||
margin-top: 10px; | ||
} | ||
|
||
.uri{ | ||
margin-top: 30px; | ||
button { | ||
margin-left: 20px; | ||
} | ||
} | ||
|
||
|
38 changes: 38 additions & 0 deletions
38
...eb/src/app/dialogs/share-playground-link-dialog/share-playground-link-dialog.component.ts
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,38 @@ | ||
import { Component, Inject } from "@angular/core"; | ||
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog"; | ||
import { MatSnackBar } from "@angular/material/snack-bar"; | ||
|
||
@Component({ | ||
selector: "app-db-uri-link-dialog", | ||
templateUrl: "./share-playground-link-dialog.component.html", | ||
styleUrls: ["./share-playground-link-dialog.component.scss"], | ||
}) | ||
export class SharePlaygroundLinkDialogComponent { | ||
constructor( | ||
@Inject(MAT_DIALOG_DATA) | ||
public data: { | ||
message: string; | ||
uri: string; | ||
}, | ||
public dialogRef: MatDialogRef<SharePlaygroundLinkDialogComponent>, | ||
private snackbar: MatSnackBar | ||
) {} | ||
|
||
copyURI() { | ||
navigator.clipboard.writeText(this.data.uri).then( | ||
() => { | ||
this.snackbar.open("URI erfolgreich kopiert!", "Ok", { | ||
duration: 3000, | ||
}); | ||
}, | ||
(error) => { | ||
console.error("URI konnte nicht kopiert werden: ", error); | ||
this.snackbar.dismiss(); | ||
} | ||
); | ||
} | ||
|
||
closeDialog() { | ||
this.dialogRef.close({ success: false }); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,3 +8,7 @@ interface ResponseTable { | |
head: string[]; | ||
rows: string[]; | ||
} | ||
|
||
export interface SQLPlaygroundShare { | ||
url: string; | ||
} |
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.