Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dotorg plugin update check #489

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scripts/setup-test-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ create_test_credentials () {
local PASSWORD_PROTECTED_POST_ID
local PASSWORD_PROTECTED_COMMENT_ID
local PASSWORD_PROTECTED_COMMENT_AUTHOR
local WORDPRESS_VERSION
SITE_URL="http://localhost"
ADMIN_USERNAME="[email protected]"
ADMIN_PASSWORD="$(wp user application-password create [email protected] test --porcelain)"
Expand All @@ -106,6 +107,8 @@ create_test_credentials () {
PASSWORD_PROTECTED_COMMENT_AUTHOR="setup-test-site.sh"
PASSWORD_PROTECTED_COMMENT_ID="$(wp comment create --comment_post_ID="$PASSWORD_PROTECTED_POST_ID" --comment_content="test_comment_for_password_protected_post" --comment_author="$PASSWORD_PROTECTED_COMMENT_AUTHOR" --porcelain)"

WORDPRESS_VERSION="$(wp core version)"

# Trash the post
wp post delete "$TRASHED_POST_ID"

Expand All @@ -126,6 +129,7 @@ create_test_credentials () {
password_protected_comment_id="$PASSWORD_PROTECTED_COMMENT_ID" \
password_protected_comment_author="$PASSWORD_PROTECTED_COMMENT_AUTHOR" \
trashed_post_id="$TRASHED_POST_ID" \
wordpress_core_version="$WORDPRESS_VERSION" \
> /app/test_credentials.json
}
create_test_credentials
Expand Down
4 changes: 3 additions & 1 deletion wp_api/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ pub struct PluginDeleteResponse {
pub previous: PluginWithEditContext,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, uniffi::Record)]
#[derive(
Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, uniffi::Record,
)]
#[serde(transparent)]
pub struct PluginSlug {
pub slug: String,
Expand Down
4 changes: 2 additions & 2 deletions wp_api/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub struct WpNetworkRequestBody {
}

impl WpNetworkRequestBody {
fn new(body: Vec<u8>) -> Self {
pub fn new(body: Vec<u8>) -> Self {
Self { inner: body }
}
}
Expand Down Expand Up @@ -457,7 +457,7 @@ impl Debug for WpNetworkResponse {
}
}

#[derive(Debug, Clone, uniffi::Enum)]
#[derive(Debug, PartialEq, Eq, Clone, uniffi::Enum)]
pub enum RequestMethod {
GET,
POST,
Expand Down
21 changes: 20 additions & 1 deletion wp_api/src/wordpress_org/client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
request::{endpoint::WpEndpointUrl, RequestExecutor, WpNetworkRequest, WpNetworkResponse},
RequestExecutionError,
wordpress_org::update_check::UpdateCheckRequest,
ParsedUrl, PluginWithViewContext, RequestExecutionError,
};
use serde::de::DeserializeOwned;
use std::{result::Result, sync::Arc};
use url::Url;

use super::plugin_directory::{PluginInformation, QueryPluginResponse};
use super::update_check::UpdateCheckResponse;

#[derive(Debug, uniffi::Object)]
pub struct WordPressOrgApiClient {
Expand Down Expand Up @@ -46,6 +48,21 @@ impl WordPressOrgApiClient {
let request = Self::search_plugins_request(search, page, page_size);
self.execute(request).await
}

pub async fn check_plugin_updates(
&self,
wordpress_core_version: String,
site_url: Arc<ParsedUrl>,
plugins: Vec<PluginWithViewContext>,
) -> Result<UpdateCheckResponse, WordPressOrgApiClientError> {
let site_url = Arc::unwrap_or_clone(site_url);
match UpdateCheckRequest::new(wordpress_core_version, site_url, plugins).try_into() {
Ok(request) => self.execute(request).await,
Err(e) => Err(WordPressOrgApiClientError::RequestEncodingError {
reason: e.to_string(),
}),
}
}
}

impl WordPressOrgApiClient {
Expand Down Expand Up @@ -147,6 +164,8 @@ impl WordPressOrgApiPluginDirectoryCategory {

#[derive(Debug, PartialEq, Eq, thiserror::Error, uniffi::Error)]
pub enum WordPressOrgApiClientError {
#[error("Failed to encode request. Reason: {}", reason)]
RequestEncodingError { reason: String },
#[error(
"Request execution failed!\nStatus Code: '{:?}'.\nResponse: '{}'",
status_code,
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/wordpress_org/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mod de;

pub mod client;
pub mod plugin_directory;
pub mod update_check;
Loading
Loading