mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
feat: Expose plugin share metadata in shareContext (#21495)
Extends PluginSummary.shareContext with shareUrl and reader shareTargets
This commit is contained in:
committed by
GitHub
Unverified
parent
3444b0d60a
commit
114bac1409
@@ -98,8 +98,10 @@ pub struct RemotePluginSummary {
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct RemotePluginShareContext {
|
||||
pub remote_plugin_id: String,
|
||||
pub share_url: Option<String>,
|
||||
pub creator_account_user_id: Option<String>,
|
||||
pub creator_name: Option<String>,
|
||||
pub share_targets: Option<Vec<RemotePluginSharePrincipal>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -363,6 +365,8 @@ struct RemotePluginDirectoryItem {
|
||||
creator_name: Option<String>,
|
||||
#[serde(default)]
|
||||
share_url: Option<String>,
|
||||
#[serde(default)]
|
||||
share_principals: Option<Vec<RemotePluginDirectorySharePrincipal>>,
|
||||
installation_policy: PluginInstallPolicy,
|
||||
authentication_policy: PluginAuthPolicy,
|
||||
#[serde(rename = "status", default)]
|
||||
@@ -370,6 +374,15 @@ struct RemotePluginDirectoryItem {
|
||||
release: RemotePluginReleaseResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
struct RemotePluginDirectorySharePrincipal {
|
||||
principal_type: RemotePluginSharePrincipalType,
|
||||
principal_id: String,
|
||||
#[serde(default)]
|
||||
role: Option<String>,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
struct RemotePluginInstalledItem {
|
||||
#[serde(flatten)]
|
||||
@@ -831,8 +844,20 @@ fn remote_plugin_share_context(
|
||||
RemotePluginScope::Global => None,
|
||||
RemotePluginScope::Workspace => Some(RemotePluginShareContext {
|
||||
remote_plugin_id: plugin.id.clone(),
|
||||
share_url: plugin.share_url.clone(),
|
||||
creator_account_user_id: plugin.creator_account_user_id.clone(),
|
||||
creator_name: plugin.creator_name.clone(),
|
||||
share_targets: plugin.share_principals.as_ref().map(|principals| {
|
||||
principals
|
||||
.iter()
|
||||
.filter(|principal| principal.role.as_deref() == Some("reader"))
|
||||
.map(|principal| RemotePluginSharePrincipal {
|
||||
principal_type: principal.principal_type,
|
||||
principal_id: principal.principal_id.clone(),
|
||||
name: principal.name.clone(),
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,15 +107,17 @@ fn remote_plugin_json(plugin_id: &str) -> serde_json::Value {
|
||||
})
|
||||
}
|
||||
|
||||
fn remote_plugin_json_with_share_url(
|
||||
fn remote_plugin_json_with_share_url_and_principals(
|
||||
plugin_id: &str,
|
||||
share_url: Option<&str>,
|
||||
share_principals: serde_json::Value,
|
||||
) -> serde_json::Value {
|
||||
let mut plugin = remote_plugin_json(plugin_id);
|
||||
let serde_json::Value::Object(fields) = &mut plugin else {
|
||||
unreachable!("plugin json should be an object");
|
||||
};
|
||||
fields.insert("share_url".to_string(), json!(share_url));
|
||||
fields.insert("share_principals".to_string(), share_principals);
|
||||
plugin
|
||||
}
|
||||
|
||||
@@ -489,9 +491,23 @@ async fn list_remote_plugin_shares_fetches_created_workspace_plugins() {
|
||||
))
|
||||
.and(query_param_is_missing("pageToken"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"plugins": [remote_plugin_json_with_share_url(
|
||||
"plugins": [remote_plugin_json_with_share_url_and_principals(
|
||||
"plugins_123",
|
||||
Some("https://chatgpt.example/plugins/share/share-key-1"),
|
||||
json!([
|
||||
{
|
||||
"principal_type": "user",
|
||||
"principal_id": "user-owner",
|
||||
"role": "owner",
|
||||
"name": "Owner",
|
||||
},
|
||||
{
|
||||
"principal_type": "user",
|
||||
"principal_id": "user-reader",
|
||||
"role": "reader",
|
||||
"name": "Reader",
|
||||
},
|
||||
]),
|
||||
)],
|
||||
"pagination": {
|
||||
"next_page_token": "page-2"
|
||||
@@ -510,7 +526,29 @@ async fn list_remote_plugin_shares_fetches_created_workspace_plugins() {
|
||||
))
|
||||
.and(query_param("pageToken", "page-2"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
||||
"plugins": [remote_plugin_json_with_share_url("plugins_456", /*share_url*/ None)],
|
||||
"plugins": [remote_plugin_json_with_share_url_and_principals(
|
||||
"plugins_456",
|
||||
/*share_url*/ None,
|
||||
json!([
|
||||
{
|
||||
"principal_type": "user",
|
||||
"principal_id": "user-owner",
|
||||
"role": "owner",
|
||||
"name": "Owner",
|
||||
},
|
||||
{
|
||||
"principal_type": "user",
|
||||
"principal_id": "user-editor",
|
||||
"role": "editor",
|
||||
"name": "Editor",
|
||||
},
|
||||
{
|
||||
"principal_type": "user",
|
||||
"principal_id": "user-missing-role",
|
||||
"name": "Missing Role",
|
||||
},
|
||||
]),
|
||||
)],
|
||||
"pagination": empty_pagination_json(),
|
||||
})))
|
||||
.expect(1)
|
||||
@@ -540,8 +578,16 @@ async fn list_remote_plugin_shares_fetches_created_workspace_plugins() {
|
||||
name: "demo-plugin".to_string(),
|
||||
share_context: Some(RemotePluginShareContext {
|
||||
remote_plugin_id: "plugins_123".to_string(),
|
||||
share_url: Some(
|
||||
"https://chatgpt.example/plugins/share/share-key-1".to_string(),
|
||||
),
|
||||
creator_account_user_id: None,
|
||||
creator_name: None,
|
||||
share_targets: Some(vec![RemotePluginSharePrincipal {
|
||||
principal_type: RemotePluginSharePrincipalType::User,
|
||||
principal_id: "user-reader".to_string(),
|
||||
name: "Reader".to_string(),
|
||||
}]),
|
||||
}),
|
||||
installed: false,
|
||||
enabled: false,
|
||||
@@ -560,8 +606,10 @@ async fn list_remote_plugin_shares_fetches_created_workspace_plugins() {
|
||||
name: "demo-plugin".to_string(),
|
||||
share_context: Some(RemotePluginShareContext {
|
||||
remote_plugin_id: "plugins_456".to_string(),
|
||||
share_url: None,
|
||||
creator_account_user_id: None,
|
||||
creator_name: None,
|
||||
share_targets: Some(Vec::new()),
|
||||
}),
|
||||
installed: true,
|
||||
enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user