45 Commits

Author SHA1 Message Date
Jan Sandbrink f9d8bc6614 Introduce SubclassResponsibility error
This error is intended for cases when a method is
intentionally not implemented, because the module/class defining
it expects a subclass (or class including the module) to implement
the method.

This is intended to distinguish it from other cases, such as:
* feature not implemented yet
* edge case of a method call not yet supported

Notably it avoids the misuse of the Ruby-defined NotImplementedError,
which is only intended for much more specific scenarios:

> Raised when a feature is not implemented on the current platform. For example, methods depending on the fsync or fork system calls may raise this exception [...]

Also see https://docs.ruby-lang.org/en/master/NotImplementedError.html
2026-03-27 08:14:56 +01:00
Jan Sandbrink 508c8bbad7 Always respond in Bearer method for WWW-Authenticate header
The intention of this change is to always respond in the metadata-rich
version of the header that indicates things like the required scope and
the URL of the resource_metadata endpoint, which was previously hidden
and only visible if clients used a non-standard HTTP request header.

semantically it's probably the preferable version of the header by now
anyways, because:

* all APIs accept some kind of Bearer token, not all of them accept Basic auth
* Even API tokens can now be passed as Bearer tokens

Practically the Basic auth header also caused unintended browser pop-ups when the frontend
code didn't include the correct request header to avoid the Basic auth offer, this now can't
happen anymore, since the Basic auth version of the header is only returned, if the client actively
tried to authenticate through Basic auth.
2026-02-10 09:02:07 +01:00
ulferts b3540f0dd7 apply feature flag to portfolio and program api 2025-11-25 16:33:00 +01:00
Christophe Bliard 0378a9d0ff Add API enpoint class name to grape logs
For instance, it adds "endpoint_name=API::V3::Versions::VersionsAPI" to
the log line.
2025-09-22 18:00:17 +02:00
Jan Sandbrink 7c978030be Make warden available across entire application
This will be required to use warden for our SCIM endpoints as well,
which are implemented in rails controllers. Since Rails controllers do
not support mounting rack middlewares partially (the way that e.g. Grape does),
the mounting of warden needed to be moved.

This was not super straight-forward, because of load order issues:

* Requiring a Rails middleware must be done before initialization finished
* Our warden config was so far done _after_ initialization
* static_routes were defined in lib, which is automatically reloaded,
  but auto-reloading code is not allowed during initialization
    * lib_static which is autoloaded_once is fine during init,
      this is also where the rest of warden authentication is defined

Additionally warden was configured to not handle HTTP 401 responses generated
by the upstream app itself. Warden will only be responsible for its own authentication
failures and it's still possible to invoke the warden failure app by throwing the :warden
symbol, but the application keeps its capability of responding with custom 401 responses.
2025-05-26 13:19:56 +02:00
Ivan Kuchin 45c5419dff extract raise_query_errors to make it available in ParamsToQuery.collection_response 2024-11-04 19:03:49 +01: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
Aaron Contreras cfe3665214 Run rubocop -a on lib 2024-03-01 18:34:17 -05:00
Oliver Günther 6b0a219ba0 Update lib/api/root_api.rb
Co-authored-by: Ivan Kuchin <i.kuchin@openproject.com>
2024-02-21 20:21:54 +01:00
Oliver Günther 64d545d8ab Do not write or update sessions or their cookies for API access
Accessing the API currently does not, and should not update the user's session.
Still, currently we're using it to access the session for authenticating the user.

As a result, the session is loaded and we're currently outputting a Set-Cookie header as well as
writing the user session on every API request.

By using session_options[:skip], we can tell rack to avoid saving the session after the request
2024-02-20 22:03:18 +01:00
Aaron Contreras 7e26c8b2f3 Ignore a missing Content-Type header for a DELETE method request 2024-01-15 11:41:16 -05: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
Klaus Zanders 3bfd6239ac Allow passing in_project param into allowed_in_any_work_package 2023-11-27 10:22:45 +01:00
Klaus Zanders bb7d508692 Add authorize_in_(any_)work_package to API 2023-11-27 10:22:33 +01:00
Klaus Zanders 0229513905 Re-add docs for permission methods 2023-10-31 08:43:44 +01:00
Klaus Zanders bf6e731868 Use Array.wrap instead of Array as it does not deconstruct hashes 2023-10-30 12:36:54 +01:00
Klaus Zanders 1b8a7a8ff3 Fix usage of intersect? on the Array intead of the relation 2023-10-30 12:25:48 +01:00
Klaus Zanders 520bdeea5b First batch of API changes for authorization checks 2023-10-30 11:50:54 +01:00
Klaus Zanders 5ceaca71e7 Try to fix root_api 2023-10-30 11:50:53 +01:00
Oliver Günther 5e60abc0bd Allow configuration request to pass through with login_required 2023-04-20 07:51:11 +02:00
Christophe Bliard 21a696ef9b Update copyright information for 2023 2022-12-30 15:51:26 +01:00
Oliver Günther 8046203c50 Use common helper to reduce duplication 2022-10-17 14:28:02 +02:00
Oliver Günther ce23fb29b5 Add 406 and 415 responses to API and clean up into components 2022-06-20 09:29:30 +02:00
Oliver Günther 7a5efe1e05 Add request tagging to rails and grape 2022-06-09 16:22:48 +02:00
Oliver Günther 78cc8b30d4 Add Appsignal configuration 2022-06-09 15:51:22 +02:00
Christophe Bliard 48a4f1b6ad lint with rubocop --autocorrect (safe cops only) 2022-06-02 10:40:10 +02:00
Christophe Bliard d4e3bfa424 delete AuthorizationService class to reduce indirections 2022-05-20 12:56:30 +02:00
Christophe Bliard 7efd14a792 add documentation to API::RootApi.authorize helper 2022-05-19 18:10:27 +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
Wieland Lindenthal 5d782626a9 Merge remote-tracking branch 'origin/release/11.4' into dev 2021-09-17 16:29:42 +02:00
Oliver Günther f98e50ccf6 Enable basic request logging for grape 2021-09-17 10:45:05 +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
luzpaz 2ae53bd252 Fix typos in user facing and non-user facing code (#9497)
* Fix typos in user facing and non-user facing code

Found via `codespell -q 3 -S ./config/locales -L ba,nd,parms,sur,varius`

* Fix strings in specs
2021-07-21 17:26:31 +02: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
Oliver Günther 38ecb6b28c [32486] Use error response for unauthenticated instead of warden
Instead of warden responding with 401 "unauthorized", use our own
error response that correctly sets the `WWWW-Authenticat` header.

We tripped into the default 401 error that does not output any headers
if we're not returning any users.

This was caused by another issue: The `session` object may be
present, even though no session id exists. Checking `session&.id`
instead always yields the anonymous user.

This will ensure consumers of APIV3 to always get a JSON / HAL response
as well.

https://community.openproject.com/wp/32486
2020-03-25 08:39:17 +01:00
Henriette Dinger bd7f4e4814 Update copyright notice 2020-01-15 11:31:26 +01:00
Oliver Günther 27fadc1b60 Provide NotImplemented error message for bitmaps 2019-11-20 14:02:25 +01:00
ulferts 0a9a7f02d1 fix content type in error handling 2019-11-13 09:18:58 +01:00
ulferts 17bd411b53 adapt the api authorization to the bcf api 2019-11-11 17:03:29 +01:00
ulferts 3a89fceb0d error handling in bcf v2.1 2019-11-11 10:57:18 +01:00
ulferts c6b17e8a7a extract root api into separate superclass 2019-11-11 10:47:48 +01:00