Fix work packages index if no project scope is given (WIP)

TODO authorization for API
pull/1065/head
Till Breuer 11 years ago
parent f0dd9971c0
commit a153ae0636
  1. 1
      app/assets/javascripts/angular/controllers/work-packages-controller.js
  2. 18
      app/assets/javascripts/angular/helpers/components/path-helper.js
  3. 4
      app/assets/javascripts/angular/services/query-service.js
  4. 8
      app/assets/javascripts/angular/services/work-package-service.js
  5. 10
      app/controllers/api/v3/queries_controller.rb
  6. 8
      app/controllers/api/v3/work_packages_controller.rb
  7. 4
      config/routes.rb

@ -7,6 +7,7 @@ angular.module('openproject.workPackages.controllers')
function initialSetup() {
$scope.projectIdentifier = gon.project_identifier;
if(gon.query_id) $scope.query_id = gon.query_id;
$scope.operatorsAndLabelsByFilterType = OPERATORS_AND_LABELS_BY_FILTER_TYPE;
$scope.loading = false;
$scope.disableFilters = false;

@ -24,20 +24,24 @@ angular.module('openproject.helpers')
versionPath: function(versionId) {
return '/versions/' + versionId;
},
apiProjectPath: function(projectIdentifier) {
return PathHelper.apiPrefixV3 + PathHelper.projectPath(projectIdentifier);
},
apiV2ProjectPath: function(projectIdentifier) {
return PathHelper.apiPrefixV2 + PathHelper.projectPath(projectIdentifier);
},
apiV3ProjectPath: function(projectIdentifier) {
return PathHelper.apiPrefixV3 + PathHelper.projectPath(projectIdentifier);
},
apiWorkPackagesPath: function() {
return PathHelper.apiPrefixV3 + '/work_packages';
},
apiProjectWorkPackagesPath: function(projectIdentifier) {
return PathHelper.apiProjectPath(projectIdentifier) + PathHelper.workPackagesPath();
return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.workPackagesPath();
},
apiAvailableColumnsPath: function() {
return PathHelper.apiPrefixV3 + '/queries/available_columns';
},
apiAvailableColumnsPath: function(projectIdentifier) {
return PathHelper.apiProjectPath(projectIdentifier) + '/queries/available_columns';
apiProjectAvailableColumnsPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectPath(projectIdentifier) + '/queries/available_columns';
},
apiWorkPackagesColumnDataPath: function() {
return PathHelper.apiWorkPackagesPath() + '/column_data';
@ -64,7 +68,7 @@ angular.module('openproject.helpers')
return PathHelper.apiV2ProjectPath(projectIdentifier) + PathHelper.usersPath();
},
apiWorkPackagesSumsPath: function(projectIdentifier) {
return PathHelper.apiProjectPath(projectIdentifier) + PathHelper.workPackagesPath() + '/column_sums';
return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.workPackagesPath() + '/column_sums';
},
};

@ -5,8 +5,8 @@ angular.module('openproject.services')
var availableColumns = [], availableFilterValues = {};
var QueryService = {
getAvailableColumns: function(projectId) {
var url = PathHelper.apiAvailableColumnsPath(projectId);
getAvailableColumns: function(projectIdentifier) {
var url = projectIdentifier ? PathHelper.apiProjectAvailableColumnsPath(projectIdentifier) : PathHelper.apiAvailableColumnsPath();
return QueryService.doQuery(url);
},

@ -3,8 +3,8 @@ angular.module('openproject.services')
.service('WorkPackageService', ['$http', 'PathHelper', 'WorkPackagesHelper', function($http, PathHelper, WorkPackagesHelper) {
var WorkPackageService = {
getWorkPackages: function(projectId, query, paginationOptions) {
var url = projectId ? PathHelper.apiProjectWorkPackagesPath(projectId) : PathHelper.apiWorkPackagesPath();
getWorkPackages: function(projectIdentifier, query, paginationOptions) {
var url = projectIdentifier ? PathHelper.apiProjectWorkPackagesPath(projectIdentifier) : PathHelper.apiWorkPackagesPath();
var params = angular.extend(query.toParams(), {
page: paginationOptions.page,
per_page: paginationOptions.perPage
@ -27,12 +27,12 @@ angular.module('openproject.services')
},
// Note: Should this be on a project-service?
getWorkPackagesSums: function(projectId, columns){
getWorkPackagesSums: function(projectIdentifier, columns){
var columnNames = columns.map(function(column){
return column.name;
});
var url = PathHelper.apiWorkPackagesSumsPath(projectId);
var url = PathHelper.apiWorkPackagesSumsPath(projectIdentifier);
var params = {
'column_names[]': columnNames

@ -11,7 +11,7 @@ module Api
include ::Api::V3::ApiController
include ExtendedHTTP
before_filter :authorize_and_setup_project
before_filter :find_optional_project
def available_columns
query = retrieve_query
@ -71,13 +71,7 @@ module Api
return "default"
end
end
def authorize_and_setup_project
find_project_by_project_id unless performed?
# TODO: Sort out the authorisation for reading query controller
# authorize unless performed?
end
end
end
end
end

@ -14,7 +14,8 @@ module Api
include ::Api::V3::ApiController
include ExtendedHTTP
before_filter :authorize_and_setup_project, only: [:index]
before_filter :find_optional_project, only: [:index]
# before_filter :authorize # TODO specify authorization
before_filter :authorize_request, only: [:column_data]
before_filter :assign_planning_elements, only: [:index]
@ -53,11 +54,6 @@ module Api
private
def authorize_and_setup_project
find_project_by_project_id unless performed?
authorize unless performed?
end
def authorize_request
# TODO: need to give this action a global role i think. tried making load_column_data role in reminde.rb
# but couldn't get it working.

@ -121,6 +121,10 @@ OpenProject::Application.routes.draw do
resources :work_packages, only: [:index] do
get :column_data, on: :collection
end
resources :queries, only: [:show] do
get :available_columns, on: :collection
end
resources :projects, only: [:show] do
resources :work_packages, only: [:index] do
get :column_sums, on: :collection

Loading…
Cancel
Save