diff --git a/api_tests/package.json b/api_tests/package.json index 14f603024..ef47bf192 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-instance-blocks.2", + "lemmy-js-client": "0.20.0-instance-blocks.5", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index aa4166a61..a95e80726 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-instance-blocks.2 - version: 0.20.0-instance-blocks.2 + specifier: 0.20.0-instance-blocks.5 + version: 0.20.0-instance-blocks.5 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-instance-blocks.2: - resolution: {integrity: sha512-R7+O/jGSvl7URWy/Gp4WRdH9EjkDmo5GRbQwJMOSM2HmFi9PIzcMynYbrNC869pbnI8S/XsitVfv9sLTuthpDg==} + lemmy-js-client@0.20.0-instance-blocks.5: + resolution: {integrity: sha512-wDuRFzg32lbbJr4cNmd+cbzjgw+okw2/d5AujYjAm4gv0OEFfsYhP3QQ2WscwUR5HJTdzsR7IIyiBnvmaEUzUw==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-instance-blocks.2: {} + lemmy-js-client@0.20.0-instance-blocks.5: {} leven@3.1.0: {} diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index d10448aba..60f8bef76 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -169,36 +169,30 @@ export async function setupLogins() { rate_limit_comment: 999, rate_limit_search: 999, }; - - // Set the blocks and auths for each - editSiteForm.allowed_instances = [ - "lemmy-beta", - "lemmy-gamma", - "lemmy-delta", - "lemmy-epsilon", - ]; await alpha.editSite(editSiteForm); - const params: AdminAllowInstanceParams = { - instance_id: 0, - allow: true, - reason: undefined - }; - await alpha.adminAllowInstance(params); - - editSiteForm.allowed_instances = betaAllowedInstances; await beta.editSite(editSiteForm); - - editSiteForm.allowed_instances = [ - "lemmy-alpha", - "lemmy-beta", - "lemmy-delta", - "lemmy-epsilon", - ]; await gamma.editSite(editSiteForm); + await delta.editSite(editSiteForm); + await epsilon.editSite(editSiteForm); + + // Set the blocksfor each + await allowInstance(alpha, "lemmy-beta"); + await allowInstance(alpha, "lemmy-gamma"); + await allowInstance(alpha, "lemmy-delta"); + await allowInstance(alpha, "lemmy-epsilon"); + + await allowInstance(beta, "lemmy-alpha"); + await allowInstance(beta, "lemmy-gamma"); + await allowInstance(beta, "lemmy-delta"); + await allowInstance(beta, "lemmy-epsilon"); + + await allowInstance(gamma, "lemmy-alpha"); + await allowInstance(gamma, "lemmy-beta"); + await allowInstance(gamma, "lemmy-delta"); + await allowInstance(gamma, "lemmy-epsilon"); // Setup delta allowed instance - editSiteForm.allowed_instances = ["lemmy-beta"]; - await delta.editSite(editSiteForm); + await allowInstance(delta, "lemmy-beta"); // Create the main alpha/beta communities // Ignore thrown errors of duplicates @@ -215,6 +209,16 @@ export async function setupLogins() { } } +async function allowInstance( + api: LemmyHttp,instance: string) { + const params: AdminAllowInstanceParams = { + instance, + allow: true, + reason: undefined + }; + await api.adminAllowInstance(params); +} + export async function createPost( api: LemmyHttp, community_id: number, diff --git a/crates/api/src/site/admin_allow_instance.rs b/crates/api/src/site/admin_allow_instance.rs index 8cb29a245..97e8279fe 100644 --- a/crates/api/src/site/admin_allow_instance.rs +++ b/crates/api/src/site/admin_allow_instance.rs @@ -28,18 +28,21 @@ pub async fn admin_allow_instance( Err(LemmyErrorType::CannotCombineFederationBlocklistAndAllowlist)?; } + let instance_id = Instance::read_or_create(&mut context.pool(), data.instance.clone()) + .await? + .id; let form = FederationAllowListForm { - instance_id: data.instance_id, + instance_id: instance_id, updated: None, }; if data.allow { FederationAllowList::allow(&mut context.pool(), &form).await?; } else { - FederationAllowList::unallow(&mut context.pool(), data.instance_id).await?; + FederationAllowList::unallow(&mut context.pool(), instance_id).await?; } let mod_log_form = AdminAllowInstanceForm { - instance_id: data.instance_id, + instance_id, admin_person_id: local_user_view.person.id, reason: data.reason.clone(), allowed: data.allow, diff --git a/crates/api/src/site/admin_block_instance.rs b/crates/api/src/site/admin_block_instance.rs index 6082f7534..d27ec252f 100644 --- a/crates/api/src/site/admin_block_instance.rs +++ b/crates/api/src/site/admin_block_instance.rs @@ -28,8 +28,11 @@ pub async fn admin_block_instance( Err(LemmyErrorType::CannotCombineFederationBlocklistAndAllowlist)?; } + let instance_id = Instance::read_or_create(&mut context.pool(), data.instance.clone()) + .await? + .id; let form = FederationBlockListForm { - instance_id: data.instance_id, + instance_id, expires: data.expires, updated: None, }; @@ -37,11 +40,11 @@ pub async fn admin_block_instance( if data.block { FederationBlockList::block(&mut context.pool(), &form).await?; } else { - FederationBlockList::unblock(&mut context.pool(), data.instance_id).await?; + FederationBlockList::unblock(&mut context.pool(), instance_id).await?; } let mod_log_form = AdminBlockInstanceForm { - instance_id: data.instance_id, + instance_id: instance_id, admin_person_id: local_user_view.person.id, blocked: data.block, reason: data.reason.clone(), diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 260175dcc..9babe423c 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -647,11 +647,11 @@ pub struct UserBlockInstanceParams { pub block: bool, } -#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct AdminBlockInstanceParams { - pub instance_id: InstanceId, + pub instance: String, pub block: bool, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option, @@ -659,11 +659,11 @@ pub struct AdminBlockInstanceParams { pub expires: Option>, } -#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] pub struct AdminAllowInstanceParams { - pub instance_id: InstanceId, + pub instance: String, pub allow: bool, #[cfg_attr(feature = "full", ts(optional))] pub reason: Option,