Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,7 @@ class UsersEndpointTest {

@Test
fun testUserListRequestWithHasPublishedPostsParam() = runTest {
// TODO: Add default values to the binding constructor from Rust
val params = UserListParams(
page = null,
perPage = null,
search = null,
exclude = emptyList(),
include = emptyList(),
offset = null,
order = null,
orderby = null,
slug = emptyList(),
roles = emptyList(),
capabilities = emptyList(),
who = null,
hasPublishedPosts = WpApiParamUsersHasPublishedPosts.PostTypes(listOf("post", "page"))
)
val result = users.list.withEditContext(params)
Expand Down Expand Up @@ -95,20 +82,7 @@ class UsersEndpointTest {

@Test
fun testErrorUserListRequestWithHasPublishedPostsInvalidParam() = runTest {
// TODO: Add default values to the binding constructor from Rust
val params = UserListParams(
page = null,
perPage = null,
search = null,
exclude = emptyList(),
include = emptyList(),
offset = null,
order = null,
orderby = null,
slug = emptyList(),
roles = emptyList(),
capabilities = emptyList(),
who = null,
hasPublishedPosts = WpApiParamUsersHasPublishedPosts.PostTypes(listOf("foo"))
)
val result = users.list.withEditContext(params)
Expand Down
26 changes: 26 additions & 0 deletions wp_api/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,49 @@ impl Display for WpApiParamUsersHasPublishedPosts {
pub struct UserListParams {
/// Current page of the collection.
/// Default: `1`
#[uniffi(default = None)]
pub page: Option<u32>,
/// Maximum number of items to be returned in result set.
/// Default: `10`
#[uniffi(default = None)]
pub per_page: Option<u32>,
/// Limit results to those matching a string.
#[uniffi(default = None)]
pub search: Option<String>,
/// Ensure result set excludes specific IDs.
#[uniffi(default = [])]
pub exclude: Vec<UserId>,
/// Limit result set to specific IDs.
#[uniffi(default = [])]
pub include: Vec<UserId>,
/// Offset the result set by a specific number of items.
#[uniffi(default = None)]
pub offset: Option<u32>,
/// Order sort attribute ascending or descending.
/// Default: `asc`
/// One of: `asc`, `desc`
#[uniffi(default = None)]
pub order: Option<WpApiParamOrder>,
/// Sort collection by user attribute.
/// Default: `name`
/// One of: `id`, `include`, `name`, `registered_date`, `slug`, `include_slugs`, `email`, `url`
#[uniffi(default = None)]
pub orderby: Option<WpApiParamUsersOrderBy>,
/// Limit result set to users with one or more specific slugs.
#[uniffi(default = [])]
pub slug: Vec<String>,
/// Limit result set to users matching at least one specific role provided. Accepts csv list or single role.
#[uniffi(default = [])]
pub roles: Vec<String>,
/// Limit result set to users matching at least one specific capability provided. Accepts csv list or single capability.
#[uniffi(default = [])]
pub capabilities: Vec<String>,
/// Limit result set to users who are considered authors.
/// One of: `authors`
#[uniffi(default = None)]
pub who: Option<WpApiParamUsersWho>,
/// Limit result set to users who have published posts.
#[uniffi(default = None)]
pub has_published_posts: Option<WpApiParamUsersHasPublishedPosts>,
}

Expand Down Expand Up @@ -237,6 +250,7 @@ pub struct UserCreateParams {
pub slug: Option<String>,
/// Roles assigned to the user.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[uniffi(default = [])]
pub roles: Vec<String>,
/// Meta fields.
#[uniffi(default = None)]
Expand Down Expand Up @@ -267,40 +281,52 @@ impl UserCreateParams {
#[derive(Debug, Default, Serialize, uniffi::Record)]
pub struct UserUpdateParams {
/// Display name for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// First name for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub first_name: Option<String>,
/// Last name for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_name: Option<String>,
/// The email address for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
/// URL of the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
/// Description of the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Locale for the user.
/// One of: , `en_US`
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<String>,
/// The nickname for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub nickname: Option<String>,
/// An alphanumeric identifier for the user.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub slug: Option<String>,
/// Roles assigned to the user.
#[serde(skip_serializing_if = "Vec::is_empty")]
#[uniffi(default = [])]
pub roles: Vec<String>,
/// Password for the user (never included).
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
/// Meta fields.
#[uniffi(default = None)]
#[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<String>,
}
Expand Down