Compare commits
No commits in common. "0bf70947705e050e955f6bfda4920fa9af4ebe8c" and "0c770f6ddcf250e37002909f66c8849208323523" have entirely different histories.
0bf7094770
...
0c770f6ddc
2
fd
2
fd
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
scp root@128.140.64.118:/home/rowing/db.sqlite db.sqlite
|
scp read@128.140.64.118:/home/rowing/db.sqlite db.sqlite
|
||||||
#sqlite3 db.sqlite < seeds.sql
|
#sqlite3 db.sqlite < seeds.sql
|
||||||
|
|
||||||
|
@ -699,57 +699,46 @@ ORDER BY departure DESC
|
|||||||
pub async fn delete(&self, db: &SqlitePool, user: &User) -> Result<(), LogbookDeleteError> {
|
pub async fn delete(&self, db: &SqlitePool, user: &User) -> Result<(), LogbookDeleteError> {
|
||||||
Log::create(db, format!("{} deleted trip: {self:?}", user.name)).await;
|
Log::create(db, format!("{} deleted trip: {self:?}", user.name)).await;
|
||||||
|
|
||||||
if self.arrival.is_none() {
|
if user.has_role(db, "admin").await
|
||||||
if user.has_role(db, "admin").await
|
|| user.has_role(db, "Vorstand").await
|
||||||
|| user.has_role(db, "Vorstand").await
|
|| user.id == self.shipmaster
|
||||||
|| user.id == self.shipmaster
|
{
|
||||||
{
|
let now = Local::now().naive_local();
|
||||||
let now = Local::now().naive_local();
|
let difference = now - self.departure;
|
||||||
let difference = now - self.departure;
|
if difference > Duration::hours(1) {
|
||||||
if difference > Duration::hours(1) {
|
let vorstand = Role::find_by_name(db, "Vorstand").await.unwrap();
|
||||||
let vorstand = Role::find_by_name(db, "Vorstand").await.unwrap();
|
let logbook = LogbookWithBoatAndRowers::from(db, self.clone()).await;
|
||||||
let logbook = LogbookWithBoatAndRowers::from(db, self.clone()).await;
|
let mut msg = format!("{} hat folgenden Logbuch-Eintrag jetzt gelöscht, welcher bereits vor über einer Stunde begonnen wurde: Schiffsführer: {}, Steuerperson: {}, Abfahrt: {}", user.name, logbook.steering_user.name, logbook.steering_user.name, logbook.logbook.departure.format("%Y-%m-%d %H:%M"));
|
||||||
let mut msg = format!("{} hat folgenden Logbuch-Eintrag jetzt gelöscht, welcher bereits vor über einer Stunde begonnen wurde: Schiffsführer: {}, Steuerperson: {}, Abfahrt: {}", user.name, logbook.steering_user.name, logbook.steering_user.name, logbook.logbook.departure.format("%Y-%m-%d %H:%M"));
|
if let Some(destination) = logbook.logbook.destination {
|
||||||
if let Some(destination) = logbook.logbook.destination {
|
msg.push_str(&format!(", Ziel: {}", destination));
|
||||||
msg.push_str(&format!(", Ziel: {}", destination));
|
} else {
|
||||||
} else {
|
msg.push_str(", kein Ziel eingegeben");
|
||||||
msg.push_str(", kein Ziel eingegeben");
|
}
|
||||||
|
msg.push_str(", Ruderer: ");
|
||||||
|
let mut it = logbook.rowers.clone().into_iter().peekable();
|
||||||
|
while let Some(rower) = it.next() {
|
||||||
|
msg.push_str(&rower.name);
|
||||||
|
if it.peek().is_some() {
|
||||||
|
msg.push_str(" + ");
|
||||||
}
|
}
|
||||||
msg.push_str(", Ruderer: ");
|
|
||||||
let mut it = logbook.rowers.clone().into_iter().peekable();
|
|
||||||
while let Some(rower) = it.next() {
|
|
||||||
msg.push_str(&rower.name);
|
|
||||||
if it.peek().is_some() {
|
|
||||||
msg.push_str(" + ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::create_for_role(
|
|
||||||
db,
|
|
||||||
&vorstand,
|
|
||||||
&msg,
|
|
||||||
"Ungewöhnliches Verhalten",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
Notification::create_for_role(
|
||||||
.execute(db)
|
db,
|
||||||
.await
|
&vorstand,
|
||||||
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
&msg,
|
||||||
return Ok(());
|
"Ungewöhnliches Verhalten",
|
||||||
}
|
None,
|
||||||
} else {
|
None,
|
||||||
// Only admins can delete completed logbook entries
|
)
|
||||||
if user.has_role(db, "admin").await {
|
.await;
|
||||||
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
|
||||||
.execute(db)
|
|
||||||
.await
|
|
||||||
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
||||||
|
.execute(db)
|
||||||
|
.await
|
||||||
|
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(LogbookDeleteError::NotYourEntry)
|
Err(LogbookDeleteError::NotYourEntry)
|
||||||
}
|
}
|
||||||
|
@ -400,11 +400,6 @@ async fn home(
|
|||||||
async fn delete(db: &State<SqlitePool>, logbook_id: i64, user: DonauLinzUser) -> Flash<Redirect> {
|
async fn delete(db: &State<SqlitePool>, logbook_id: i64, user: DonauLinzUser) -> Flash<Redirect> {
|
||||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||||
if let Some(logbook) = logbook {
|
if let Some(logbook) = logbook {
|
||||||
let redirect = if logbook.arrival.is_some() {
|
|
||||||
"/log/show"
|
|
||||||
} else {
|
|
||||||
"/log"
|
|
||||||
};
|
|
||||||
Log::create(
|
Log::create(
|
||||||
db,
|
db,
|
||||||
format!("User {} tries to delete log entry {logbook_id}", &user.name),
|
format!("User {} tries to delete log entry {logbook_id}", &user.name),
|
||||||
@ -412,11 +407,11 @@ async fn delete(db: &State<SqlitePool>, logbook_id: i64, user: DonauLinzUser) ->
|
|||||||
.await;
|
.await;
|
||||||
match logbook.delete(db, &user).await {
|
match logbook.delete(db, &user).await {
|
||||||
Ok(_) => Flash::success(
|
Ok(_) => Flash::success(
|
||||||
Redirect::to(redirect),
|
Redirect::to("/log"),
|
||||||
format!("Eintrag {} von {} gelöscht!", logbook_id, user.name),
|
format!("Eintrag {} gelöscht!", logbook_id),
|
||||||
),
|
),
|
||||||
Err(LogbookDeleteError::NotYourEntry) => Flash::error(
|
Err(LogbookDeleteError::NotYourEntry) => Flash::error(
|
||||||
Redirect::to(redirect),
|
Redirect::to("/log"),
|
||||||
"Du hast nicht die Berechtigung, den Eintrag zu löschen!",
|
"Du hast nicht die Berechtigung, den Eintrag zu löschen!",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -262,12 +262,6 @@
|
|||||||
<input type="hidden" name="logtype" value="{{ log.logtype }}" />
|
<input type="hidden" name="logtype" value="{{ log.logtype }}" />
|
||||||
<input type="submit" value="Updaten" />
|
<input type="submit" value="Updaten" />
|
||||||
</form>
|
</form>
|
||||||
<a href="/log/{{ log.id }}/delete"
|
|
||||||
class="w-28 btn btn-alert"
|
|
||||||
onclick="return confirm('Willst du diesen Logbucheintrag wirklich löschen?');">
|
|
||||||
{% include "includes/delete-icon" %}
|
|
||||||
Löschen
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user