38 Commits

Author SHA1 Message Date
Christophe Bliard adf9cc1669 [68047] Prevent FrozenError in Attachments::ExtractFulltextJob
There is a bug in the plaintext gem in its `Plaintext::Resolve#text`: it
executes external commands to extract text from files. This can return
`nil` when it has no output, and it's then converted to a string using
`to_s`.

`nil.to_s` returns a frozen empty string since ruby 2.7. When it then
calls `text.gsub!(/\s+/m, ' ')` later in the `#text` method, the
`FrozenError` occurs.

The fix is to patch the `Plaintext::Resolver#text` method to create a
mutable copy of the text if it's frozen.
2025-10-08 16:21:58 +02:00
Christophe Bliard 643a58f801 Trigger virus scanning after completing direct upload to S3 storage
https://community.openproject.org/wp/67664

When storing attachments on S3, the file is not fully uploaded until the
direct upload finishes (hook called from client browser when file is
finished uploading).

The `FinishDirectUploadService#schedule_jobs` now calls
`attachment.enqueue_jobs` to ensure the same jobs are run on attachment
creation (useful when s3 storage is not used) and on attachment upload
completion. This means virus scanning job is now triggered correctly.
2025-09-24 12:21:58 +02:00
Christophe Bliard a69859f0ec [67642] Avoid error when attachment is not uploaded yet
https://community.openproject.org/wp/67642

Attachments::ExtractFulltextJob is run twice:
- one time on creation
- one time when the direct upload is completed

When it runs on creation, and the attachments are stored on S3, the
attachment is in 'prepared' status and is not complete yet.

Due to a bug in carrierwave which is fixed since June 2023 (see
https://github.com/carrierwaveuploader/carrierwave/issues/2524), the
`#local_file` method raises the error "NoMethodError: undefined method
'body' for nil:NilClass". There is a separate issue for upgrading this
dependency one day: https://community.openproject.org/wp/67626.

The fix is to call `#local_file` only if the attachment is readable.

Additionnally:
- error handling has been updated to raise the error instead of
  swallowing it silently, so well have proper reporting in AppSignal
  next time.
- when a custom S3 endpoint is used (for local testing with minio for
  instance), this custom endpoint is added to the CSP.

Co-authored-by: Jan Sandbrink <j.sandbrink@openproject.com>
2025-09-24 10:21:22 +02:00
ulferts 3ba3e8b74b work in review comments 2025-06-24 11:55:37 +02:00
ulferts 0ecd09b06b rename to allowlist 2025-06-24 11:19:26 +02:00
Jan Sandbrink 0b87e7543f Freeze string literals in specs
Rolling out frozen string literals further by freezing all
string literals in core specs.
2025-05-05 09:29:55 +02:00
Ivan Kuchin 8be9f2452f fix copyright years for files which got them from 38cae188ad 2024-08-16 19:27:44 +02:00
Ivan Kuchin 4911b8a149 remove years from copyrights (except for COPYRIGHT file) 2024-07-31 15:02:49 +02:00
ulferts 3b2121f733 Revert "Merge remote-tracking branch 'origin/release/13.4' into dev"
This reverts commit 40b2bbeb09, reversing
changes made to b4c6cb17cc.
2024-03-21 11:31:17 +01:00
Ivan Kuchin 7787e457a3 Revert "Merge branch 'dev' into release/13.4"
This reverts commit a901541269, reversing
changes made to e573ca00b7.
2024-03-20 20:19:08 +01:00
Ivan Kuchin 9e4934cd0a change quotes using rubocop --only Style/StringLiterals,Style/QuotedSymbols -a 2024-03-20 18:05:22 +01:00
Oliver Günther 2508ede65c Fix prepared upload specs 2024-02-20 09:37:03 +01:00
Christophe Bliard 8fa8584538 Run rubocop --autocorrect on all files
Only the safe cops have run. rubocop version is 1.59.0.
2024-01-05 15:27:09 +01:00
Christophe Bliard c795874f7f Update copyright year for 2024
command used: `rg -l 'Copyright \(C\) 2012-202\d the OpenProject' | xargs -n 100 sed -i -r 's/Copyright \(C\) 2012-202. the OpenProject/Copyright (C) 2012-2024 the OpenProject/'`
2024-01-02 16:23:54 +01:00
Christophe Bliard 4c2a9d0aa8 Enable RSpec zero monkey patching mode
The plan for RSpec 4.0 is to disable monkey patching.

See https://github.com/rspec/rspec-core/blob/main/features/configuration/zero_monkey_patching_mode.feature for details.
2023-05-31 19:22:29 +02:00
Christophe Bliard aa23106c11 lint: autocorrect RSpec/FactoryBot/ConsistentParenthesesStyle
command is

    rubocop -A --only RSpec/FactoryBot/ConsistentParenthesesStyle modules spec
2023-03-07 15:04:32 +01:00
Christophe Bliard 21a696ef9b Update copyright information for 2023 2022-12-30 15:51:26 +01:00
Christophe Bliard 48a4f1b6ad lint with rubocop --autocorrect (safe cops only) 2022-06-02 10:40:10 +02:00
Christophe Bliard a33524ef6d remove ruby magic comment for utf-8
ruby interprets source encoding as utf-8 since 2.0.0, making magic comment redundant and useless
2022-03-10 19:36:58 +01:00
Christophe Bliard bc8d423ec2 update copyright information for 2022 2022-03-01 17:05:59 +01:00
Christophe Bliard 47a297daae Fix argument alignment since f08bea3467 (#10129)
* Fix argument alignment since f08bea3467

The FactoryBot.* prefix has been removed in f08bea3467. Since then
rubocop complains about Layout/ArgumentAlignment. This commit fixes it.

* do not fix alignments for modules/*/spec yet

hoping to be under the limit of 65535 characters for reviewdog to report on rubocop errors
2022-02-02 21:48:06 +01:00
Oliver Günther f08bea3467 Remove FactoryBot.* prefix where applicable 2022-01-25 08:19:06 +01:00
Oliver Günther e9a08e64f0 Allow overriding whitelist in FinishDirectUploadJob 2021-11-04 13:25:36 +01:00
Markus Kahl d86e2787c7 Merge branch 'release/11.4' into dev 2021-10-20 13:44:48 +01:00
Oliver Günther 38907c3273 [39130] Validate the whitelist on finishing a direct upload
https://community.openproject.org/wp/39130
2021-10-14 16:17:50 +02:00
Oliver Günther 69eb40e7a3 Expect changed content_type 2021-09-20 09:24:16 +02:00
Oliver Günther ccfa29c728 Move license and copyright docs to root, fix names and references 2021-09-02 21:50:46 +02:00
Oliver Günther 7382822e12 [38085] Also send ATTACHMENT_CREATED on direct upload completed
https://community.openproject.org/wp/38085
2021-07-21 09:47:57 +02:00
Oliver Günther e9d7c374cc [37868] Whitelist for attachment mime types and extensions on upload (#9431)
* Add setting for whitelist

* Make attachments API BaseServices compatible

* Add prepare service and contract

* Correctly pass the filename to the UploadedFile

* Add presence check to filename

* Fix expected validation message

* We no longer raise a multipart error when metadata is empty

* Fix filesize validation on prepared uploads

* Add parser error if invalid metadata json

* When attachment is not saved, use filename property

* Return correct error message on JSON parser erroro

* Fix specs

* Use attachment upload representer

* Fix direct uploads mocks with new service layer

* Lint

* Fix export job using attachment service

* Fix IFC controller using attachment prepare service

* Fix export job

* RenameRename params_getter to params_source

* Fix mail handler using attachment service

* Fix usage of attachment create service in documents

* Reuse shared examples for document attachment spec

* Fix stubbed attachment service in export job spec

* Use admin user in backup spec

* Fix export job for bim

* Fix attachment integration spec

* Fix issues_controller spec

* Make budget resource spec reuse common examples

* Fix attachment parsing representer spec

* Replace prepare part of attachment spec into separate service spec

* Clear cache for login spec

* Convert document create/update into services

* Budget services

* Allow options to be passed to property twin

* Remove setting author on budget initialize

* Replace meetings update with services

* Replace ifc models attachment handling with services

* Don't check uploader if changed by system

* Fix uploader being changed by system

* Replace wiki page attach_files with attachable services

* Replace avatar  saving

* Replace snapshot attach_files

* Skip double validation when container present

* Set snapshot through attachment service

* Remove attach_files

* Validate content type in contract

* Enforce writing the content type without accepting user input

* Expect changed content_type

* Fix content of viewpoint image to get correct content type

* Fix tsv spec

* Add create contract spec

* Bypass whitelist in internal services when conflicting with user

* Fix expects in specs after whitelist bypass

* Render contract errors for wiki

* Add before_hook to bodied to allow to pre-authorize permissions

* Budget errors from contract

* Document errors from contract
2021-07-14 14:43:19 +02:00
ulferts 1bdd2ab9ae safe automatic fixes by rubocop (#8994) 2021-02-11 16:02:18 +01:00
ulferts cf385d53e6 Merge branch 'release/11.1' into dev 2021-01-19 11:08:38 +01:00
ulferts 2744673ec8 avoid updating the lock version on finishing an attachment upload (#8934)
If the lock version is increased, it might happen while the user is still editing the description. The user might have added an image to the description and continues typing. In the backend, the FinishDirectUploadJob is run before the user presses the checkmark to send the updated description. In that case, a 409 conflict would be signaled if the lock version were to be updated in the meantime.
2021-01-19 10:50:42 +01:00
ulferts 71491e2f52 Merge branch 'release/11.1' into dev 2021-01-18 17:48:27 +01:00
ulferts 38cae188ad Fix/journals on direct uploads (#8933)
* linting

* use Carrierwave's replacement for filename

This avoids having the name altered by Carrierwave later on in the Attachments::FinishDirectUploadJob job where the file is fetched and then the attachment is stored.

* separate cases for no attachment and no local file

* correct journalizing on direct upload

In case the container of an attachment is journalized, the container needs to have added a journal to it when an attachment is uploaded. Without that, the attachment is only picked up in the journals once the container is altered again (possibly by a different user). This will then lead to a history which does not reflect the actual upload.
2021-01-18 17:28:32 +01:00
ulferts 6140f4c7e9 update copyright to 2021 (#8925)
Updates the copyright to 2021 for all files that have a copyright. Files in our source code without the copyright header still do not receive one automatically. Additionally, backlisted files are also excluded.

Previously the copyright of chiliproject which references redmine stated a copyright of redmine up to and including 2017 which is not true for the code we have in here. Because of that I changed that to 2013
2021-01-13 17:47:45 +01:00
Markus Kahl c1b82bad00 direct uploads to S3 for attachments including IFC models
Co-authored-by: Oliver Günther <mail@oliverguenther.de>
2020-08-07 15:28:09 +01:00
Henriette Dinger bd7f4e4814 Update copyright notice 2020-01-15 11:31:26 +01:00
Jens Ulferts 57c8aeb5aa add job to cleanup uncontainered attachments 2018-06-04 09:11:35 +02:00