fix setup

This commit is contained in:
Felix Ableitner 2024-11-26 11:58:32 +01:00
parent 1324963fb9
commit 1001e3f67a
6 changed files with 51 additions and 41 deletions

View file

@ -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",

View file

@ -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: {}

View file

@ -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,

View file

@ -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,

View file

@ -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(),

View file

@ -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<String>,
@ -659,11 +659,11 @@ pub struct AdminBlockInstanceParams {
pub expires: Option<DateTime<Utc>>,
}
#[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<String>,