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

Add new setting to block NSFW content #5436

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

flamingo-cant-draw
Copy link
Collaborator

@flamingo-cant-draw flamingo-cant-draw commented Feb 17, 2025

Block NSFW posts or communities from being created via either the API or federation.

Depends on LemmyNet/lemmy-js-client#500

@Nutomic
Copy link
Member

Nutomic commented Feb 17, 2025

Not sure if this makes sense, is there any issue where it was discussed? At least it should be possible to make nsfw posts in remote communities which allow nsfw content.

@flamingo-cant-draw
Copy link
Collaborator Author

Sorry, I should've added more context. This was prompted from the feddit.uk admin chat where we've been discussing how we handle our obligations under the Online Safety Act and one of the big things it tries to tackle is children accessing pornography. Basically, we're liable to face a big fine if we allow users to access adult content without first verifying that they're adults. Instead of trying to do age verification, we'd prefer not to host adult content in the first place (host in this case includes posts made by non-local users).

At least it should be possible to make nsfw posts in remote communities which allow nsfw content.

I can't imagine an admin only being OK hosting adult content if it's in a non-local community.

@Nutomic
Copy link
Member

Nutomic commented Feb 17, 2025

Ah with that explanation it makes sense. However there are probably many instances which dont want to be so strict, so this behaviour should be a separate setting.

@dessalines
Copy link
Member

Agree, the content_warning.is_some() means your entire site is nsfw. If its None, it doesn't necessarily mean you want to disallow either local or federated nsfw content.

So we probably need a separate boolean column in local_site for this, probably named something like dissallow_nsfw_content

@flamingo-cant-draw flamingo-cant-draw changed the title Block NSFW content on instances with it disabled Add new setting to block NSFW content Feb 19, 2025
Comment on lines 55 to +58
"postgres",
"serde_json",
"uuid",
"64-column-tables",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured this would be OK given it's already happening in #5407

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's fine.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, this looks really good, and a lot of instances will probably use this.

Up to @Nutomic as to whether to merge this before or after the large aggregates-removal PR.


// If NSFW is not allowed, reject new communities marked NSFW and
// remove communities that update to be NSFW
let nsfw_disallowed = local_site.is_some_and(|s| s.disallow_nsfw_content);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use the same function you created. You might need to make local_site into an &Option<LocalSite>, like I'm seeing a few of the other functions in api_common/utils

Side point but @Nutomic I'm seeing this let local_site_data = local_site_data_cached(&mut context.pool()).await? in some places, and other places it runs LocalSite::read(...

Might be good to make an issue about going over all those in the apub code, and making them all use the cached version.

Copy link
Member

@Nutomic Nutomic Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalSite::read is also cached so thats fine. However I found that slur filter handling is unnecessarily complicated, opened #5442 for that.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW @flamingo-cant-draw would you be able to help become a lemmy maintainer? It'd be a huge help.

If so, link me your matrix id so we can add you to a maintainers chat, and I'll get you added as a maintainer on github also.

Comment on lines 157 to 167
let block_for_nsfw = check_nsfw_allowed(group.sensitive, local_site.as_ref());
let removed = if let Err(e) = block_for_nsfw {
let c = ApubCommunity::read_from_id(group.id.inner().clone(), context).await?;
if c.is_some() {
Some(true)
} else {
Err(e)?
}
} else {
None
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt you need to read the community. Probably this is enough.

// Your previous comment
let removed = check_nsfw_allowed(group.sensitive, local_site.as_ref()).is_err();

// posts that get updated to be NSFW
let block_for_nsfw = check_nsfw_allowed(page.sensitive, local_site.as_ref());
if block_for_nsfw.is_err() {
let post = ApubPost::read_from_id(page.id.inner().clone(), context).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I don't think you need to read the post, you already have the url above for purging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I did this to see if the post already existed, but thinking about it I could just ignore NotFound errors from ApubPost::delete to avoid the extra db query.

@flamingo-cant-draw
Copy link
Collaborator Author

@dessalines Sure, I'd love to help! My matrix username is @flamingos-cant:matrix.org.

@dessalines
Copy link
Member

Sweet, I'll get you added shortly.

Comment on lines 155 to 158
// If NSFW is not allowed, then remove NSFW communities
let removed = check_nsfw_allowed(group.sensitive, local_site.as_ref())
.map_err(|_err| true)
.err();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just be able to use .is_err()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to limit this to be either Some(true) or None to avoid unintentionally unremoving a community.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm. There's probably a .err_and_then .

If not, just use |_| on L157

@dessalines dessalines requested a review from Nutomic March 1, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants