Compare commits

..

2 Commits

Author SHA1 Message Date
e040764902 Merge pull request 'first draft of sending blog post notifications' (#678) from send-blogpost-notification into staging
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m12s
CI/CD Pipeline / deploy-staging (push) Successful in 6m54s
CI/CD Pipeline / deploy-main (push) Has been skipped
Reviewed-on: #678
2024-08-18 21:33:36 +02:00
25161fc8e9 first draft of sending blog post notifications
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled
2024-08-18 21:30:14 +02:00
3 changed files with 46 additions and 0 deletions

View File

@ -5,3 +5,4 @@ limits = { file = "10 MiB", data-form = "10 MiB"}
smtp_pw = "8kIjlLH79Ky6D3jQ"
usage_log_path = "./usage.txt"
openweathermap_key = "c8dab8f91b5b815d76e9879cbaecd8d5"
wordpress_key = "KYplHPxd6Gtqjdx4Ruik"

View File

@ -118,6 +118,35 @@ fn unauthorized_error(req: &Request) -> Redirect {
Redirect::to("/auth")
}
#[derive(FromForm, Debug)]
struct NewBlogpostForm<'r> {
article_url: &'r str,
pw: &'r str,
}
#[post("/", data = "<blogpost>")]
async fn new_blogpost(
db: &State<SqlitePool>,
blogpost: Form<NewBlogpostForm<'_>>,
config: &State<Config>,
) -> String {
if blogpost.pw == &config.wordpress_key {
let member = Role::find_by_name(&db, "Donau Linz").await.unwrap();
Notification::create_for_role(
db,
&member,
&format!("auf unserer Website!"),
&format!("Neuer Blogpost"),
Some(blogpost.article_url),
None,
)
.await;
"ACK".into()
} else {
"WRONG pw".into()
}
}
#[catch(403)] //forbidden
fn forbidden_error() -> Flash<Redirect> {
Flash::error(Redirect::to("/"), "Keine Berechtigung für diese Aktion. Wenn du der Meinung bist, dass du das machen darfst, melde dich bitte bei it@rudernlinz.at.")
@ -187,6 +216,7 @@ pub struct Config {
smtp_pw: String,
usage_log_path: String,
pub openweathermap_key: String,
wordpress_key: String,
}
pub fn config(rocket: Rocket<Build>) -> Rocket<Build> {
@ -194,6 +224,7 @@ pub fn config(rocket: Rocket<Build>) -> Rocket<Build> {
.mount("/", routes![index, steering, impressum])
.mount("/auth", auth::routes())
.mount("/wikiauth", routes![wikiauth])
.mount("/new-blogpost", routes![new_blogpost])
.mount("/log", log::routes())
.mount("/planned", planned::routes())
.mount("/ergo", ergo::routes())

View File

@ -33,6 +33,13 @@
<div class="mt-1">{{ notification.message | safe }}</div>
</div>
<div>
{% if notification.link %}
<a href="{{ notification.link }}" class="inline-block">
<button class="btn btn-primary" type="button">
🔗
</button>
</a>
{% endif %}
{% if not notification.read_at %}
<a href="/notification/{{ notification.id }}/read" class="inline-block">
<button class="btn btn-primary" type="button">
@ -56,6 +63,13 @@
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
</small>
<div class="mt-1">{{ notification.message | safe }}</div>
{% if notification.link %}
<a href="{{ notification.link }}" class="inline-block">
<button class="btn btn-primary" type="button">
🔗
</button>
</a>
{% endif %}
</div>
{% endif %}
{% endfor %}