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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
add current-user end point
ulferts35269da87e52
diff --git a/modules/bcf/app/controllers/bcf/api/root.rb b/modules/bcf/app/controllers/bcf/api/root.rbindex e7dc6b3a968..a212e675b7d 100644--- a/modules/bcf/app/controllers/bcf/api/root.rb+++ b/modules/bcf/app/controllers/bcf/api/root.rb@@ -45,6 +45,8 @@ module Bcf::APIauthentication_scope OpenProject::Authentication::Scope::BCF_V2_1version '2.1', using: :path do+ # /current-user+ mount ::Bcf::API::V2_1::CurrentUserAPI# /projectsmount ::Bcf::API::V2_1::ProjectsAPIenddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/current_user_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/current_user_api.rbnew file mode 100644index 00000000000..34e8b222a1f--- /dev/null+++ b/modules/bcf/app/controllers/bcf/api/v2_1/current_user_api.rb@@ -0,0 +1,38 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module Bcf::API::V2_1+ class CurrentUserAPI < ::API::OpenProjectAPI+ resources :'current-user' do+ get &::Bcf::API::V2_1::Endpoints::Show.new(model: User,+ instance_generator: ->(*) { current_user }).mount+ end+ end+enddiff --git a/modules/bcf/app/representers/bcf/api/v2_1/users/single_representer.rb b/modules/bcf/app/representers/bcf/api/v2_1/users/single_representer.rbnew file mode 100644index 00000000000..bef6e635f69--- /dev/null+++ b/modules/bcf/app/representers/bcf/api/v2_1/users/single_representer.rb@@ -0,0 +1,40 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++module Bcf::API::V2_1+ class Users::SingleRepresenter < Roar::Decorator+ include Representable::JSON++ property :mail,+ as: :id++ property :name+ end+enddiff --git a/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rb b/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rbindex af65f29ed26..0d0aa279f71 100644--- a/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rb+++ b/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rb@@ -30,7 +30,6 @@ require 'spec_helper'describe Bcf::API::V2_1::Projects::SingleRepresenter, 'rendering' dolet(:project) { FactoryBot.build_stubbed(:project) }- let(:user) { FactoryBot.build_stubbed(:project) }let(:instance) { described_class.new(project) }diff --git a/modules/bcf/spec/representers/bcf/api/v2_1/shared_examples.rb b/modules/bcf/spec/representers/bcf/api/v2_1/shared_examples.rbnew file mode 100644index 00000000000..1ad3751f1ec--- /dev/null+++ b/modules/bcf/spec/representers/bcf/api/v2_1/shared_examples.rb@@ -0,0 +1,8 @@+shared_examples_for 'attribute' do+ it 'reflects the project' do+ expect(subject)+ .to be_json_eql(value.to_json)+ .at_path(path)+ end+end+diff --git a/modules/bcf/spec/representers/bcf/api/v2_1/users/single_representer_rendering_spec.rb b/modules/bcf/spec/representers/bcf/api/v2_1/users/single_representer_rendering_spec.rbnew file mode 100644index 00000000000..2d820808e92--- /dev/null+++ b/modules/bcf/spec/representers/bcf/api/v2_1/users/single_representer_rendering_spec.rb@@ -0,0 +1,55 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2019 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++require_relative '../shared_examples'++describe Bcf::API::V2_1::Users::SingleRepresenter, 'rendering' do+ let(:user) { FactoryBot.build_stubbed(:user) }++ let(:instance) { described_class.new(user) }++ subject { instance.to_json }++ describe 'attributes' do+ context 'id' do+ it_behaves_like 'attribute' do+ let(:value) { user.mail }+ let(:path) { 'id' }+ end+ end++ context 'name' do+ it_behaves_like 'attribute' do+ let(:value) { user.name }+ let(:path) { 'name' }+ end+ end+ end+enddiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/current_user_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/current_user_api_spec.rbnew file mode 100644index 00000000000..4a1d576fd3c--- /dev/null+++ b/modules/bcf/spec/requests/api/bcf/v2_1/current_user_api_spec.rb@@ -0,0 +1,60 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2019 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'+require 'rack/test'++require_relative './shared_responses'++describe 'BCF 2.1 current-user resource', type: :request, content_type: :json do+ include Rack::Test::Methods++ let(:current_user) do+ FactoryBot.create(:user)+ end++ subject(:response) { last_response }++ describe 'GET /api/bcf/2.1/current-user' do+ let(:path) { "/api/bcf/2.1/current-user" }++ before do+ login_as(current_user)+ get path+ end++ it_behaves_like 'bcf api successful response' do+ let(:expected_body) do+ {+ id: current_user.mail,+ name: current_user.name+ }+ end+ end+ end+enddiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rbsimilarity index 99%rename from modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rbrename to modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rbindex 5f48ef01104..405fe340610 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/projects/projects_api_spec.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'require 'rack/test'-require_relative '../shared_responses'+require_relative './shared_responses'describe 'BCF 2.1 projects resource', type: :request, content_type: :json doinclude Rack::Test::Methods