Merge pull request #130 from 0xF013/feature/add-hook-for-edit-type
changes hooks for new layout of details panepull/6827/head
commit
fce9f390a1
@ -1,12 +1,13 @@ |
||||
<span class="costs costTypes" ng-if="costTypes"> |
||||
<span ng-repeat="costType in costTypes"> |
||||
<a ng-href="{{ linkToSummary(costType) }}" title="{{ costType.props.name }}"> |
||||
{{ costType.props.units }} |
||||
<span class="unit" ng-switch="costType.props.units"> |
||||
<span ng-switch-when="1">{{ costType.props.unit }}</span> |
||||
<span ng-switch-default>{{ costType.props.unitPlural }}</span> |
||||
<a ng-href="{{ linkToSummary(costType.embedded.costType) }}" title="{{ costType.embedded.costType.props.name }}"> |
||||
{{ costType.props.spentUnits }} |
||||
<span class="unit" ng-switch="costType.props.spentUnits"> |
||||
<span ng-switch-when="1">{{ costType.embedded.costType.props.unit }}</span> |
||||
<span ng-switch-default>{{ costType.embedded.costType.props.unitPlural }}</span> |
||||
</span> |
||||
</a> |
||||
<span class="separator" ng-if="!$last">,</span> |
||||
</span> |
||||
</span> |
||||
<span ng-if="!costTypes.length">-</span> |
@ -0,0 +1,47 @@ |
||||
#-- copyright |
||||
# OpenProject Costs Plugin |
||||
# |
||||
# Copyright (C) 2009 - 2014 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. |
||||
# |
||||
# 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. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
# N.B. This class is currently quite specifically crafted for the aggregation of cost entries |
||||
# of a single work package by their type. This might be improved in the future™ |
||||
class AggregatedCostEntryRepresenter < ::API::Decorators::Single |
||||
def initialize(cost_type, units) |
||||
@cost_type = cost_type |
||||
@spent_units = units |
||||
|
||||
super(nil) |
||||
end |
||||
|
||||
linked_property :cost_type, |
||||
getter: -> { @cost_type }, |
||||
embed_as: ::API::V3::CostTypes::CostTypeRepresenter |
||||
|
||||
property :spent_units, |
||||
exec_context: :decorator, |
||||
getter: -> (*) { @spent_units } |
||||
|
||||
def _type |
||||
'AggregatedCostEntry' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,58 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'api/v3/cost_types/cost_type_representer' |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
class CostEntriesAPI < ::API::OpenProjectAPI |
||||
resources :cost_entries do |
||||
route_param :id do |
||||
before do |
||||
@cost_entry = CostEntry.find(params[:id]) |
||||
|
||||
authorize(:view_cost_entries, context: @cost_entry.project) do |
||||
if current_user == @cost_entry.user |
||||
authorize(:view_own_cost_entries, context: @cost_entry.project) |
||||
else |
||||
raise API::Errors::Unauthorized |
||||
end |
||||
end |
||||
end |
||||
|
||||
get do |
||||
CostEntryRepresenter.new(@cost_entry, current_user: current_user) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,60 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'api/v3/cost_types/cost_type_representer' |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
class CostEntriesByWorkPackageAPI < ::API::OpenProjectAPI |
||||
before do |
||||
authorize_any([:view_cost_entries, :view_own_cost_entries], |
||||
projects: @work_package.project) |
||||
@cost_helper = ::OpenProject::Costs::AttributesHelper.new(@work_package, current_user) |
||||
end |
||||
|
||||
resources :cost_entries do |
||||
get do |
||||
path = api_v3_paths.cost_entries_by_work_package(@work_package.id) |
||||
cost_entries = @cost_helper.cost_entries |
||||
CostEntryCollectionRepresenter.new(cost_entries, |
||||
cost_entries.count, |
||||
path) |
||||
end |
||||
end |
||||
|
||||
resources :summarized_costs_by_type do |
||||
get do |
||||
WorkPackageCostsByTypeRepresenter.new(@work_package, current_user: current_user) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,38 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
class CostEntryCollectionRepresenter < ::API::Decorators::Collection |
||||
element_decorator ::API::V3::CostEntries::CostEntryRepresenter |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
#-- copyright |
||||
# OpenProject Costs Plugin |
||||
# |
||||
# Copyright (C) 2009 - 2014 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. |
||||
# |
||||
# 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. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
class CostEntryRepresenter < ::API::Decorators::Single |
||||
self_link title_getter: -> (*) { nil } |
||||
linked_property :project, embed_as: ::API::V3::Projects::ProjectRepresenter |
||||
linked_property :user, embed_as: ::API::V3::Users::UserRepresenter |
||||
linked_property :cost_type, embed_as: ::API::V3::CostTypes::CostTypeRepresenter |
||||
|
||||
# for now not embedded, because work packages are quite large |
||||
linked_property :work_package, title_getter: -> (*) { represented.work_package.subject } |
||||
|
||||
property :id, render_nil: true |
||||
property :units, as: :spentUnits |
||||
property :spent_on, |
||||
exec_context: :decorator, |
||||
getter: -> (*) { datetime_formatter.format_date(represented.spent_on) } |
||||
property :created_on, |
||||
as: 'createdAt', |
||||
exec_context: :decorator, |
||||
getter: -> (*) { datetime_formatter.format_datetime(represented.created_on) } |
||||
property :updated_on, |
||||
as: 'updatedAt', |
||||
exec_context: :decorator, |
||||
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_on) } |
||||
|
||||
def _type |
||||
'CostEntry' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,71 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CostEntries |
||||
# Ripped from ::API::Decorators::Collection, which does not support injecting |
||||
# decorators directly |
||||
# This class should use the Collection class directly (or inherit from it) in the future |
||||
class WorkPackageCostsByTypeRepresenter < ::API::Decorators::Single |
||||
link :self do |
||||
{ href: api_v3_paths.summarized_work_package_costs_by_type(represented.id) } |
||||
end |
||||
|
||||
property :total, |
||||
exec_context: :decorator, |
||||
getter: -> (*) { cost_helper.summarized_cost_entries.size } |
||||
property :count, |
||||
exec_context: :decorator, |
||||
getter: -> (*) { cost_helper.summarized_cost_entries.size } |
||||
|
||||
collection :elements, |
||||
getter: -> (*) { |
||||
cost_helper.summarized_cost_entries.map { |kvp| |
||||
type = kvp[0] |
||||
units = kvp[1] |
||||
::API::V3::CostEntries::AggregatedCostEntryRepresenter.new(type, units) |
||||
} |
||||
}, |
||||
exec_context: :decorator, |
||||
embedded: true |
||||
|
||||
private |
||||
|
||||
def cost_helper |
||||
@cost_helper ||= ::OpenProject::Costs::AttributesHelper.new(represented, current_user) |
||||
end |
||||
|
||||
def _type |
||||
'Collection' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,56 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'api/v3/cost_types/cost_type_representer' |
||||
|
||||
module API |
||||
module V3 |
||||
module CostTypes |
||||
class CostTypesAPI < ::API::OpenProjectAPI |
||||
resources :cost_types do |
||||
before do |
||||
authorize_any([:view_cost_entries, :view_own_cost_entries], |
||||
global: true, |
||||
user: current_user) |
||||
end |
||||
|
||||
route_param :id do |
||||
before do |
||||
@cost_type = CostType.active.find(params[:id]) |
||||
end |
||||
|
||||
get do |
||||
CostTypeRepresenter.new(@cost_type, current_user: current_user) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
#-- copyright |
||||
# OpenProject Costs Plugin |
||||
# |
||||
# Copyright (C) 2009 - 2014 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. |
||||
# |
||||
# 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. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::CostEntries::AggregatedCostEntryRepresenter do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:cost_entry) { FactoryGirl.build(:cost_entry, id: 42) } |
||||
let(:representer) { described_class.new(cost_entry.cost_type, cost_entry.units) } |
||||
|
||||
subject { representer.to_json } |
||||
|
||||
it 'has a type' do |
||||
is_expected.to be_json_eql('AggregatedCostEntry'.to_json).at_path('_type') |
||||
end |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'costType' } |
||||
let(:href) { api_v3_paths.cost_type cost_entry.cost_type.id } |
||||
let(:title) { cost_entry.cost_type.name } |
||||
end |
||||
|
||||
it 'has spent units' do |
||||
is_expected.to be_json_eql(cost_entry.units.to_json).at_path('spentUnits') |
||||
end |
||||
end |
@ -0,0 +1,85 @@ |
||||
#-- copyright |
||||
# OpenProject Costs Plugin |
||||
# |
||||
# Copyright (C) 2009 - 2014 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. |
||||
# |
||||
# 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. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::CostEntries::CostEntryRepresenter do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:cost_entry) { FactoryGirl.build(:cost_entry, id: 42) } |
||||
let(:representer) { described_class.new(cost_entry) } |
||||
|
||||
subject { representer.to_json } |
||||
|
||||
it 'has a type' do |
||||
is_expected.to be_json_eql('CostEntry'.to_json).at_path('_type') |
||||
end |
||||
|
||||
it_behaves_like 'has an untitled link' do |
||||
let(:link) { 'self' } |
||||
let(:href) { api_v3_paths.cost_entry cost_entry.id } |
||||
end |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'project' } |
||||
let(:href) { api_v3_paths.project cost_entry.project.id } |
||||
let(:title) { cost_entry.project.name } |
||||
end |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'user' } |
||||
let(:href) { api_v3_paths.user cost_entry.user.id } |
||||
let(:title) { cost_entry.user.name } |
||||
end |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'costType' } |
||||
let(:href) { api_v3_paths.cost_type cost_entry.cost_type.id } |
||||
let(:title) { cost_entry.cost_type.name } |
||||
end |
||||
|
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'workPackage' } |
||||
let(:href) { api_v3_paths.work_package cost_entry.work_package.id } |
||||
let(:title) { cost_entry.work_package.subject } |
||||
end |
||||
|
||||
it 'has an id' do |
||||
is_expected.to be_json_eql(cost_entry.id.to_json).at_path('id') |
||||
end |
||||
|
||||
it 'has spent units' do |
||||
is_expected.to be_json_eql(cost_entry.units.to_json).at_path('spentUnits') |
||||
end |
||||
|
||||
it_behaves_like 'has ISO 8601 date only' do |
||||
let(:date) { cost_entry.spent_on } |
||||
let(:json_path) { 'spentOn' } |
||||
end |
||||
|
||||
it_behaves_like 'has UTC ISO 8601 date and time' do |
||||
let(:date) { cost_entry.created_on } |
||||
let(:json_path) { 'createdAt' } |
||||
end |
||||
|
||||
it_behaves_like 'has UTC ISO 8601 date and time' do |
||||
let(:date) { cost_entry.updated_on } |
||||
let(:json_path) { 'updatedAt' } |
||||
end |
||||
end |
@ -0,0 +1,85 @@ |
||||
#-- copyright |
||||
# OpenProject Costs Plugin |
||||
# |
||||
# Copyright (C) 2009 - 2014 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. |
||||
# |
||||
# 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. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::CostEntries::WorkPackageCostsByTypeRepresenter do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:project) { FactoryGirl.create(:project) } |
||||
let(:work_package) { FactoryGirl.create(:work_package, project: project) } |
||||
let(:cost_type_A) { FactoryGirl.create(:cost_type) } |
||||
let(:cost_type_B) { FactoryGirl.create(:cost_type) } |
||||
let(:cost_entries_A) { |
||||
FactoryGirl.create_list(:cost_entry, |
||||
2, |
||||
units: 1, |
||||
work_package: work_package, |
||||
project: project, |
||||
cost_type: cost_type_A) |
||||
} |
||||
let(:cost_entries_B) { |
||||
FactoryGirl.create_list(:cost_entry, |
||||
3, |
||||
units: 2, |
||||
work_package: work_package, |
||||
project: project, |
||||
cost_type: cost_type_B) |
||||
} |
||||
let(:current_user) { |
||||
FactoryGirl.build(:user, member_in_project: project, member_through_role: role) |
||||
} |
||||
let(:role) { FactoryGirl.build(:role, permissions: [:view_cost_entries]) } |
||||
|
||||
let(:representer) { described_class.new(work_package, current_user: current_user) } |
||||
|
||||
subject { representer.to_json } |
||||
|
||||
before do |
||||
# create the lists |
||||
cost_entries_A |
||||
cost_entries_B |
||||
end |
||||
|
||||
it 'has a type' do |
||||
is_expected.to be_json_eql('Collection'.to_json).at_path('_type') |
||||
end |
||||
|
||||
it 'has one element per type' do |
||||
is_expected.to have_json_size(2).at_path('_embedded/elements') |
||||
end |
||||
|
||||
it 'indicates the cost types' do |
||||
elements = JSON.parse(subject)['_embedded']['elements'] |
||||
types = elements.map { |entry| entry['_links']['costType']['href'] } |
||||
expect(types).to include(api_v3_paths.cost_type cost_type_A.id) |
||||
expect(types).to include(api_v3_paths.cost_type cost_type_B.id) |
||||
end |
||||
|
||||
it 'aggregates the units' do |
||||
elements = JSON.parse(subject)['_embedded']['elements'] |
||||
units_by_type = elements.inject({}) do |hash, entry| |
||||
hash[entry['_links']['costType']['href']] = entry['spentUnits'] |
||||
hash |
||||
end |
||||
|
||||
expect(units_by_type[api_v3_paths.cost_type cost_type_A.id]).to eql 2.0 |
||||
expect(units_by_type[api_v3_paths.cost_type cost_type_B.id]).to eql 6.0 |
||||
end |
||||
end |
@ -0,0 +1,70 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::Utilities::PathHelper do |
||||
let(:helper) { Class.new.tap { |c| c.extend(described_class) }.api_v3_paths } |
||||
|
||||
describe '#cost_entry' do |
||||
subject { helper.cost_entry 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/cost_entries/42') } |
||||
end |
||||
|
||||
describe '#cost_entries_by_work_package' do |
||||
subject { helper.cost_entries_by_work_package 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/work_packages/42/cost_entries') } |
||||
end |
||||
|
||||
describe '#summarized_work_package_costs_by_type' do |
||||
subject { helper.summarized_work_package_costs_by_type 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/work_packages/42/summarized_costs_by_type') } |
||||
end |
||||
|
||||
|
||||
describe '#cost_type' do |
||||
subject { helper.cost_type 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/cost_types/42') } |
||||
end |
||||
|
||||
describe '#budget' do |
||||
subject { helper.budget 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/budgets/42') } |
||||
end |
||||
|
||||
describe '#budgets_by_project' do |
||||
subject { helper.budgets_by_project 42 } |
||||
|
||||
it { is_expected.to eql('/api/v3/projects/42/budgets') } |
||||
end |
||||
end |
@ -0,0 +1,110 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe 'API v3 Cost Entry resource' do |
||||
include Rack::Test::Methods |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:current_user) { |
||||
FactoryGirl.create(:user, member_in_project: project, member_through_role: role) |
||||
} |
||||
let(:role) { FactoryGirl.create(:role, permissions: permissions) } |
||||
let(:permissions) { [:view_cost_entries] } |
||||
let(:project) { FactoryGirl.create(:project) } |
||||
let(:work_package) { FactoryGirl.create(:work_package, project: project) } |
||||
subject(:response) { last_response } |
||||
|
||||
let(:cost_entry) { |
||||
FactoryGirl.build(:cost_entry, |
||||
project: project, |
||||
work_package: work_package, |
||||
user: current_user) |
||||
} |
||||
|
||||
before do |
||||
allow(User).to receive(:current).and_return current_user |
||||
cost_entry.save! |
||||
|
||||
get get_path |
||||
end |
||||
|
||||
describe 'work_packages/:id/cost_entries' do |
||||
let(:get_path) { api_v3_paths.cost_entries_by_work_package work_package.id } |
||||
|
||||
context 'user can see any cost entries' do |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'user can see own cost entries' do |
||||
let(:permissions) { [:view_own_cost_entries] } |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'user has no cost entry permissions' do |
||||
let(:permissions) { [] } |
||||
|
||||
it_behaves_like 'error response', |
||||
403, |
||||
'MissingPermission', |
||||
I18n.t('api_v3.errors.code_403') |
||||
end |
||||
end |
||||
|
||||
describe 'work_packages/:id/summarized_costs_by_type' do |
||||
let(:get_path) { api_v3_paths.summarized_work_package_costs_by_type work_package.id } |
||||
|
||||
context 'user can see any cost entries' do |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'user can see own cost entries' do |
||||
let(:permissions) { [:view_own_cost_entries] } |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'user has no cost entry permissions' do |
||||
let(:permissions) { [] } |
||||
|
||||
it_behaves_like 'error response', |
||||
403, |
||||
'MissingPermission', |
||||
I18n.t('api_v3.errors.code_403') |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,103 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe 'API v3 Cost Entry resource' do |
||||
include Rack::Test::Methods |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:current_user) { |
||||
FactoryGirl.create(:user, member_in_project: project, member_through_role: role) |
||||
} |
||||
let(:role) { FactoryGirl.create(:role, permissions: permissions) } |
||||
let(:permissions) { [:view_cost_entries] } |
||||
let(:project) { FactoryGirl.create(:project) } |
||||
subject(:response) { last_response } |
||||
|
||||
let(:cost_entry) { FactoryGirl.build(:cost_entry, project: project) } |
||||
|
||||
before do |
||||
allow(User).to receive(:current).and_return current_user |
||||
cost_entry.save! |
||||
|
||||
get get_path |
||||
end |
||||
|
||||
describe 'cost_entries/:id' do |
||||
let(:get_path) { api_v3_paths.cost_entry cost_entry.id } |
||||
|
||||
context 'user can see cost entries' do |
||||
context 'valid id' do |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'invalid id' do |
||||
let(:get_path) { api_v3_paths.cost_type 'bogus' } |
||||
|
||||
it_behaves_like 'not found' do |
||||
let(:id) { 'bogus' } |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'user can only see own cost entries' do |
||||
let(:permissions) { [:view_own_cost_entries] } |
||||
|
||||
context 'cost entry is not his own' do |
||||
it_behaves_like 'error response', |
||||
403, |
||||
'MissingPermission', |
||||
I18n.t('api_v3.errors.code_403') |
||||
end |
||||
|
||||
context 'cost entry is his own' do |
||||
let(:cost_entry) { FactoryGirl.build(:cost_entry, project: project, user: current_user) } |
||||
|
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'user has no cost entry permissions' do |
||||
let(:permissions) { [] } |
||||
|
||||
describe 'he can\'t even see own cost entries' do |
||||
let(:cost_entry) { FactoryGirl.build(:cost_entry, project: project, user: current_user) } |
||||
it_behaves_like 'error response', |
||||
403, |
||||
'MissingPermission', |
||||
I18n.t('api_v3.errors.code_403') |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,87 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2015 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-2013 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe 'API v3 Cost Type resource' do |
||||
include Rack::Test::Methods |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:current_user) { |
||||
FactoryGirl.create(:user, member_in_project: project, member_through_role: role) |
||||
} |
||||
let(:role) { FactoryGirl.create(:role, permissions: [:view_cost_entries]) } |
||||
let(:project) { FactoryGirl.create(:project) } |
||||
subject(:response) { last_response } |
||||
|
||||
let!(:cost_type) { FactoryGirl.create(:cost_type) } |
||||
|
||||
before do |
||||
allow(User).to receive(:current).and_return current_user |
||||
|
||||
get get_path |
||||
end |
||||
|
||||
describe 'cost_types/:id' do |
||||
let(:get_path) { api_v3_paths.cost_type cost_type.id } |
||||
|
||||
context 'user can see cost entries' do |
||||
context 'valid id' do |
||||
it 'should return HTTP 200' do |
||||
expect(response.status).to eql(200) |
||||
end |
||||
end |
||||
|
||||
context 'cost type deleted' do |
||||
let!(:cost_type) { FactoryGirl.create(:cost_type, :deleted) } |
||||
|
||||
it_behaves_like 'not found' do |
||||
let(:id) { cost_type.id } |
||||
end |
||||
end |
||||
|
||||
context 'invalid id' do |
||||
let(:get_path) { api_v3_paths.cost_type 'bogus' } |
||||
|
||||
it_behaves_like 'not found' do |
||||
let(:id) { 'bogus' } |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'user can\'t see cost entries' do |
||||
let(:current_user) { FactoryGirl.create(:user) } |
||||
|
||||
it_behaves_like 'error response', |
||||
403, |
||||
'MissingPermission', |
||||
I18n.t('api_v3.errors.code_403') |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue