Compare commits

..

No commits in common. "f55f45d960a071fc39e2cb1b5e28a54756db9085" and "8588e1f71b0e72a645ac0eba1140ec391151d863" have entirely different histories.

3 changed files with 2 additions and 62 deletions

View File

@ -179,13 +179,6 @@ ORDER BY read_at DESC, created_at DESC;
.await .await
.unwrap(); .unwrap();
} }
pub(crate) async fn delete_by_link(db: &sqlx::Pool<Sqlite>, link: &str) {
sqlx::query!("DELETE FROM notification WHERE link=?", link)
.execute(db)
.await
.unwrap();
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -148,26 +148,6 @@ async fn new_blogpost(
} }
} }
#[derive(FromForm, Debug)]
struct BlogpostUnpublishedForm<'r> {
article_url: &'r str,
pw: &'r str,
}
#[post("/", data = "<blogpost>")]
async fn blogpost_unpublished(
db: &State<SqlitePool>,
blogpost: Form<BlogpostUnpublishedForm<'_>>,
config: &State<Config>,
) -> String {
if blogpost.pw == &config.wordpress_key {
Notification::delete_by_link(&db, blogpost.article_url).await;
"ACK".into()
} else {
"WRONG pw".into()
}
}
#[catch(403)] //forbidden #[catch(403)] //forbidden
fn forbidden_error() -> Flash<Redirect> { 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.") 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.")
@ -246,7 +226,6 @@ pub fn config(rocket: Rocket<Build>) -> Rocket<Build> {
.mount("/auth", auth::routes()) .mount("/auth", auth::routes())
.mount("/wikiauth", routes![wikiauth]) .mount("/wikiauth", routes![wikiauth])
.mount("/new-blogpost", routes![new_blogpost]) .mount("/new-blogpost", routes![new_blogpost])
.mount("/blogpost-unpublished", routes![blogpost_unpublished])
.mount("/log", log::routes()) .mount("/log", log::routes())
.mount("/planned", planned::routes()) .mount("/planned", planned::routes())
.mount("/ergo", ergo::routes()) .mount("/ergo", ergo::routes())

View File

@ -78,6 +78,7 @@ add_filter( 'authenticate', 'rot_auth', 10, 3 );
Add the following code to `wp-content/themes/bravada/functions.php`: Add the following code to `wp-content/themes/bravada/functions.php`:
``` ```
function send_article_url_on_publish($new_status, $old_status, $post) { function send_article_url_on_publish($new_status, $old_status, $post) {
// Check if the post is transitioning to 'publish' status // Check if the post is transitioning to 'publish' status
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') { if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') {
@ -92,7 +93,7 @@ function send_article_url_on_publish($new_status, $old_status, $post) {
$body = array( $body = array(
'article_url' => $article_url, 'article_url' => $article_url,
'article_title' => $article_title, 'article_title' => $article_title,
'pw' => "wordpress_key" 'pw' => "pw-as-specified-in-rockettoml"
); );
// Prepare the arguments for wp_remote_post // Prepare the arguments for wp_remote_post
@ -116,39 +117,6 @@ function send_article_url_on_publish($new_status, $old_status, $post) {
error_log('POST request sent successfully with article URL: ' . $article_url); error_log('POST request sent successfully with article URL: ' . $article_url);
} }
} }
if ($new_status != 'publish' && $old_status == 'publish' && $post->post_type == 'post') {
$article_url = get_permalink($post->ID);
// URL to send the POST request to
$api_url = 'https://app.rudernlinz.at/blogpost-unpublished';
// Prepare the data for the POST request
$body = array(
'article_url' => $article_url,
'pw' => "wordpress_key"
);
// Prepare the arguments for wp_remote_post
$args = array(
'body' => $body,
'timeout' => '5',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'cookies' => array()
);
// Send the POST request
$response = wp_remote_post($api_url, $args);
// Optional: Check if the request was successful
if (is_wp_error($response)) {
error_log('Failed to send POST request: ' . $response->get_error_message());
} else {
error_log('POST request sent successfully with article URL: ' . $article_url);
}
}
} }
// Hook the function to the 'transition_post_status' action // Hook the function to the 'transition_post_status' action