41 Commits

Author SHA1 Message Date
Ivan Kuchin d664e70c5f handle comment attribute in all contracts 2026-02-25 20:07:02 +01:00
Alexander Brandon Coles 0091ee164d Freeze string literals in app/contracts
rubocop -A --only Style/FrozenStringLiteralComment,Layout/EmptyLineAfterMagicComment,Style/RedundantFreeze app/contracts
2025-07-18 17:51:41 +01:00
Jan Sandbrink c753ce6e30 Replace with_merged_former_errors by validate_and_merge_errors
The main problem with the previous method was that it only worked
if the contract being validated inside the block was sharing the same
errors object as the contract calling it. The old implementation
was incapable of incorporating errors from a contract that had its
own errors object.

In my opinion it's a code smell that our contracts use the #errors
of the model they are validating as the place to store their validation
result, however I didn't dare touching this yet, because changing that
would certainly be a huge change. I can also imagine that some places rely
on it for historic reasons (because using "classic" validations also
puts the errors on the model). However, I think that no two contracts
should RELY on using the SAME errors object, just because the way we implemented
them happens to cause them to share the same object.
2025-02-11 10:51:49 +01:00
Oliver Günther 12ee9e6b83 Merge remote-tracking branch 'origin/idea/56781-remove-years-from-copyrights' into dev 2024-08-06 10:17:59 +02:00
Ivan Kuchin 4911b8a149 remove years from copyrights (except for COPYRIGHT file) 2024-07-31 15:02:49 +02:00
Dombi Attila 2ed8c330a2 Move Project's available custom fields overrides to their corresponding Project contract class 2024-07-29 16:47:42 +03:00
Dombi Attila d1560336cf Restrict Project#all_available_custom_fields by the visible scope to apply the view_project_attributes permission on the Project schema api. 2024-07-29 16:47:42 +03:00
Christophe Bliard 71f0728898 Fix writable_attributes when redefining attributes in child classes
There were cases were the writable parameter of a parent contract would
take precedence of the child contract writable parameter when the parent
condition is a lambda: a child could say `writable: true` and it would
still be the parent `writable: -> { false }` that would "win" because
when reducing and evaluating `writable_conditions`, only lambda are
considered.

This commit fixes the issue by adding extensive tests and putting both
lambdas AND true/false values in the `writable_conditions` hash.
2024-07-18 17:13:19 +02:00
Dombi Attila 81a44b2484 [#53729] Remove project_custom_field_mapping and the projects aac patch
https://community.openproject.org/work_packages/53729
2024-06-17 16:02:11 +03:00
Ivan Kuchin 6678cab48d auto correct quotes 2024-03-28 18:22:34 +01:00
Jonas Jabari 8610e769f0 fixing project API 2024-02-28 15:48:28 +07:00
Richard "Virgo" Richter 9a530b6e0f Merge branch 'dev' into feature/50849_change_work_packages_status
# Conflicts:
#	spec/requests/api/v3/work_packages/update_resource_spec.rb
2024-01-08 08:39:36 +00: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
Richard "Virgo" Richter 722bb0c567 Fix of collect_ancestor_attributes to respect overrides in subclasses
Because collect_ancestor_attributes_by goes from the subclass attributes
and then combining them with the superclass attributes, merge overrides
more specific definitions (from subclass) with the more generic ones.
Instead, `reverse_merge!` can be used, even merging in place as the
attributes are duped first.
2023-12-19 12:54:41 +00:00
Richard "Virgo" Richter 3215192673 Feature 50849, WP :status_id overridden in CreateContract w/o permission
This fixes the status writability for new WPs without the need for
shortcut-hack in common BaseContract.
2023-12-19 10:04:08 +00:00
Richard "Virgo" Richter f8e307a7a0 Merge branch 'dev' into feature/50849_change_work_packages_status
# Conflicts:
#	lib/api/v3/work_packages/work_package_representer.rb
2023-11-28 09:16:09 +00:00
Klaus Zanders e35fce23f8 Fix permission check when the project is the model 2023-11-27 10:22:56 +01:00
Klaus Zanders f832824668 Use allowed_based_on_permission_context? in BaseContract 2023-11-27 10:22:46 +01:00
Richard "Virgo" Richter 234c0a750d Feature 50849, reduce_by_writable_permissions shortcut for new models
For new models, per-field permissions are not considered, only the
default permission (e.g. add_work_package).
This is may not be a final solution, but at this moment I don't know how
to distinguish between per-field permissions for edit and create cases.

This fixes more tests, but copy WP scenario required also explicit
`status_id` in the merge block in CopyService#copied_attributes.
This was previously done for `parent_id` as well, so it's not exactly
a precedent.
2023-11-13 14:14:48 +00:00
Klaus Zanders 8931c063cf Update allowed_to calls in contracts 2023-10-27 11:32:41 +02:00
ulferts 9ed32a276c extract method 2023-10-24 11:54:41 +02:00
ulferts cc83055668 remove no longer required method for falling back on unknown properties 2023-10-24 11:53:20 +02:00
ulferts 304154552d handle validating contract inside contract 2023-10-24 11:52:59 +02:00
ulferts 976fccb296 allow our models to have non existing attributes read for validation 2023-10-24 11:52:49 +02:00
ulferts 7c30a625b0 share model`s error object in contract 2023-10-24 11:52:37 +02:00
Klaus Zanders bf1293a361 Fixes Performance/DeleteSuffix offenses 2023-09-06 10:59:34 +02:00
Andreas Pfohl e1b305ab24 Merge pull request #13570 from opf/implementation/49760-create-form-for-creating-onedrive-storages
[#49760] Creating and editing of OneDrive storages
2023-09-04 09:26:40 +02:00
ulferts f5bdb718c2 remove overrides doing the same as super() 2023-08-31 09:47:24 +02:00
Eric Schubert 9ac18b9b4a [#49760] fixed test setups and specs
- fixed file link SetAttributeServiceSpec
- changed contract structure
2023-08-29 17:07:03 +02:00
Christophe Bliard 10085736da refactor: Rename and generalize #accessor_name as #attribute_name
Also extract #attribute_getter and #attribute_setter when
using #attribute_name in the context of calling the getter/setter
methods.
2023-01-17 09:39:27 +01:00
Christophe Bliard 21a696ef9b Update copyright information for 2023 2022-12-30 15:51:26 +01:00
ulferts 2321701f7f move property name conversion for writability check
This way, the conversion occurs where the name is determined and representation logic does not mix with business logic.
2022-12-02 17:09:33 +01:00
Dombi Attila f02c07a57f [#45032] Custom fields editing looks like it's possible in read-only status (although changes are not saved and there is no error message)
https://community.openproject.org/work_packages/45032
2022-11-28 23:00:11 +02:00
Dombi Attila 92a7f1ffda Rename :writeable to :writable 2022-06-20 13:30:33 +02: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
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 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
Wieland Lindenthal 3044b5ce5e Align ModelContract validate/valid? methods with ActiveModel::Validations (#8955)
* Align ModelContract validate/valid? methods with ActiveModel::Validations

* Add BaseContract to allow contracts on non ActiveRecord resources

* Avoid using alias_method as that won't work with subclasses

Co-authored-by: Oliver Günther <mail@oliverguenther.de>
2021-02-01 15:20:29 +01:00