Merge pull request #109 from finnlabs/feature/16975_grouped_attributes_on_overview_tab

16975 grouped attributes on overview tab
pull/6827/head
ulferts 10 years ago
commit 9e7c0a3bfa
  1. 30
      app/assets/javascripts/angular/openproject-costs-app.js
  2. 2
      config/locales/js-de.yml
  3. 2
      config/locales/js-en.yml
  4. 8
      lib/open_project/costs/engine.rb
  5. 47
      lib/open_project/costs/hooks/work_packages_overview_attributes.rb
  6. 75
      spec/controllers/work_packages_controller_spec.rb

@ -29,13 +29,39 @@
// main app
var openprojectCostsApp = angular.module('openproject');
openprojectCostsApp.run(['HookService', function(HookService) {
openprojectCostsApp.run(['HookService',
'ConfigurationService',
'WorkPackagesOverviewService',
function(HookService, ConfigurationService, WorkPackagesOverviewService) {
var setupCostsAttributes = function() {
var position = WorkPackagesOverviewService.getGroupedWorkPackageOverviewAttributes().length - 1;
var costsAttributes = {
overallCosts: null,
spentHours: 'spentHoursLinked',
costObject: null,
summarizedCostEntries: 'spentUnits'
};
WorkPackagesOverviewService.removeAttribute('spentTime');
WorkPackagesOverviewService.addGroup('costs', position);
angular.forEach(costsAttributes, function(id, costAttribute) {
WorkPackagesOverviewService.addAttributeToGroup('costs', id || costAttribute);
});
}
if (ConfigurationService.isModuleEnabled('costs_module')) {
setupCostsAttributes();
}
HookService.register('workPackageOverviewAttributes', function(params) {
var directive;
switch (params.type) {
case "spentUnits":
if (params.workPackage.embedded.summarizedCostEntries.length > 0) {
var summarizedCostEntries = params.workPackage.embedded.summarizedCostEntries;
if (summarizedCostEntries && summarizedCostEntries.length > 0) {
directive = "summarized-cost-entries";
}
break;

@ -36,6 +36,8 @@
de:
js:
work_packages:
property_groups:
costs: "Kosten"
properties:
costObject: "Budget"
spentHoursLinked: "Aufgewendete Zeit"

@ -36,6 +36,8 @@
en:
js:
work_packages:
property_groups:
costs: "Costs"
properties:
costObject: "Budget"
spentHoursLinked: "Spent time"

@ -134,7 +134,7 @@ module OpenProject::Costs
property :summarized_cost_entries,
embedded: true,
exec_context: :decorator,
if: -> (*) { costs_enabled }
if: -> (*) { costs_enabled && current_user_allowed_to_view_summarized_cost_entries }
send(:define_method, :cost_object) do
::API::V3::CostObjects::CostObjectModel.new(represented.model.cost_object)
@ -149,6 +149,11 @@ module OpenProject::Costs
current_user_allowed_to(:view_own_time_entries, represented.model)
end
send(:define_method, :current_user_allowed_to_view_summarized_cost_entries) do
current_user_allowed_to(:view_cost_entries, represented.model) ||
current_user_allowed_to(:view_own_cost_entries, represented.model)
end
send(:define_method, :overall_costs) do
number_to_currency(self.attributes_helper.overall_costs)
end
@ -185,7 +190,6 @@ module OpenProject::Costs
require 'open_project/costs/hooks/project_hook'
require 'open_project/costs/hooks/work_package_action_menu'
require 'open_project/costs/hooks/work_packages_show_attributes'
require 'open_project/costs/hooks/work_packages_overview_attributes'
end
initializer 'costs.register_observers' do |app|

@ -1,47 +0,0 @@
#-- 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 OpenProject::Costs::Hooks
class WorkPackagesOverviewHook < Redmine::Hook::ViewListener
def work_packages_overview_attributes(context = {})
project = context[:project]
attributes = context[:attributes]
return unless project && project.module_enabled?(:costs_module)
attributes.reject!{ |attribute| attribute == :spentTime }
attributes << :costObject
attributes << :spentHoursLinked if user_allowed_to?(project, :view_time_entries, :view_own_time_entries)
attributes << :overallCosts
attributes << :spentUnits if user_allowed_to?(project, :view_cost_entries, :view_own_cost_entries)
attributes
end
private
def user_allowed_to?(project, *privileges)
privileges.inject(false) do |result, privilege|
result || User.current.allowed_to?(privilege, project)
end
end
end
end

@ -1,75 +0,0 @@
#-- 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 WorkPackagesController, type: :controller do
let(:project) { FactoryGirl.create(:project) }
let(:current_user) { FactoryGirl.create(:user) }
let(:query) { FactoryGirl.build_stubbed(:query).tap(&:add_default_filter) }
let(:work_packages) { double("work packages").as_null_object }
before do
allow(User).to receive(:current).and_return current_user
allow(User.current).to receive(:allowed_to?).and_return(true)
end
describe 'settings passed to front-end client' do
describe 'visible attributes' do
let(:call_action) { get('index', project_id: project.id) }
let(:costs_attributes) { [:costObject, :spentHoursLinked, :overallCosts, :spentUnits] }
subject { assigns(:enabled_default_work_package_properties) }
context 'costs module disabled' do
before do
allow_any_instance_of(Project).to receive(:module_enabled?).and_return(true)
allow_any_instance_of(Project).to receive(:module_enabled?).with(:costs_module).and_return(false)
call_action
end
it { expect(subject).not_to include(*costs_attributes) }
it { expect(subject).to include(:spentTime) }
end
context 'all permissions granted' do
before { call_action }
it { expect(subject).to include(*costs_attributes) }
it { expect(subject).not_to include(:spentTime) }
end
context 'costs permissions revoked' do
before do
allow(User.current).to receive(:allowed_to?).with(:view_time_entries, anything).and_return(false)
allow(User.current).to receive(:allowed_to?).with(:view_own_time_entries, anything).and_return(false)
allow(User.current).to receive(:allowed_to?).with(:view_cost_entries, anything).and_return(false)
allow(User.current).to receive(:allowed_to?).with(:view_own_cost_entries, anything).and_return(false)
call_action
end
it { expect(subject).not_to include(:spentHoursLinked, :spentUnits) }
end
end
end
end
Loading…
Cancel
Save