Merge pull request 'first draft of sending blog post notifications' (#678) from send-blogpost-notification into staging
Reviewed-on: #678
This commit is contained in:
commit
e040764902
@ -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"
|
||||
|
@ -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())
|
||||
|
@ -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> • {{ 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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user