* Improve media deletion logic
Media replacements for avatars, banners, and icons now only delete previously
used media if it was uploaded by the person performing the change or if that
person is an admin.
Removing avatars, banners, and icons has previously incorrectly retained them,
this has also been addressed by using the same deletion logic for both
replacements with new media and also removal of media in those places.
Updating community metadata now validates that the user has appropriate
permissions before executing media replacement code to delete old media.
Media deletions via API now validate that the user performing the deletion
either owns the upload or is an admin. This is a partial backport of #5317 and
#5588 without the associated DB migrations and the requirement of having a
correct pict-rs API key set up in Lemmy's configuration. The media deletion
token provided via API is now completely ignored and Lemmy only evaluates media
ownership or admin status to decide whether deletion is allowed.
For community banner and icon updates this no longer deletes old media unless
it's been uploaded by the current user or the person changing it is an admin.
Cleanup of old media in these cases will return in 1.0, which has a different
approach to dealing with this type of media.
* trigger ci
* Automatically marking posts created in an NSFW community as NSFW. (#5310)
* Automatically marking posts created in an NSFW community as NSFW.
- Context: https://github.com/LemmyNet/lemmy-ui/issues/2885
* Update crates/api_crud/src/post/create.rs
Co-authored-by: Nutomic <me@nutomic.com>
---------
Co-authored-by: Nutomic <me@nutomic.com>
---------
fixes https://github.com/LemmyNet/lemmy-ui/issues/3114
* Ensure new posts in NSFW communities are marked NSFW
Clients exposing the NSFW setting to users will typically do so by providing a
checkbox, which is either checked or unchecked, but there is no third option
to let the server decide. As a result, virtually all posts created through
user interfaces will have a bool value for NSFW, so this logic likely is used
only for posts created by scripts/bots.
In #5310 the behavior for new posts was changed to default the NSFW flag to
the community's NSFW setting, but it only did so as a default if no value was
provided when creating a post via API.
This changes the logic to force all new posts created via API or received from
federation to be NSFW if the community they're posted in is marked NSFW,
otherwise use the value provided by the creator, with a default of false if
nothing is provided.
It also ensures that this logic is used for filtering out NSFW posts on
instances blocking NSFW content.
backports #5649
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Register users in a transaction.
* Replace build_transactions with async transactions.
backport of #5480
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Enable site languages for new user (fixes#5234) (#5235)
* Enable site languages for new user (fixes#5234)
* test coverage
This is backported from f6de3b0388https://github.com/LemmyNet/lemmy/pull/5235f6de3b0388
* Install Diesel CLI with `--locked` to ensure compatibility with rust version
* Using different corepack install method to fix corepack bug. (#5379)
- https://github.com/nodejs/corepack/issues/612
---------
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Ignore zero values when setting rate limits (fixes#4280)
Havent bothered to add an error message for such an uncommon case.
* fmt
* reorder, add test
* Adding a URL max length error.
- Also increasing the post.url max length to 2000 (seems standard)
- I ran into this when fixing torrent support, which often use longer
urls.
* Fixing sql_format.
* pass local user to send local notif
* pass local user to all crud calls
* execution of command "cargo +nightly fmt"
* Formatting and mode fixes.
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
* Make sure you can view your moderated deleted and removed communities.
- The front end checks to see whether you are a mod, in order to be
able to restore deleted / removed communities. This removes a filter
which prevents that.
- Fixes#4911
* Only show deleted communities to creator, and removed to admins.
* Addressing PR comments.
* Adding checks for higher admin and mod.
* Adding admin/mod checks for ban and comment removal.
* Combining mod or admin check with an SQL union.
* Making community ban or add mod also allow higher admins.
* Making sure remove post also checks higher mods or admins.
* Add unit test for is_higher_mod_or_admin_check
* Fixing comment.
* Addressing PR comments.
* Get rid of pointless wrapper functions, return lemmyresult directly.
* Fixing not being able to create comments on local community posts.
- This was caused by not passing my_person_id into various
`CommentView::read` functions.
- Fixes#4853
* Refactoring views to use local_user, rather than person
* Addressing PR comments.
* Fixing API tests.
* Allow empty string to clear URL-type DB fields.
- To address difficulties with clearing URL-type fields like
avatars, banners, site icons, this PR turns the URL type form
fields into strings.
- This allows an empty string to be used as a "clear data", as
in the case with the regular text form fields.
- Also includes various cleanups.
- Fixes#4777
- Context: #2287
* Fixing comment.
* Use Option<&str> and deref.
---------
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* After creating a comment, update the unread comments for the post.
- Fixes#3863
* Addressing PR comments.
* Add comment.
---------
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* Adding an image_details table to store image dimensions.
- Adds an image_details table, which stores the height,
width, and content_type for local and remote images.
- For LocalImages, this information already comes back with
the upload.
- For RemoteImages, it calls the pictrs details endpoint.
- Fixed some issues with proxying non-image urls.
- Fixes#3328
- Also fixes#4703
* Running sql format.
* Running fmt.
* Don't fetch metadata in background for local API requests.
* Dont export remote_image table to typescript.
* Cleaning up validate.
* Dont proxy url.
* Fixing tests, fixing issue with federated thumbnails.
* Fix tests.
* Updating corepack, fixing issue.
* Refactoring image inserts to use transactions.
* Use select exists again.
* Fixing imports.
* Fix test.
* Removing pointless backgrounded metadata generation version.
* Removing public pictrs details route.
* Fixing clippy.
* Fixing proxy image fetching. Fixes#4703
- This extracts only the proxy image fixes from #4704, leaving off
thumbnails.
* Fix test.
* Addressing PR comments.
* Address PR comments 2.
---------
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
- Diesel ordinarily throws an error when no results are returned for a
single fetch, which is a bit confusing. This PR ensures that the
missing value cases are all caught, and wrapped with new LemmyErrors,
rather than diesel errors.
- Fixes#4601
* Fixing bug where comment replies wouldn't be sent to blocked instances.
- Instance blocks should only affect communities, not comments.
- Fixes#4590
* Revert "Fixing bug where comment replies wouldn't be sent to blocked instances."
This reverts commit 1349aa351a.
* Only block replies from the community's instance id.
- Also refactor send_local_notifs slightly, since it has to fetch the
community now.
- Fixes#4590
---------
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* Generate post thumbnail/metadata in background (ref #4529)
* fix api test
* Apply suggestions from code review
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* fix test
---------
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* On registration, automatically set content languages from accept header
* no need to set site language or default language for new user anymore
* fix test
* fix langs
* avoid duplicate writing of new user languages
* Add a blocklist for URLs.
* Fix SQL format
* Make clippy happy.
* Use regex for URL matching.
* Escape regex chars in URLs.
* Use post for modification.
* Make URL block regex static and remove API routes.
* Add date fields to table and use transaction.
* Use Cache for blocklist.
* Rename check_links + move list to parameters of process_markdown.
* SQL format.
* Format, again.
* Remove println.
* Add API test.
* Set a shorter lifetime for regex in debug mode.
* Add missing macro.
* Update lemmy-js-client
* Update api_test/pnpm-lock.yaml
* Don't break other tests
* Use different URL for test
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Nutomic <me@nutomic.com>
* Expose LemmyErrorType in lemmy_api_common
* Make conditional compilation gates for utils
* Make it so api_common doesn't pull in unnecessary deps
* Make error type non exhaustive
* Fix formatting
* Format toml
* Add some convenience derives to LemmyError
* Simplify features
* Fix CI compile error
---------
Co-authored-by: SleeplessOne1917 <insomnia-void@protonmail.com>