Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

hide op version for non admins in api

ulferts6718428b6945
diff --git a/docs/api/apiv3/endpoints/root.apib b/docs/api/apiv3/endpoints/root.apib
index 2bc7d705f52..62d2412042f 100644
--- a/docs/api/apiv3/endpoints/root.apib
+++ b/docs/api/apiv3/endpoints/root.apib
@@ -19,10 +19,10 @@ a client should be able to discover further resources in the API.
## Local Properties
-| Property | Description | Type | Condition | Supported operations |
-| :-----------------------: | ---------------------------------------------------- | ---------- | --------------------------------- | -------------------- |
-| instanceName | The name of the OpenProject instance | String | | READ |
-| coreVersion | The OpenProject core version number for the instance | String | | READ |
+| Property | Description | Type | Condition | Supported operations |
+| :-----------------------: | ---------------------------------------------------- | ---------- | --------------------------------- | -------------------- |
+| instanceName | The name of the OpenProject instance | String | | READ |
+| coreVersion | The OpenProject core version number for the instance | String | **Permission** requires admin privileges | READ |
## Root [/api/v3]
@@ -61,7 +61,7 @@ a client should be able to discover further resources in the API.
}
},
"instanceName" : "My own OpenProject",
- "coreVersion" : "6.1.0"
+ "coreVersion" : "10.3.0"
}
## View root [GET]
diff --git a/lib/api/v3/root_representer.rb b/lib/api/v3/root_representer.rb
index 0847a17c468..409a0d19300 100644
--- a/lib/api/v3/root_representer.rb
+++ b/lib/api/v3/root_representer.rb
@@ -86,6 +86,7 @@ module API
link :user do
next unless current_user.logged?
+
{
href: api_v3_paths.user(current_user.id),
title: current_user.name
@@ -94,6 +95,7 @@ module API
link :userPreferences do
next unless current_user.logged?
+
{
href: api_v3_paths.my_preferences
}
@@ -109,7 +111,9 @@ module API
getter: ->(*) { Setting.app_title }
property :core_version,
- getter: ->(*) { OpenProject::VERSION.to_semver }
+ exec_context: :decorator,
+ getter: ->(*) { OpenProject::VERSION.to_semver },
+ if: ->(*) { current_user.admin? }
def _type
'Root'
diff --git a/spec/lib/api/v3/root_representer_spec.rb b/spec/lib/api/v3/root_representer_spec.rb
index bd3e7e81e0b..bbce9f10503 100644
--- a/spec/lib/api/v3/root_representer_spec.rb
+++ b/spec/lib/api/v3/root_representer_spec.rb
@@ -145,10 +145,21 @@ describe ::API::V3::RootRepresenter do
end
describe 'coreVersion' do
- it 'indicates the OpenProject version number' do
- is_expected
- .to be_json_eql(version.to_json)
- .at_path('coreVersion')
+ context 'for a non admin user' do
+ it 'has no coreVersion property' do
+ is_expected
+ .not_to have_json_path('coreVersion')
+ end
+ end
+
+ context 'for an admin user' do
+ let(:user) { FactoryBot.build_stubbed(:admin) }
+
+ it 'indicates the OpenProject version number' do
+ is_expected
+ .to be_json_eql(version.to_json)
+ .at_path('coreVersion')
+ end
end
end